Skip to content

Commit

Permalink
leishman#3 - Implemented OHLC method/specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkybro committed Mar 13, 2014
1 parent e6e8cf8 commit 492d299
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 21 deletions.
29 changes: 18 additions & 11 deletions lib/kraken_ruby/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,33 @@ def asset_pairs(asset_pairs=nil, opts={})
get_public 'AssetPairs', opts
end

def ticker(asset_pairs=nil, opts={}) # takes string of comma delimited pairs
if asset_pairs
raise ArgumentError if !asset_pairs.is_a?(String)
opts[:pair] = asset_pairs
end
def ticker(asset_pairs, opts={}) # takes string of comma delimited pairs
raise ArgumentError if !asset_pairs.is_a?(String)
opts[:pair] = asset_pairs
get_public 'Ticker', opts
end

def order_book(pair, opts={})
opts['pair'] = pair
def ohlc(asset_pairs, opts={})
raise ArgumentError if !asset_pairs.is_a?(String)
opts[:pair] = asset_pairs
get_public 'OHLC', opts
end

def order_book(asset_pairs, opts={})
raise ArgumentError if !asset_pairs.is_a?(String)
opts[:pair] = asset_pairs
get_public 'Depth', opts
end

def trades(pair, opts={})
opts['pair'] = pair
def trades(asset_pairs, opts={})
raise ArgumentError if !asset_pairs.is_a?(String)
opts[:pair] = asset_pairs
get_public 'Trades', opts
end

def spread(pair, opts={})
opts['pair'] = pair
def spread(asset_pairs, opts={})
raise ArgumentError if !asset_pairs.is_a?(String)
opts[:pair] = asset_pairs
get_public 'Spread', opts
end

Expand Down
75 changes: 65 additions & 10 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
end

context "given invalid input" do
it "throws an expection" do
it "throws an ArgumentError exception" do
expect { kraken.assets(1234) }.to raise_error(ArgumentError)
expect { kraken.assets(1234.56) }.to raise_error(ArgumentError)
expect { kraken.assets({}) }.to raise_error(ArgumentError)
Expand Down Expand Up @@ -137,7 +137,7 @@
end

context "given invalid input" do
it "throws an expection" do
it "throws an ArgumentError exception" do
expect { kraken.asset_pairs(1234) }.to raise_error(ArgumentError)
expect { kraken.asset_pairs(1234.56) }.to raise_error(ArgumentError)
expect { kraken.asset_pairs({}) }.to raise_error(ArgumentError)
Expand All @@ -148,7 +148,9 @@

context "using ticker()" do
context "given no input" do

it "throws an ArgumentError exception" do
expect { kraken.ticker }.to raise_error(ArgumentError)
end
end

context "given valid input" do
Expand All @@ -160,13 +162,47 @@
end

context "given invalid input" do

it "throws an ArgumentError exception" do
expect { kraken.ticker(1234) }.to raise_error(ArgumentError)
expect { kraken.ticker(1234.56) }.to raise_error(ArgumentError)
expect { kraken.ticker({}) }.to raise_error(ArgumentError)
expect { kraken.ticker([]) }.to raise_error(ArgumentError)
end
end
end

context "using ohlc()" do
context "given no input" do
it "throws an ArgumentError exception" do
expect { kraken.ohlc }.to raise_error(ArgumentError)
end
end

context "given valid input" do
it "gets order book data for a given asset pair" do
result = kraken.ohlc('XLTCXXDG')
expect(result).to respond_to :XLTCXXDG
expect(result.XLTCXXDG).to be_instance_of(Array)
expect(result).to respond_to :last
#expect(result.last).to be_instance_of(Fixnum)
end
end

context "given invalid input" do
it "throws an ArgumentError exception" do
expect { kraken.ohlc(1234) }.to raise_error(ArgumentError)
expect { kraken.ohlc(1234.56) }.to raise_error(ArgumentError)
expect { kraken.ohlc({}) }.to raise_error(ArgumentError)
expect { kraken.ohlc([]) }.to raise_error(ArgumentError)
end
end
end

context "using order_book()" do
context "given no input" do

it "throws an ArgumentError exception" do
expect { kraken.order_book }.to raise_error(ArgumentError)
end
end

context "given valid input" do
Expand All @@ -179,13 +215,20 @@
end

context "given invalid input" do

it "throws an ArgumentError exception" do
expect { kraken.order_book(1234) }.to raise_error(ArgumentError)
expect { kraken.order_book(1234.56) }.to raise_error(ArgumentError)
expect { kraken.order_book({}) }.to raise_error(ArgumentError)
expect { kraken.order_book([]) }.to raise_error(ArgumentError)
end
end
end

context "using trades()" do
context "given no input" do

it "throws an ArgumentError exception" do
expect { kraken.trades }.to raise_error(ArgumentError)
end
end

context "given valid input" do
Expand All @@ -197,13 +240,20 @@
end

context "given invalid input" do

it "throws an ArgumentError exception" do
expect { kraken.trades(1234) }.to raise_error(ArgumentError)
expect { kraken.trades(1234.56) }.to raise_error(ArgumentError)
expect { kraken.trades({}) }.to raise_error(ArgumentError)
expect { kraken.trades([]) }.to raise_error(ArgumentError)
end
end
end

context "using spread()" do
context "given no input" do

it "throws an ArgumentError exception" do
expect { kraken.spread }.to raise_error(ArgumentError)
end
end

context "given valid input" do
Expand All @@ -215,7 +265,12 @@
end

context "given invalid input" do

it "throws an ArgumentError exception" do
expect { kraken.spread(1234) }.to raise_error(ArgumentError)
expect { kraken.spread(1234.56) }.to raise_error(ArgumentError)
expect { kraken.spread({}) }.to raise_error(ArgumentError)
expect { kraken.spread([]) }.to raise_error(ArgumentError)
end
end
end
end
Expand Down

0 comments on commit 492d299

Please sign in to comment.