excoin 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +32 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +674 -0
- data/README.md +278 -0
- data/Rakefile +9 -0
- data/config/config.example.yml +16 -0
- data/excoin.gemspec +26 -0
- data/lib/account/account.rb +116 -0
- data/lib/account/deposit.rb +20 -0
- data/lib/account/order.rb +43 -0
- data/lib/account/orders.rb +138 -0
- data/lib/account/trade.rb +26 -0
- data/lib/account/trades.rb +59 -0
- data/lib/account/wallet.rb +72 -0
- data/lib/account/withdrawal.rb +27 -0
- data/lib/exchange/candlestick_chart.rb +33 -0
- data/lib/exchange/candlestick_data.rb +20 -0
- data/lib/exchange/exchange.rb +75 -0
- data/lib/exchange/market.rb +50 -0
- data/lib/exchange/order.rb +23 -0
- data/lib/exchange/order_depth_chart.rb +41 -0
- data/lib/exchange/order_depth_data.rb +23 -0
- data/lib/exchange/orders.rb +119 -0
- data/lib/exchange/trade.rb +26 -0
- data/lib/exchange/trades.rb +68 -0
- data/lib/excoin.rb +45 -0
- data/lib/excoin/api.rb +212 -0
- data/lib/excoin/version.rb +10 -0
- data/spec/fixtures/cassette_library/account_cancel_order_erb.yml +59 -0
- data/spec/fixtures/cassette_library/account_issue_order_erb.yml +59 -0
- data/spec/fixtures/cassette_library/account_view_order_erb.yml +59 -0
- data/spec/fixtures/cassette_library/exc_recent_trades.yml +157 -0
- data/spec/fixtures/cassette_library/exc_recent_trades_count.yml +62 -0
- data/spec/fixtures/cassette_library/exc_recent_trades_timestamp.yml +142 -0
- data/spec/fixtures/cassette_library/exchange_candlestick_chart_data.yml +58 -0
- data/spec/fixtures/cassette_library/exchange_candlestick_chart_data_duration.yml +58 -0
- data/spec/fixtures/cassette_library/exchange_open_orders.yml +58 -0
- data/spec/fixtures/cassette_library/exchange_open_orders_type.yml +58 -0
- data/spec/fixtures/cassette_library/exchange_order_depth_chart_data.yml +58 -0
- data/spec/fixtures/cassette_library/excoin_wallet_reserves.yml +59 -0
- data/spec/fixtures/cassette_library/excoin_wallets_summary.yml +65 -0
- data/spec/fixtures/cassette_library/excoin_wallets_summary_coin.yml +59 -0
- data/spec/fixtures/cassette_library/multi_exchange_summ.yml +58 -0
- data/spec/fixtures/cassette_library/multi_exchange_summ_currency.yml +58 -0
- data/spec/fixtures/cassette_library/single_exchange_summ.yml +58 -0
- data/spec/fixtures/cassette_library/single_exchange_summary.yml +58 -0
- data/spec/lib/account/account_spec.rb +136 -0
- data/spec/lib/account/orders_spec.rb +51 -0
- data/spec/lib/account/trades_spec.rb +52 -0
- data/spec/lib/account/wallet_spec.rb +67 -0
- data/spec/lib/exchange/candlestick_chart_spec.rb +23 -0
- data/spec/lib/exchange/exchange_spec.rb +38 -0
- data/spec/lib/exchange/market_spec.rb +23 -0
- data/spec/lib/exchange/order_depth_chart_spec.rb +20 -0
- data/spec/lib/exchange/orders_spec.rb +47 -0
- data/spec/lib/exchange/trades_spec.rb +50 -0
- data/spec/lib/excoin/api_spec.rb +228 -0
- data/spec/lib/excoin_spec.rb +28 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/vcr.rb +21 -0
- metadata +209 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::Account::Orders do
|
4
|
+
subject {Excoin.account.orders}
|
5
|
+
|
6
|
+
it "is an Excoin::Account::Orders object" do
|
7
|
+
expect(subject).to be_an(Excoin::Account::Orders)
|
8
|
+
end
|
9
|
+
|
10
|
+
it ".all returns array of complete Order objects" do
|
11
|
+
expect(subject.all).to be_an(Array)
|
12
|
+
subject.all.each do |order|
|
13
|
+
expect(order).to be_an(Excoin::Account::Order)
|
14
|
+
expect(order.currency).to be_a(String)
|
15
|
+
expect(order.commodity).to be_a(String)
|
16
|
+
expect(order.type).to be_a(String)
|
17
|
+
expect(order.id).to be_a(String)
|
18
|
+
expect(order.timestamp).to be_a(Time)
|
19
|
+
expect(order.price).to be_a(BigDecimal)
|
20
|
+
expect(order.currency_amount).to be_a(BigDecimal)
|
21
|
+
expect(order.commodity_amount).to be_a(BigDecimal)
|
22
|
+
expect(order.status).to be_a(String)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it ".add(order) adds Order object to Orders" do
|
27
|
+
initial_count = subject.count
|
28
|
+
order = Excoin::Account::Order.new($order_data)
|
29
|
+
subject.add(order)
|
30
|
+
expect(subject.count).to eq(initial_count + 1)
|
31
|
+
expect(subject.all).to include{|new_order| new_order.id == $order_data['id']}
|
32
|
+
end
|
33
|
+
|
34
|
+
it ".delete(order_data) removes Order matching order_data from Orders" do
|
35
|
+
subject.delete($order_data)
|
36
|
+
expect(subject.all).to_not include{|order| order.id == $order_data['id']}
|
37
|
+
end
|
38
|
+
|
39
|
+
it ".filter(attr, value, operator) returns an array matching criteria" do
|
40
|
+
subject.filter("type", $type).each do |order|
|
41
|
+
expect(order.type).to eq($type)
|
42
|
+
end
|
43
|
+
subject.filter("currency", $currency).each do |order|
|
44
|
+
expect(order.currency).to eq($currency)
|
45
|
+
end
|
46
|
+
subject.filter("price", $price, :<).each do |order|
|
47
|
+
expect(order.price).to be < BigDecimal.new($price)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::Account::Orders do
|
4
|
+
subject {Excoin.account.trades}
|
5
|
+
|
6
|
+
it "is an Excoin::Account::Trades object" do
|
7
|
+
expect(subject).to be_an(Excoin::Account::Trades)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has complete Excoin::Account::Trade objects" do
|
11
|
+
expect(subject.first).to be_an(Excoin::Account::Trade)
|
12
|
+
expect(subject.first.timestamp).to be_a(Time)
|
13
|
+
expect(subject.first.currency).to be_a(String)
|
14
|
+
expect(subject.first.commodity).to be_a(String)
|
15
|
+
expect(subject.first.type).to be_a(String)
|
16
|
+
expect(subject.first.price).to be_a(BigDecimal)
|
17
|
+
expect(subject.first.sent).to be_a(BigDecimal)
|
18
|
+
expect(subject.first.received).to be_a(BigDecimal)
|
19
|
+
expect(subject.first.fee).to be_a(BigDecimal)
|
20
|
+
expect(subject.first.net_received).to be_a(BigDecimal)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "buys returns all buy trades" do
|
24
|
+
expect(subject.buys).to be_an(Array)
|
25
|
+
subject.buys.each do |trade|
|
26
|
+
expect(trade.type).to eq("BUY")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "sells returns all sell trades" do
|
31
|
+
expect(subject.sells).to be_an(Array)
|
32
|
+
subject.sells.each do |trade|
|
33
|
+
expect(trade.type).to eq("SELL")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "highest returns highest priced trade" do
|
38
|
+
expect(subject.highest).to be_an(Excoin::Account::Trade)
|
39
|
+
expect(subject.highest("sell")).to be_an(Excoin::Account::Trade)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "trim(n) removes n trades" do
|
43
|
+
initial_size = subject.size
|
44
|
+
subject.trim(1)
|
45
|
+
expect(subject.size).to eq(initial_size - 1)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "add(trade_data) adds a new Trade object" do
|
49
|
+
subject.add($trade_data)
|
50
|
+
expect(subject.select{|trade| trade.timestamp == Time.parse($trade_data['timestamp'])}.first).to be_an(Excoin::Account::Trade)
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::Account do
|
4
|
+
subject {Excoin.account.wallet($currency)}
|
5
|
+
|
6
|
+
it "has complete Deposit objects" do
|
7
|
+
unless subject.deposits.empty?
|
8
|
+
subject.deposits.each_value do |deposit|
|
9
|
+
expect(deposit).to be_an(Excoin::Account::Wallet::Deposit)
|
10
|
+
expect(deposit.id).to be_a(String)
|
11
|
+
expect(deposit.timestamp).to be_a(Time)
|
12
|
+
expect(deposit.currency).to be_a(String)
|
13
|
+
expect(deposit.address).to be_a(String)
|
14
|
+
expect(deposit.amount).to be_a(BigDecimal)
|
15
|
+
expect(deposit.confirmed).to be_a(TrueClass).or be_a(FalseClass)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has complete Withdrawal objects" do
|
22
|
+
unless subject.withdrawals.empty?
|
23
|
+
subject.withdrawals.each_value do |withdrawal|
|
24
|
+
expect(withdrawal).to be_an(Excoin::Account::Wallet::Withdrawal)
|
25
|
+
expect(withdrawal.id).to be_a(String)
|
26
|
+
expect(withdrawal.timestamp).to be_a(Time)
|
27
|
+
expect(withdrawal.currency).to be_a(String)
|
28
|
+
expect(withdrawal.address).to be_a(String)
|
29
|
+
expect(withdrawal.amount).to be_a(BigDecimal)
|
30
|
+
expect(withdrawal.confirmed).to be_a(TrueClass).or be_a(FalseClass)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it ".deposits returns hash of all deposits" do
|
36
|
+
expect(subject.deposits).to be_a(Hash)
|
37
|
+
unless subject.deposits.empty?
|
38
|
+
subject.deposits.each_pair do |id, deposit_object|
|
39
|
+
expect(deposit_object).to be_a(Excoin::Account::Wallet::Deposit)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it ".withdrawals returns hash of all withdrawals" do
|
45
|
+
expect(subject.withdrawals).to be_a(Hash)
|
46
|
+
unless subject.withdrawals.empty?
|
47
|
+
subject.withdrawals.each_pair do |id, withdrawal_object|
|
48
|
+
expect(withdrawal_object).to be_a(Excoin::Account::Wallet::Withdrawal)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it ".unconfirmed_deposits returns hash" do
|
54
|
+
expect(subject.unconfirmed_deposits).to be_a(Hash)
|
55
|
+
subject.unconfirmed_deposits.each_pair do |id, deposit_object|
|
56
|
+
expect(deposit_object.confirmed).to be false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it ".unconfirmed_withdrawals returns hash" do
|
61
|
+
expect(subject.unconfirmed_withdrawals).to be_a(Hash)
|
62
|
+
subject.unconfirmed_withdrawals.each_pair do |id, withdrawal_object|
|
63
|
+
expect(withdrawal_object.confirmed).to be false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::Market::Exchange::CandlestickChart, vcr: { cassette_name: "exchange_candlestick_chart_data", match_requests_on: [:method, :uri_without_timestamp] } do
|
4
|
+
subject{Excoin::Market::Exchange::CandlestickChart.new($currency + $commodity)}
|
5
|
+
|
6
|
+
it "is a complete Excoin::Market::Exchange::CandlestickChart object" do
|
7
|
+
expect(subject).to be_an(Excoin::Market::Exchange::CandlestickChart)
|
8
|
+
expect(subject.currency).to be_a(String)
|
9
|
+
expect(subject.commodity).to be_a(String)
|
10
|
+
expect(subject.datapoints).to be_a(Array)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has complete Excoin::Market::Exchange::CandlestickChart::DataPoint objects" do
|
14
|
+
expect(subject.datapoints.first.timestamp).to be_a(Time)
|
15
|
+
expect(subject.datapoints.first.open).to be_a(BigDecimal)
|
16
|
+
expect(subject.datapoints.first.close).to be_a(BigDecimal)
|
17
|
+
expect(subject.datapoints.first.high).to be_a(BigDecimal)
|
18
|
+
expect(subject.datapoints.first.low).to be_a(BigDecimal)
|
19
|
+
expect(subject.datapoints.first.commodity_volume).to be_a(BigDecimal)
|
20
|
+
expect(subject.datapoints.first.currency_volume).to be_a(BigDecimal)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::Market::Exchange, vcr: { cassette_name: "multi_exchange_summ", match_requests_on: [:method, :uri_without_timestamp] } do
|
4
|
+
subject {Excoin.market.exchange($currency + $commodity)}
|
5
|
+
|
6
|
+
it "is a complete Excoin::Market::Exchange object" do
|
7
|
+
expect(subject.name).to be_a(String)
|
8
|
+
expect(subject.currency).to be_a(String)
|
9
|
+
expect(subject.commodity).to be_a(String)
|
10
|
+
expect(subject.last_price).to be_a(BigDecimal)
|
11
|
+
expect(subject.daily_high).to be_a(BigDecimal)
|
12
|
+
expect(subject.daily_low).to be_a(BigDecimal)
|
13
|
+
expect(subject.daily_volume).to be_a(BigDecimal)
|
14
|
+
expect(subject.top_bid).to be_a(BigDecimal)
|
15
|
+
expect(subject.lowest_ask).to be_a(BigDecimal)
|
16
|
+
expect(subject.spread).to be_a(BigDecimal)
|
17
|
+
expect(subject.orders).to be_an(Excoin::Market::Exchange::Orders)
|
18
|
+
expect(subject.trades).to be_an(Excoin::Market::Exchange::Trades)
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with sufficient funds for order", vcr: { cassette_name: "account_issue_order_erb", match_requests_on: [:method, :uri_without_timestamp], erb: true } do
|
22
|
+
it "issue_order(type, amount, price) checks wallet balance and creates order" do
|
23
|
+
VCR.use_cassette("account_summary", match_requests_on: [:method, :uri_without_timestamp]) do
|
24
|
+
if Excoin.account.wallet(subject.currency).available_balance >= BigDecimal.new($amount)
|
25
|
+
id = subject.issue_order($type, $amount, $price)
|
26
|
+
expect(Excoin.account.order(id)).to be_truthy
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "insufficient funds" do
|
33
|
+
it "issue_order returns 'insufficient funds' error", vcr: { cassette_name: "account_issue_order_erb", match_requests_on: [:method, :uri_without_timestamp], erb: true } do
|
34
|
+
expect(subject.issue_order($type, 10000, 100)).to eq("Insufficient funds for this order (#{$currency})")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::Market do
|
4
|
+
subject {Excoin.market}
|
5
|
+
|
6
|
+
it "is a complete Excoin::Market object", vcr: { cassette_name: 'multi_exchange_summ', match_requests_on: [:method, :uri_without_timestamp] } do
|
7
|
+
expect(subject.first).to be_an(Excoin::Market::Exchange)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "exchanges(currency) returns all exchanges with currency", vcr: { cassette_name: 'multi_exchange_summ_currency', match_requests_on: [:method, :uri_without_timestamp] } do
|
11
|
+
expect(subject.exchanges($currency)).to be_an(Array)
|
12
|
+
subject.exchanges($currency).each do |exchange|
|
13
|
+
expect(exchange.currency).to eq($currency)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "exchange(exchange_name) returns matching Exchange object", vcr: { cassette_name: 'single_exchange_summary', match_requests_on: [:method, :uri_without_timestamp] } do
|
18
|
+
exchange = subject.exchange($currency + $commodity)
|
19
|
+
expect(exchange).to be_an(Excoin::Market::Exchange)
|
20
|
+
expect(exchange.currency).to eq($currency)
|
21
|
+
expect(exchange.commodity).to eq($commodity)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::Market::Exchange::OrderDepthChart, vcr: { cassette_name: "exchange_order_depth_chart_data", match_requests_on: [:method, :uri_without_timestamp] } do
|
4
|
+
subject{Excoin::Market::Exchange::OrderDepthChart.new($currency + $commodity)}
|
5
|
+
|
6
|
+
it "is a complete Excoin::Market::Exchange::OrderDepthChart object" do
|
7
|
+
expect(subject).to be_an(Excoin::Market::Exchange::OrderDepthChart)
|
8
|
+
expect(subject.currency).to be_a(String)
|
9
|
+
expect(subject.commodity).to be_a(String)
|
10
|
+
expect(subject.bid_orders).to be_an(Array)
|
11
|
+
expect(subject.ask_orders).to be_an(Array)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has complete Excoin::Market::Exchange::OrderDepthChart::DataPoint objects" do
|
15
|
+
expect(subject.bid_orders.first.type).to be_a(String)
|
16
|
+
expect(subject.bid_orders.first.currency_amount).to be_a(String)
|
17
|
+
expect(subject.bid_orders.first.price).to be_a(BigDecimal)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::Market::Exchange::Orders, vcr: { cassette_name: "exchange_open_orders", match_requests_on: [:method, :uri_without_timestamp] } do
|
4
|
+
subject {Excoin.market.exchange($currency + $commodity).orders}
|
5
|
+
|
6
|
+
it "is a complete Excoin::Market::Exchange::Orders object" do
|
7
|
+
expect(subject).to be_an(Excoin::Market::Exchange::Orders)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has complete Excoin::Market::Exchange::Order objects" do
|
11
|
+
expect(subject.all.first).to be_an(Excoin::Market::Exchange::Order)
|
12
|
+
expect(subject.all.first.currency).to be_a(String)
|
13
|
+
expect(subject.all.first.commodity).to be_a(String)
|
14
|
+
expect(subject.all.first.type).to be_a(String)
|
15
|
+
expect(subject.all.first.price).to be_a(BigDecimal)
|
16
|
+
expect(subject.all.first.commodity_amount).to be_a(BigDecimal)
|
17
|
+
expect(subject.all.first.currency_amount).to be_a(BigDecimal)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "adds order to Orders" do
|
21
|
+
order = Excoin::Market::Exchange::Order.new($order_data)
|
22
|
+
expect(subject.all).to_not include(order)
|
23
|
+
subject.add(order)
|
24
|
+
expect(subject.all).to include(order)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "remove removes matching order from Orders" do
|
28
|
+
order = Excoin::Market::Exchange::Order.new($order_data)
|
29
|
+
subject.add(order)
|
30
|
+
initial_size = subject.all.size
|
31
|
+
subject.remove($order_data)
|
32
|
+
expect(subject.all.size).to eq(initial_size - 1)
|
33
|
+
end
|
34
|
+
|
35
|
+
it ".filter(attr, value, operator) returns an array matching criteria" do
|
36
|
+
subject.filter("type", $type).each do |order|
|
37
|
+
expect(order.type).to eq($type)
|
38
|
+
end
|
39
|
+
subject.filter("currency", $currency).each do |order|
|
40
|
+
expect(order.currency).to eq($currency)
|
41
|
+
end
|
42
|
+
subject.filter("price", $price, :<).each do |order|
|
43
|
+
expect(order.price).to be < BigDecimal.new($price)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::Market::Exchange::Trades, vcr: { cassette_name: "exc_recent_trades", match_requests_on: [:method, :uri_without_timestamp] } do
|
4
|
+
subject {Excoin.market.exchange($currency + $commodity).trades}
|
5
|
+
|
6
|
+
it "is a complete Excoin::Market::Exchange::Trades object" do
|
7
|
+
expect(subject).to be_an(Excoin::Market::Exchange::Trades)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has complete Excoin::Market::Exchange::Trade objects" do
|
11
|
+
expect(subject.first).to be_an(Excoin::Market::Exchange::Trade)
|
12
|
+
expect(subject.first.timestamp).to be_a(Time)
|
13
|
+
expect(subject.first.currency).to be_a(String)
|
14
|
+
expect(subject.first.commodity).to be_a(String)
|
15
|
+
expect(subject.first.type).to be_a(String)
|
16
|
+
expect(subject.first.price).to be_a(BigDecimal)
|
17
|
+
expect(subject.first.commodity_amount).to be_a(BigDecimal)
|
18
|
+
expect(subject.first.currency_amount).to be_a(BigDecimal)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "buys returns all buy trades" do
|
22
|
+
expect(subject.buys).to be_an(Array)
|
23
|
+
subject.buys.each do |trade|
|
24
|
+
expect(trade.type).to eq("BUY")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sells returns all sell trades" do
|
29
|
+
expect(subject.sells).to be_an(Array)
|
30
|
+
subject.sells.each do |trade|
|
31
|
+
expect(trade.type).to eq("SELL")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "highest returns highest priced trade" do
|
36
|
+
expect(subject.highest).to be_an(Excoin::Market::Exchange::Trade)
|
37
|
+
expect(subject.highest("sell")).to be_an(Excoin::Market::Exchange::Trade)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "trim(n) removes n trades" do
|
41
|
+
initial_size = subject.size
|
42
|
+
subject.trim(1)
|
43
|
+
expect(subject.size).to eq(initial_size - 1)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "add(trade_data) adds a new Trade object" do
|
47
|
+
subject.add($exchange_trade_data)
|
48
|
+
expect(subject.select{|trade| trade.timestamp == Time.parse($trade_data['timestamp'])}.first).to be_an(Excoin::Market::Exchange::Trade)
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,228 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Excoin::API do
|
4
|
+
subject {Excoin.api}
|
5
|
+
|
6
|
+
describe "multiple_exchange_summary" do
|
7
|
+
context "without parameters" do
|
8
|
+
it "returns array of exchange hashes", vcr: { cassette_name: 'multi_exchange_summ', match_requests_on: [:method, :uri_without_timestamp] } do
|
9
|
+
response_body = subject.multiple_exchange_summary
|
10
|
+
expect(response_body).to be_an(Array)
|
11
|
+
expect(response_body.first).to be_a(Hash)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with currency parameter" do
|
16
|
+
it "returns exchange array by currency", vcr: { cassette_name: 'multi_exchange_summ_currency', match_requests_on: [:method, :uri_without_timestamp] } do
|
17
|
+
response_body = subject.multiple_exchange_summary($currency)
|
18
|
+
expect(response_body).to be_an(Array)
|
19
|
+
response_body.each do |exchange|
|
20
|
+
expect(exchange['currency']).to eq($currency)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "exchange_summary" do
|
27
|
+
it "returns exchange summary hash", vcr: { cassette_name: "single_exchange_summary", match_requests_on: [:method, :uri_without_timestamp] } do
|
28
|
+
response_body = subject.exchange_summary($currency, $commodity)
|
29
|
+
expect(response_body["currency"]).to eq($currency)
|
30
|
+
expect(response_body["commodity"]).to eq($commodity)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "exchange_recent_trades" do
|
35
|
+
context "without params" do
|
36
|
+
it "returns recent trades array", vcr: { cassette_name: "exc_recent_trades", match_requests_on: [:method, :uri_without_timestamp] } do
|
37
|
+
response_body = subject.exchange_recent_trades($currency, $commodity)
|
38
|
+
expect(response_body.has_key?("trades")).to be true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context "with count limit" do
|
42
|
+
it "returns recent trades array", vcr: { cassette_name: "exc_recent_trades_count", match_requests_on: [:method, :uri_without_timestamp] } do
|
43
|
+
response_body = subject.exchange_recent_trades($currency, $commodity, "count", "5")
|
44
|
+
expect(response_body.has_key?("trades")).to be true
|
45
|
+
expect(response_body["count"]).to eq(5)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context "with timestamp limit" do
|
49
|
+
it "returns recent trades array", vcr: { cassette_name: "exc_recent_trades_timestamp", match_requests_on: [:method, :uri_without_timestamp], record: :new_episodes } do
|
50
|
+
time_utc= Time.now.utc - 24*60*60
|
51
|
+
time_limit = time_utc.to_i
|
52
|
+
response_body = subject.exchange_recent_trades($currency, $commodity, "timestamp", time_limit)
|
53
|
+
response_body["trades"].each do |trade|
|
54
|
+
expect(Time.parse(trade["timestamp"])).to be > time_utc
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "exchange_open_orders" do
|
61
|
+
context "without type parameter" do
|
62
|
+
it "returns exchange open orders array", vcr: { cassette_name: "exchange_open_orders", match_requests_on: [:method, :uri_without_timestamp] } do
|
63
|
+
response_body = subject.exchange_open_orders($currency, $commodity)
|
64
|
+
expect(response_body).to be_an(Array)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "with type parameter" do
|
69
|
+
it "returns exchange open orders array, grouped by type", vcr: { cassette_name: "exchange_open_orders_type", match_requests_on: [:method, :uri_without_timestamp] } do
|
70
|
+
response_body = subject.exchange_open_orders($currency, $commodity, $type)
|
71
|
+
expect(response_body["type"]).to eq($type)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "exchange_candlestick_chart_data" do
|
77
|
+
context "without parameters" do
|
78
|
+
it "returns array of datapoint hashes", vcr: { cassette_name: "exchange_candlestick_chart_data", match_requests_on: [:method, :uri_without_timestamp] } do
|
79
|
+
response_body = subject.exchange_candlestick_chart_data($currency, $commodity)
|
80
|
+
expect(response_body).to be_an(Array)
|
81
|
+
expect(response_body.first).to be_a(Hash)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with duration parameter" do
|
86
|
+
it "returns array of datapoint hashes", vcr: { cassette_name: "exchange_candlestick_chart_data_duration", match_requests_on: [:method, :uri_without_timestamp] } do
|
87
|
+
response_body = subject.exchange_candlestick_chart_data($currency, $commodity, "1D")
|
88
|
+
expect(response_body).to be_an(Array)
|
89
|
+
expect(Time.parse(response_body.last['timestamp']) - Time.parse(response_body.first['timestamp'])).to be <= 86400
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "exchange_order_depth_chart_data" do
|
95
|
+
it "returns array of datapoint hashes", vcr: { cassette_name: "exchange_order_depth_chart_data", match_requests_on: [:method, :uri_without_timestamp] } do
|
96
|
+
response_body = subject.exchange_order_depth_chart_data($currency, $commodity)
|
97
|
+
expect(response_body).to be_an(Array)
|
98
|
+
expect(response_body.first).to be_a(Hash)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "account_summary" do
|
103
|
+
it "returns account summary array", vcr: { cassette_name: "account_summary", match_requests_on: [:method, :uri_without_timestamp] } do
|
104
|
+
response_body = subject.account_summary
|
105
|
+
expect(response_body['username']).to be_a(String)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "account_withdraw" do
|
110
|
+
it "returns withdrawal hash", vcr: { cassette_name: "account_withdraw", match_requests_on: [:method, :uri_without_timestamp], record: :new_episodes } do
|
111
|
+
response_body = subject.account_withdraw($currency, $address, $amount)
|
112
|
+
expect(response_body['address']).to eq($address)
|
113
|
+
expect(response_body['amount']).to eq($amount)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "account_generate_deposit_address" do
|
118
|
+
it "returns hash with address", vcr: { cassette_name: "account_generate_deposit_address", match_requests_on: [:method, :uri_without_timestamp] } do
|
119
|
+
response_body = subject.account_generate_deposit_address($commodity)
|
120
|
+
expect(response_body['address']).to match(/\A[\S][a-km-zA-HJ-NP-Z0-9]{26,33}\z/)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "account_trades" do
|
125
|
+
context "with default count parameter (100)" do
|
126
|
+
it "returns hash with counts and trades hashes", vcr: { cassette_name: "account_trades", match_requests_on: [:method, :uri_without_timestamp] } do
|
127
|
+
response_body = subject.account_trades
|
128
|
+
expect(response_body.has_key?("trades")).to be true
|
129
|
+
expect(response_body["trades"].size).to be <= 100
|
130
|
+
expect(response_body["count"].to_i).to be <= 100
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "with custom count parameter (#{$count})" do
|
135
|
+
it "returns hash with counts and trades hashes", vcr: { cassette_name: "account_trades_count", match_requests_on: [:method, :uri_without_timestamp] } do
|
136
|
+
response_body = subject.account_trades($count)
|
137
|
+
expect(response_body.has_key?("trades")).to be true
|
138
|
+
expect(response_body["trades"].size).to be <= $count
|
139
|
+
expect(response_body["count"].to_i).to be <= $count
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "account_open_orders" do
|
145
|
+
context "without parameters" do
|
146
|
+
it "returns array of exchange+type hashes", vcr: { cassette_name: "account_open_orders", match_requests_on: [:method, :uri_without_timestamp] } do
|
147
|
+
response_body = subject.account_open_orders
|
148
|
+
expect(response_body).to be_an(Array)
|
149
|
+
expect(response_body.first).to be_a(Hash)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "with currency and commodity parameters" do
|
154
|
+
it "returns hash of bids and asks for the currency and commodity specified", vcr: { cassette_name: "account_open_orders_exchange",
|
155
|
+
match_requests_on: [:method, :uri_without_timestamp] } do
|
156
|
+
response_body = subject.account_open_orders($currency, $commodity)
|
157
|
+
expect(response_body["currency"]).to eq($currency)
|
158
|
+
expect(response_body["commodity"]).to eq($commodity)
|
159
|
+
expect(response_body["orders"].count).to eq(2)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "with currency, commodity, and type parameters" do
|
164
|
+
it "returns a hash for the currency, commodity, and type specified", vcr: { cassette_name: "account_open_orders_exchange_type",
|
165
|
+
match_requests_on: [:method, :uri_without_timestamp] } do
|
166
|
+
response_body = subject.account_open_orders($currency, $commodity, $type)
|
167
|
+
expect(response_body["orders"].first["type"]).to eq($type)
|
168
|
+
expect(response_body["currency"]).to eq($currency)
|
169
|
+
expect(response_body["commodity"]).to eq($commodity)
|
170
|
+
expect(response_body["orders"].count).to eq(1)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "account issue_order" do
|
176
|
+
it "returns an order hash", vcr: { cassette_name: "account_issue_order_erb", match_requests_on: [:method, :uri_without_timestamp], erb: true } do
|
177
|
+
response_body = subject.account_issue_order($currency, $commodity, $type, $amount, $price)
|
178
|
+
expect(response_body["type"]).to eq($type)
|
179
|
+
expect(BigDecimal.new(response_body["price"])).to eq(BigDecimal.new($price))
|
180
|
+
if $type == "BID"
|
181
|
+
expect(BigDecimal.new(response_body["currency_amount"])).to eq(BigDecimal.new($amount))
|
182
|
+
elsif $type == "ASK"
|
183
|
+
expect(BigDecimal.new(response_body["commodity_amount"])).to eq(BigDecimal.new($amount))
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "account_view_order" do
|
189
|
+
it "returns an order hash matching #{$order_id}", vcr: { cassette_name: "account_view_order_erb", match_requests_on: [:method, :uri_without_timestamp], erb: { order_id: $order_id } } do
|
190
|
+
response_body = subject.account_view_order($order_id)
|
191
|
+
expect(response_body["id"]).to eq($order_id)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "account_cancel_order" do
|
196
|
+
it "returns an order hash matching #{$order_id}", vcr: { cassette_name: "account_cancel_order_erb", match_requests_on: [:method, :uri_without_timestamp], erb: { order_id: $order_id } } do
|
197
|
+
response_body = subject.account_cancel_order($order_id)
|
198
|
+
expect(response_body["id"]).to eq($order_id)
|
199
|
+
expect(response_body["status"]).to eq("CLOSED")
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "excoin_wallets_summary" do
|
204
|
+
context "without coin parameter" do
|
205
|
+
it "returns array of wallet hashes", vcr: { cassette_name: "excoin_wallets_summary", match_requests_on: [:method, :uri_without_timestamp] } do
|
206
|
+
response_body = subject.excoin_wallets_summary
|
207
|
+
expect(response_body).to be_an(Array)
|
208
|
+
expect(response_body.first.has_key?("iso_code")).to be true
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "with coin parameter" do
|
213
|
+
it "returns wallet hash", vcr: { cassette_name: "excoin_wallets_summary_coin", match_requests_on: [:method, :uri_without_timestamp] } do
|
214
|
+
response_body = subject.excoin_wallets_summary($currency)
|
215
|
+
expect(response_body["iso_code"]).to eq($currency)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "excoin_wallet_reserves(currency)" do
|
221
|
+
it "returns a hash with reserve info ", vcr: { cassette_name: "excoin_wallet_reserves", match_requests_on: [:method, :uri_without_timestamp] } do
|
222
|
+
response_body = subject.excoin_wallet_reserves($currency)
|
223
|
+
expect(response_body["iso_code"]).to eq($currency)
|
224
|
+
expect(response_body["hot_addresses"]).to be_an(Array)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|