cointrader.net 0.7.0 → 0.8.0
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 +4 -4
- data/lib/cointrader.net/client/order.rb +11 -1
- data/lib/cointrader.net/client/request.rb +19 -3
- data/lib/cointrader.net/version.rb +1 -1
- data/spec/client_spec.rb +51 -26
- data/spec/fixtures/vcr_cassettes/balance.yml +39 -54
- data/spec/fixtures/vcr_cassettes/cancel.yml +39 -38
- data/spec/fixtures/vcr_cassettes/limit_buy.yml +7 -6
- data/spec/fixtures/vcr_cassettes/limit_sell.yml +7 -6
- data/spec/fixtures/vcr_cassettes/list.yml +39 -58
- data/spec/fixtures/vcr_cassettes/market_buy.yml +71 -0
- data/spec/fixtures/vcr_cassettes/market_sell.yml +72 -0
- data/spec/fixtures/vcr_cassettes/orders.yml +40 -84
- data/spec/fixtures/vcr_cassettes/stats_24h.yml +40 -46
- data/spec/fixtures/vcr_cassettes/stats_7d.yml +40 -46
- data/spec/fixtures/vcr_cassettes/symbol.yml +41 -53
- data/spec/fixtures/vcr_cassettes/tradehistory.yml +39 -46
- data/spec/fixtures/vcr_cassettes/trades.yml +37 -84
- data/spec/spec_helper.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c04efa6cfe08064cb0a38a0a0833cd0c381e7c1f
|
4
|
+
data.tar.gz: 3ff238c3c11eddece8093c43a0dd36c94f2135d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 174fa7f56e4f7c47e43a560eec5bca74b7f39646151b1e5c49025155e753bc17f52356019052a4cd61883ebc0e67ed9072c749fd401335509dc949c3aa458c8a
|
7
|
+
data.tar.gz: 8c8f63407026fdf073e2daf634fdaa68b2286148e2cabc6583f825990c5736303153897aef0a5fdd6cb08df90e5bd59160fd28f4ec9da027e0392c867ab6cd47
|
@@ -12,12 +12,22 @@ module Cointrader
|
|
12
12
|
|
13
13
|
def cancel params={}
|
14
14
|
params = get_defaults(params)
|
15
|
-
request(:post, "/order/#{params[:currency_pair]}/cancel")
|
15
|
+
request(:post, "/order/#{params[:currency_pair]}/cancel", order_id: params[:order_id])
|
16
16
|
end
|
17
17
|
|
18
18
|
def list params={}
|
19
19
|
params = get_defaults(params)
|
20
20
|
request(:post, "/order/#{params[:currency_pair]}/list")
|
21
21
|
end
|
22
|
+
|
23
|
+
def market_buy params={}
|
24
|
+
params = get_defaults(params)
|
25
|
+
request(:post, "/order/#{params[:currency_pair]}/marketbuy", total_amount: params[:total_amount])
|
26
|
+
end
|
27
|
+
|
28
|
+
def market_sell params={}
|
29
|
+
params = get_defaults(params)
|
30
|
+
request(:post, "/order/#{params[:currency_pair]}/marketsell", total_amount: params[:total_amount])
|
31
|
+
end
|
22
32
|
end
|
23
33
|
end
|
@@ -14,11 +14,28 @@ module Cointrader
|
|
14
14
|
names.map { |name| params[name] }.compact.join('/')
|
15
15
|
end
|
16
16
|
|
17
|
+
def convert_values params
|
18
|
+
pairs = params.map do |k, v|
|
19
|
+
new_value =
|
20
|
+
if k.match(/price|total_amount/)
|
21
|
+
"%04.2f" % v
|
22
|
+
elsif k.match(/amount|quantity/)
|
23
|
+
"%04.8f" % v
|
24
|
+
else
|
25
|
+
v
|
26
|
+
end
|
27
|
+
|
28
|
+
[k, new_value]
|
29
|
+
end
|
30
|
+
|
31
|
+
Hash[pairs]
|
32
|
+
end
|
33
|
+
|
17
34
|
def get_defaults params
|
18
35
|
defaults = {
|
19
36
|
currency_pair: Client::DEFAULT_CURRENCY_PAIR
|
20
37
|
}
|
21
|
-
defaults.merge(params)
|
38
|
+
defaults.merge(convert_values(params))
|
22
39
|
end
|
23
40
|
|
24
41
|
def request(method, path, body={})
|
@@ -39,10 +56,9 @@ module Cointrader
|
|
39
56
|
|
40
57
|
raise 'API key and API secret are required!' unless api_key && api_secret
|
41
58
|
|
42
|
-
nonce = DateTime.now.strftime('%Q')
|
43
59
|
payload = body.merge({
|
44
60
|
secret: api_secret,
|
45
|
-
t:
|
61
|
+
t: Time.now.utc.to_s
|
46
62
|
})
|
47
63
|
|
48
64
|
digest = OpenSSL::Digest.new('sha256')
|
data/spec/client_spec.rb
CHANGED
@@ -9,6 +9,14 @@ describe Cointrader::Client do
|
|
9
9
|
subject.limit_sell(total_quantity: 1, price: 10)
|
10
10
|
end
|
11
11
|
|
12
|
+
def market_buy
|
13
|
+
subject.market_buy(total_amount: 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
def market_sell
|
17
|
+
subject.market_sell(total_amount: 1)
|
18
|
+
end
|
19
|
+
|
12
20
|
def safe_limit_buy
|
13
21
|
VCR.use_cassette('limit_buy', &method(:limit_buy))
|
14
22
|
end
|
@@ -17,44 +25,48 @@ describe Cointrader::Client do
|
|
17
25
|
VCR.use_cassette('limit_sell', &method(:limit_sell))
|
18
26
|
end
|
19
27
|
|
28
|
+
def safe_market_buy
|
29
|
+
VCR.use_cassette('market_buy', &method(:market_buy))
|
30
|
+
end
|
31
|
+
|
32
|
+
def safe_market_sell
|
33
|
+
VCR.use_cassette('market_sell', &method(:market_sell))
|
34
|
+
end
|
35
|
+
|
20
36
|
describe 'stats' do
|
21
37
|
describe '#symbol' do
|
22
38
|
it 'returns supported currencies' do
|
23
39
|
VCR.use_cassette('symbol') do
|
24
40
|
response = subject.symbol
|
25
|
-
|
26
|
-
expect(response).not_to be_nil
|
41
|
+
expect_success(response)
|
27
42
|
expect(response['data'][0]['name']).to eq 'Bitcoin (BTC)'
|
28
43
|
end
|
29
44
|
end
|
30
45
|
end
|
31
46
|
|
32
|
-
# TODO(maros): Add more detailed tests.
|
33
47
|
describe '#stats_24h' do
|
34
48
|
it 'returns 24 hour sliding statistics' do
|
35
49
|
VCR.use_cassette('stats_24h') do
|
36
50
|
response = subject.stats_24h
|
37
|
-
|
51
|
+
expect_success(response)
|
38
52
|
end
|
39
53
|
end
|
40
54
|
end
|
41
55
|
|
42
|
-
# TODO(maros): Add more detailed tests.
|
43
56
|
describe '#stats_7d' do
|
44
57
|
it 'returns 7 day sliding statistics' do
|
45
58
|
VCR.use_cassette('stats_7d') do
|
46
59
|
response = subject.stats_7d
|
47
|
-
|
60
|
+
expect_success(response)
|
48
61
|
end
|
49
62
|
end
|
50
63
|
end
|
51
64
|
|
52
|
-
# TODO(maros): Add more detailed tests.
|
53
65
|
describe '#orders' do
|
54
66
|
it 'returns open orders' do
|
55
67
|
VCR.use_cassette('orders') do
|
56
68
|
response = subject.orders
|
57
|
-
|
69
|
+
expect_success(response)
|
58
70
|
end
|
59
71
|
end
|
60
72
|
end
|
@@ -66,7 +78,7 @@ describe Cointrader::Client do
|
|
66
78
|
VCR.use_cassette('balance') do
|
67
79
|
response = subject.balance
|
68
80
|
|
69
|
-
|
81
|
+
expect_success(response)
|
70
82
|
expect(response['data']['BTC']['available']).not_to be_nil
|
71
83
|
end
|
72
84
|
end
|
@@ -76,9 +88,7 @@ describe Cointrader::Client do
|
|
76
88
|
it 'returns trade history' do
|
77
89
|
VCR.use_cassette('tradehistory') do
|
78
90
|
response = subject.tradehistory
|
79
|
-
|
80
|
-
expect(response).not_to be_nil
|
81
|
-
expect(response['data'][0]['fee']).not_to be_nil
|
91
|
+
expect_success(response)
|
82
92
|
end
|
83
93
|
end
|
84
94
|
end
|
@@ -89,8 +99,7 @@ describe Cointrader::Client do
|
|
89
99
|
it 'returns an order' do
|
90
100
|
VCR.use_cassette('limit_buy') do
|
91
101
|
response = limit_buy
|
92
|
-
|
93
|
-
expect(response).not_to be_nil
|
102
|
+
expect_success(response)
|
94
103
|
expect(response['data']['id']).not_to be_nil
|
95
104
|
end
|
96
105
|
end
|
@@ -100,8 +109,7 @@ describe Cointrader::Client do
|
|
100
109
|
it 'returns an order' do
|
101
110
|
VCR.use_cassette('limit_sell') do
|
102
111
|
response = limit_sell
|
103
|
-
|
104
|
-
expect(response).not_to be_nil
|
112
|
+
expect_success(response)
|
105
113
|
expect(response['data']['id']).not_to be_nil
|
106
114
|
end
|
107
115
|
end
|
@@ -112,11 +120,10 @@ describe Cointrader::Client do
|
|
112
120
|
|
113
121
|
it 'cancels and order' do
|
114
122
|
VCR.use_cassette('cancel') do
|
115
|
-
response = subject.cancel(
|
116
|
-
|
117
|
-
expect(response).not_to be_nil
|
118
|
-
expect(response['data']['
|
119
|
-
expect(response['data']['currency_pair']).not_to be_nil
|
123
|
+
response = subject.cancel(order_id: order['data']['id'])
|
124
|
+
expect_success(response)
|
125
|
+
# expect(response['data']['id']).not_to be_nil
|
126
|
+
# expect(response['data']['currency_pair']).not_to be_nil
|
120
127
|
end
|
121
128
|
end
|
122
129
|
end
|
@@ -125,9 +132,28 @@ describe Cointrader::Client do
|
|
125
132
|
it 'lists open limit orders' do
|
126
133
|
VCR.use_cassette('list') do
|
127
134
|
response = subject.list
|
135
|
+
expect_success(response)
|
136
|
+
# expect(response['data'][0]['type'])
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#market_buy' do
|
142
|
+
it 'returns an order' do
|
143
|
+
VCR.use_cassette('market_buy') do
|
144
|
+
response = market_buy
|
145
|
+
expect_success(response)
|
146
|
+
expect(response['message']).not_to eq('Unauthorized')
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
128
150
|
|
129
|
-
|
130
|
-
|
151
|
+
describe '#market_sell' do
|
152
|
+
it 'returns an order' do
|
153
|
+
VCR.use_cassette('market_sell') do
|
154
|
+
response = market_sell
|
155
|
+
expect_success(response)
|
156
|
+
expect(response['message']).not_to eq('Unauthorized')
|
131
157
|
end
|
132
158
|
end
|
133
159
|
end
|
@@ -136,9 +162,8 @@ describe Cointrader::Client do
|
|
136
162
|
it 'lists recent trades executed' do
|
137
163
|
VCR.use_cassette('trades') do
|
138
164
|
response = subject.trades
|
139
|
-
|
140
|
-
expect(response)
|
141
|
-
expect(response['data'][0]['price'])
|
165
|
+
expect_success(response)
|
166
|
+
# expect(response['data'][0]['price'])
|
142
167
|
end
|
143
168
|
end
|
144
169
|
end
|
@@ -2,10 +2,11 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://
|
5
|
+
uri: https://sandbox.cointrader.net/api4/account/balance
|
6
6
|
body:
|
7
7
|
encoding: UTF-8
|
8
|
-
string: '{"secret":"
|
8
|
+
string: '{"secret":"2MlxW8mUU9MG4bvq7C6M4PSd5J8SaauW4H2dXnyJyAcN","t":"2015-06-13
|
9
|
+
23:00:21 UTC"}'
|
9
10
|
headers:
|
10
11
|
Accept:
|
11
12
|
- "*/*; q=0.5, application/xml"
|
@@ -14,11 +15,11 @@ http_interactions:
|
|
14
15
|
Content-Type:
|
15
16
|
- application/json
|
16
17
|
X-Auth:
|
17
|
-
-
|
18
|
+
- nCsNvmrxTpYFnJQyU16gq6R9ncOUA6UhF4wZnuf7IqkL
|
18
19
|
X-Auth-Hash:
|
19
|
-
-
|
20
|
+
- 149ab2f07d5f872b8244e00a63e7978aa961760215f523c46869aba6c69b41a9
|
20
21
|
Content-Length:
|
21
|
-
- '
|
22
|
+
- '87'
|
22
23
|
User-Agent:
|
23
24
|
- Ruby
|
24
25
|
response:
|
@@ -26,56 +27,40 @@ http_interactions:
|
|
26
27
|
code: 200
|
27
28
|
message: OK
|
28
29
|
headers:
|
29
|
-
Server:
|
30
|
-
- Cowboy
|
31
|
-
Connection:
|
32
|
-
- keep-alive
|
33
|
-
X-Apiary-Ratelimit-Limit:
|
34
|
-
- '120'
|
35
|
-
X-Apiary-Ratelimit-Remaining:
|
36
|
-
- '115'
|
37
|
-
Access-Control-Allow-Origin:
|
38
|
-
- "*"
|
39
|
-
Access-Control-Allow-Methods:
|
40
|
-
- OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT
|
41
|
-
Access-Control-Max-Age:
|
42
|
-
- '10'
|
43
|
-
X-Apiary-Transaction-Id:
|
44
|
-
- 556ab7d01197a90300fefd03
|
45
30
|
Date:
|
46
|
-
-
|
47
|
-
|
48
|
-
-
|
49
|
-
|
50
|
-
-
|
31
|
+
- Sat, 13 Jun 2015 23:00:26 GMT
|
32
|
+
Server:
|
33
|
+
- Apache
|
34
|
+
X-Frame-Options:
|
35
|
+
- SAMEORIGIN
|
36
|
+
X-Xss-Protection:
|
37
|
+
- 1; mode=block
|
38
|
+
X-Content-Type-Options:
|
39
|
+
- nosniff
|
40
|
+
X-Powered-By:
|
41
|
+
- ''
|
42
|
+
Set-Cookie:
|
43
|
+
- CTXIDSCK=rumaii5548fj7n7g95sjggu251; path=/; HttpOnly
|
44
|
+
Expires:
|
45
|
+
- Thu, 19 Nov 1981 08:52:00 GMT
|
46
|
+
Cache-Control:
|
47
|
+
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
48
|
+
Pragma:
|
49
|
+
- no-cache
|
50
|
+
Vary:
|
51
|
+
- Accept-Encoding
|
52
|
+
Content-Encoding:
|
53
|
+
- gzip
|
54
|
+
Content-Length:
|
55
|
+
- '131'
|
56
|
+
Content-Type:
|
57
|
+
- application/json
|
51
58
|
body:
|
52
|
-
encoding:
|
53
|
-
string:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
"data":
|
58
|
-
{
|
59
|
-
"BTC":
|
60
|
-
{
|
61
|
-
"available":"5.26240216",
|
62
|
-
"on_hold":"0.00000000",
|
63
|
-
"total":"5.26240216"
|
64
|
-
},
|
65
|
-
"USD":
|
66
|
-
{
|
67
|
-
"available":"0.35",
|
68
|
-
"on_hold":"0.00",
|
69
|
-
"total":"0.35"
|
70
|
-
},
|
71
|
-
"CAD":
|
72
|
-
{
|
73
|
-
"available":"1.41",
|
74
|
-
"on_hold":"0.00",
|
75
|
-
"total":"1.41"
|
76
|
-
}
|
77
|
-
}
|
78
|
-
}
|
59
|
+
encoding: ASCII-8BIT
|
60
|
+
string: !binary |-
|
61
|
+
H4sIAAAAAAAAA6tWKi5NTk4tLlayKikqTdVRygWyE9NTlayUHJOT80vzShSc
|
62
|
+
EnMS84BKlHSUUhJLEpWsqpWcQpxBVGJZYmZOYlIOSLWBngEUANXl58Vn5Oek
|
63
|
+
oAuX5Jck5qAK1uoohQa7YDMMwxg0A0BanR3J1FpbywUAkRGfN/oAAAA=
|
79
64
|
http_version:
|
80
|
-
recorded_at:
|
65
|
+
recorded_at: Sat, 13 Jun 2015 23:00:26 GMT
|
81
66
|
recorded_with: VCR 2.9.3
|
@@ -2,10 +2,11 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://
|
5
|
+
uri: https://sandbox.cointrader.net/api4/order/BTCUSD/cancel
|
6
6
|
body:
|
7
7
|
encoding: UTF-8
|
8
|
-
string: '{"secret":"
|
8
|
+
string: '{"order_id":"2222321","secret":"2MlxW8mUU9MG4bvq7C6M4PSd5J8SaauW4H2dXnyJyAcN","t":"2015-06-13
|
9
|
+
23:01:51 UTC"}'
|
9
10
|
headers:
|
10
11
|
Accept:
|
11
12
|
- "*/*; q=0.5, application/xml"
|
@@ -14,11 +15,11 @@ http_interactions:
|
|
14
15
|
Content-Type:
|
15
16
|
- application/json
|
16
17
|
X-Auth:
|
17
|
-
-
|
18
|
+
- nCsNvmrxTpYFnJQyU16gq6R9ncOUA6UhF4wZnuf7IqkL
|
18
19
|
X-Auth-Hash:
|
19
|
-
-
|
20
|
+
- f6f960802d0ec32112a9b5c659ceac1a46cbe62ad22bdc38070451fa0c09ae50
|
20
21
|
Content-Length:
|
21
|
-
- '
|
22
|
+
- '108'
|
22
23
|
User-Agent:
|
23
24
|
- Ruby
|
24
25
|
response:
|
@@ -26,40 +27,40 @@ http_interactions:
|
|
26
27
|
code: 200
|
27
28
|
message: OK
|
28
29
|
headers:
|
29
|
-
Server:
|
30
|
-
- Cowboy
|
31
|
-
Connection:
|
32
|
-
- keep-alive
|
33
|
-
X-Apiary-Ratelimit-Limit:
|
34
|
-
- '120'
|
35
|
-
X-Apiary-Ratelimit-Remaining:
|
36
|
-
- '111'
|
37
|
-
Access-Control-Allow-Origin:
|
38
|
-
- "*"
|
39
|
-
Access-Control-Allow-Methods:
|
40
|
-
- OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE,CONNECT
|
41
|
-
Access-Control-Max-Age:
|
42
|
-
- '10'
|
43
|
-
X-Apiary-Transaction-Id:
|
44
|
-
- 556ab7d42e7cbc030044b280
|
45
30
|
Date:
|
46
|
-
-
|
47
|
-
|
48
|
-
-
|
49
|
-
|
50
|
-
-
|
31
|
+
- Sat, 13 Jun 2015 23:01:53 GMT
|
32
|
+
Server:
|
33
|
+
- Apache
|
34
|
+
X-Frame-Options:
|
35
|
+
- SAMEORIGIN
|
36
|
+
X-Xss-Protection:
|
37
|
+
- 1; mode=block
|
38
|
+
X-Content-Type-Options:
|
39
|
+
- nosniff
|
40
|
+
X-Powered-By:
|
41
|
+
- ''
|
42
|
+
Set-Cookie:
|
43
|
+
- CTXIDSCK=pmv8crr36dojr43dlq3784r1d1; path=/; HttpOnly
|
44
|
+
Expires:
|
45
|
+
- Thu, 19 Nov 1981 08:52:00 GMT
|
46
|
+
Cache-Control:
|
47
|
+
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
48
|
+
Pragma:
|
49
|
+
- no-cache
|
50
|
+
Vary:
|
51
|
+
- Accept-Encoding
|
52
|
+
Content-Encoding:
|
53
|
+
- gzip
|
54
|
+
Content-Length:
|
55
|
+
- '114'
|
56
|
+
Content-Type:
|
57
|
+
- application/json
|
51
58
|
body:
|
52
|
-
encoding:
|
53
|
-
string: |-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
"data":
|
58
|
-
{
|
59
|
-
"id":"85",
|
60
|
-
"currency_pair":"BTCAD"
|
61
|
-
}
|
62
|
-
}
|
59
|
+
encoding: ASCII-8BIT
|
60
|
+
string: !binary |-
|
61
|
+
H4sIAAAAAAAAA6tWKi5NTk4tLlaySkvMKU7VUcoFchLTU5WslPyLUlKLFPzy
|
62
|
+
SxTc8kvzUpR0lFISSxKVrKqVUouK8ouc81NAqiwMDJSQdYVkpCrkg3Wm5KcW
|
63
|
+
56mXKKRWZBaX6CnV1nIBAHEGK69uAAAA
|
63
64
|
http_version:
|
64
|
-
recorded_at:
|
65
|
+
recorded_at: Sat, 13 Jun 2015 23:01:55 GMT
|
65
66
|
recorded_with: VCR 2.9.3
|