cryptomarket-sdk 1.0.1 → 3.0.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/README.md +156 -70
- data/lib/cryptomarket/client.rb +1154 -730
- data/lib/cryptomarket/constants.rb +123 -0
- data/lib/cryptomarket/credentials_factory.rb +53 -0
- data/lib/cryptomarket/exceptions.rb +18 -19
- data/lib/cryptomarket/http_manager.rb +98 -0
- data/lib/cryptomarket/websocket/auth_client.rb +72 -0
- data/lib/cryptomarket/websocket/callback_cache.rb +54 -0
- data/lib/cryptomarket/websocket/client_base.rb +135 -0
- data/lib/cryptomarket/websocket/market_data_client.rb +302 -0
- data/lib/cryptomarket/websocket/market_data_client_core.rb +62 -0
- data/lib/cryptomarket/websocket/methods.rb +36 -54
- data/lib/cryptomarket/websocket/reusable_callback.rb +21 -0
- data/lib/cryptomarket/websocket/trading_client.rb +274 -0
- data/lib/cryptomarket/websocket/wallet_client.rb +170 -0
- data/lib/cryptomarket/websocket/ws_manager.rb +65 -0
- metadata +77 -18
- data/lib/cryptomarket/HttpManager.rb +0 -75
- data/lib/cryptomarket/utils.rb +0 -57
- data/lib/cryptomarket/websocket/accountClient.rb +0 -150
- data/lib/cryptomarket/websocket/authClient.rb +0 -53
- data/lib/cryptomarket/websocket/callbackCache.rb +0 -51
- data/lib/cryptomarket/websocket/orderbookCache.rb +0 -123
- data/lib/cryptomarket/websocket/publicClient.rb +0 -275
- data/lib/cryptomarket/websocket/tradingClient.rb +0 -134
- data/lib/cryptomarket/websocket/wsClientBase.rb +0 -158
- data/lib/cryptomarket/websocket/wsManager.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b00c37cd577d6d79dd8e65c6333a5122d28728fa3023f24aa7ca0b13eab2bf6
|
4
|
+
data.tar.gz: a2523b57da4464aed4a0c655fe7316c4445b57cfa622d85425c583e70b424303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6f0bf8e26c38b44f686d36b5103ee56eeca2319ab30aa4552c180e8f4535a3aabd8d5b86b38b6c6e05d256cf85f4a9208d9e2877e04cd6ceaa9b42b97545d36
|
7
|
+
data.tar.gz: b859df27e046ecb43e678c4b2e9ca0b3dc03007dbc259c7d56ac23f79fa16b7850f6cfaa1ca7502aa7b477a9833974616b352e874a460d4c0f6c84a0b5da5f07
|
data/README.md
CHANGED
@@ -1,129 +1,216 @@
|
|
1
1
|
# CryptoMarket-Ruby
|
2
|
-
[main page](https://www.cryptomkt.com/)
|
3
2
|
|
3
|
+
[main page](https://www.cryptomkt.com/)
|
4
4
|
|
5
5
|
[sign up in CryptoMarket](https://www.cryptomkt.com/account/register).
|
6
6
|
|
7
7
|
# Installation
|
8
|
+
|
8
9
|
To install Cryptomarket use gem
|
10
|
+
|
9
11
|
```
|
10
12
|
gem install cryptomarket-sdk
|
11
13
|
```
|
14
|
+
|
12
15
|
# Documentation
|
13
|
-
|
16
|
+
|
17
|
+
This sdk makes use of the [api version 3](https://api.exchange.cryptomkt.com/) of cryptomarket
|
14
18
|
|
15
19
|
# Quick Start
|
16
20
|
|
17
21
|
## rest client
|
22
|
+
|
18
23
|
```ruby
|
19
|
-
require "cryptomarket"
|
24
|
+
require "cryptomarket-sdk"
|
20
25
|
|
21
26
|
# instance a client
|
22
27
|
api_key='AB32B3201'
|
23
28
|
api_secret='21b12401'
|
24
|
-
client = Cryptomarket::Client.new
|
29
|
+
client = Cryptomarket::Client.new api_key:api_key, api_secret:api_secret
|
25
30
|
|
26
31
|
# get currencies
|
27
|
-
currencies = client.
|
32
|
+
currencies = client.get_currencies
|
28
33
|
|
29
34
|
# get order books
|
30
|
-
order_book = client.
|
35
|
+
order_book = client.get_orderbooks symbols:['EOSETH']
|
31
36
|
|
32
37
|
# get your account balances
|
33
|
-
account_balance = client.
|
38
|
+
account_balance = client.get_wallet_balances
|
34
39
|
|
35
40
|
# get your trading balances
|
36
|
-
trading_balance = client.
|
41
|
+
trading_balance = client.get_spot_trading_balances
|
37
42
|
|
38
43
|
# move balance from account bank to account trading
|
39
|
-
result = client.
|
44
|
+
result = @client.transfer_between_wallet_and_exchange(
|
45
|
+
currency: "CRO",
|
46
|
+
amount: "0.1",
|
47
|
+
source:"wallet",
|
48
|
+
destination:"spot",
|
49
|
+
)
|
40
50
|
|
41
51
|
# get your active orders
|
42
|
-
orders = client.
|
52
|
+
orders = client.get_all_active_spot_orders('EOSETH')
|
43
53
|
|
44
54
|
# create a new order
|
45
|
-
order = client.
|
55
|
+
order = client.create_spot_order(
|
56
|
+
symbol:'EOSETH',
|
57
|
+
side:'buy',
|
58
|
+
quantity:'10',
|
59
|
+
order_type:args.ORDER_TYPE.MARKET
|
60
|
+
)
|
46
61
|
```
|
47
62
|
|
48
|
-
##
|
63
|
+
## Websocket Clients
|
49
64
|
|
50
|
-
|
65
|
+
Ahere are three websocket clients, the `MarketDataClient`, the `TradingClient` and the `WalletClient`. The `MarketDataClient` is public, while the others require authentication to be used.
|
51
66
|
|
52
|
-
callbacks
|
67
|
+
All websocket methods take Procs for their callbacks. These procs take two argument, the first is a possible error in the call (such as missing arguments), and the result data of the method.
|
53
68
|
|
54
|
-
|
55
|
-
|
56
|
-
```ruby
|
57
|
-
require "cryptomarket-sdk"
|
69
|
+
Subscriptions also take in a Proc of two parameters, the notification data, and the notification type. The notification type is of type Args::NotificationType, and is either SNAPSHOT, NOTIFICATION or DATA, corresponding to the strings 'snapshot', 'update' and 'data'
|
58
70
|
|
59
|
-
|
71
|
+
The documentation of a specific subscriptions explains with of this types of notification uses.
|
60
72
|
|
61
|
-
|
73
|
+
### Websocket Market Data Client
|
62
74
|
|
63
|
-
|
75
|
+
There are no unsubscriptions methods for the `MarketDataClient`. To stop recieving messages is recomended to close the `MarketDataClient`.
|
64
76
|
|
65
|
-
|
77
|
+
```ruby
|
78
|
+
# instance a client
|
79
|
+
client = Cryptomarket::Websocket::MarketDataClient.new
|
80
|
+
client.connect
|
81
|
+
# close the client
|
82
|
+
client.close
|
83
|
+
# subscribe to public trades
|
84
|
+
client.subscribe_to_trades(
|
85
|
+
callback:Proc.new {|notification, type|
|
86
|
+
if type == Args::NotificationType::UPDATE
|
87
|
+
puts "an update"
|
88
|
+
end
|
89
|
+
if type == Args::NotificationType::SNAPSHOT
|
90
|
+
puts "a snapshot"
|
91
|
+
end
|
92
|
+
puts notification
|
93
|
+
},
|
94
|
+
symbols:['eoseth', 'ethbtc'],
|
95
|
+
limit:2,
|
96
|
+
result_callback:Proc.new {|err, result|
|
66
97
|
if not err.nil?
|
67
|
-
|
68
|
-
|
98
|
+
puts err
|
99
|
+
else
|
100
|
+
puts result
|
69
101
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
102
|
+
}
|
103
|
+
)
|
104
|
+
|
105
|
+
# subscribe to symbol tickers
|
106
|
+
client.subscribe_to_ticker(
|
107
|
+
speed:"1s",
|
108
|
+
callback:Proc.new {|notificatoin, type|
|
109
|
+
if type == Args::NotificationType::DATA
|
110
|
+
puts "is always data"
|
111
|
+
end
|
112
|
+
puts notification
|
113
|
+
},
|
114
|
+
symbols:['eoseth', 'ethbtc'],
|
115
|
+
result_callback:Proc.new {|err, result|
|
116
|
+
if not err.nil?
|
117
|
+
puts err
|
118
|
+
else
|
119
|
+
puts result
|
120
|
+
end
|
121
|
+
}
|
122
|
+
)
|
123
|
+
```
|
83
124
|
|
84
|
-
|
125
|
+
### Websocket Trading Client
|
85
126
|
|
86
|
-
|
127
|
+
Subscription callback to spot trading balances takes only one argument, a list of balances (see example below)
|
87
128
|
|
88
|
-
|
129
|
+
```ruby
|
130
|
+
# instance a client with a 15 seconds window
|
131
|
+
client = Cryptomarket::Websocket::TradingClient.new(
|
132
|
+
api_key:Keyloader.api_key,
|
133
|
+
api_secret:Keyloader.api_secret,
|
134
|
+
window:15_000
|
135
|
+
)
|
136
|
+
client.connect
|
137
|
+
# close the client
|
138
|
+
client.close
|
139
|
+
|
140
|
+
# subscribe to order reports
|
141
|
+
client.subscribe_to_reports(
|
142
|
+
callback:Proc.new {|notification, type|
|
143
|
+
if type == Args::NotificationType::UPDATE
|
144
|
+
puts "a lonely report in a list"
|
145
|
+
end
|
146
|
+
if type == 'snapshot' # same as Args::NotificationType::SNAPSHOT
|
147
|
+
puts "reports of active orders"
|
148
|
+
end
|
149
|
+
puts notification
|
150
|
+
}
|
151
|
+
)
|
152
|
+
# unsubscribe from order reports
|
153
|
+
client.unsubscribe_to_reports
|
154
|
+
|
155
|
+
@wsclient.subscribe_to_spot_balance(
|
156
|
+
callback: ->(balances) {puts balances},
|
157
|
+
result_callback: ->(_) {},
|
158
|
+
mode: 'updates'
|
159
|
+
)
|
160
|
+
|
161
|
+
client_order_id = Time.now.to_i.to_s
|
162
|
+
|
163
|
+
# create an order
|
164
|
+
client.create_spot_order(
|
165
|
+
symbol: symbol,
|
166
|
+
price:'10000',
|
167
|
+
quantity:'0.01',
|
168
|
+
side:'sell',
|
169
|
+
clientOrderId:client_order_id
|
170
|
+
)
|
171
|
+
|
172
|
+
# candel an order
|
173
|
+
client.cancel_spot_order(client_order_id)
|
89
174
|
|
90
|
-
|
175
|
+
```
|
91
176
|
|
92
|
-
|
93
|
-
wsclient.getTradingBalance(my_callback)
|
177
|
+
### Websocket Wallet Management Client
|
94
178
|
|
95
|
-
|
96
|
-
wsclient.getActinveOrders(my_callback)
|
179
|
+
Subscription callback to transactions takes only one argument, a transaction (see example below)
|
97
180
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
price:"10",
|
105
|
-
callback:my_callback)
|
181
|
+
```ruby
|
182
|
+
# instance a client with a default window of 10 seconds
|
183
|
+
client = Cryptomarket::Websocket::WalletClient.new api_key:Keyloader.api_key, api_secret:Keyloader.api_secret
|
184
|
+
client.connect
|
185
|
+
# close the client
|
186
|
+
defer client.close
|
106
187
|
|
107
|
-
#
|
188
|
+
# subscribe to wallet transactions
|
189
|
+
def callback(transaction):
|
190
|
+
->(transaction) { puts(transaction) }
|
108
191
|
|
109
|
-
|
192
|
+
client.subscribe_to_transactions(callback)
|
110
193
|
|
111
|
-
|
194
|
+
# unsubscribe from wallet transactions
|
195
|
+
client.unsubscribe_to_transactions(lambda { |is_success|
|
196
|
+
puts('successful unsubscription') if is_success
|
197
|
+
})
|
112
198
|
|
113
|
-
|
199
|
+
# get wallet balances
|
200
|
+
client.get_wallet_balances(->(balances){ puts balances})
|
114
201
|
```
|
115
202
|
|
116
|
-
|
117
203
|
## exception handling
|
204
|
+
|
118
205
|
```ruby
|
119
206
|
require "cryptomarket-sdk"
|
120
207
|
|
121
|
-
client = Cryptomarket::Client.new
|
208
|
+
client = Cryptomarket::Client.new api_key:api_key, api_secret:api_secret
|
122
209
|
|
123
|
-
# catch a wrong argument
|
210
|
+
# catch a wrong argument
|
124
211
|
begin
|
125
|
-
order = client.
|
126
|
-
symbol='EOSETH',
|
212
|
+
order = client.create_spot_order(
|
213
|
+
symbol='EOSETH',
|
127
214
|
side='selllll', # wrong
|
128
215
|
quantity='3'
|
129
216
|
)
|
@@ -133,18 +220,18 @@ end
|
|
133
220
|
|
134
221
|
# catch a failed transaction
|
135
222
|
begin
|
136
|
-
order = client.
|
223
|
+
order = client.create_spot_order(
|
137
224
|
symbol='eosehtt', # non existant symbol
|
138
225
|
side='sell',
|
139
|
-
quantity='10',
|
226
|
+
quantity='10',
|
140
227
|
)
|
141
228
|
rescue Cryptomarket::SDKException => e:
|
142
229
|
puts e
|
143
230
|
end
|
144
231
|
|
145
|
-
wsclient = Cryptomarket::Websocket::TradingClient.new
|
232
|
+
wsclient = Cryptomarket::Websocket::TradingClient.new api_key:api_key, api_secret:api_secret
|
146
233
|
|
147
|
-
# websocket errors are passed as the first argument to the callback
|
234
|
+
# websocket errors are passed as the first argument to the callback. valid for all non subscription methods
|
148
235
|
my_callback = Proc.new {|err, data|
|
149
236
|
if not err.nil?
|
150
237
|
puts err # deal with error
|
@@ -153,16 +240,15 @@ my_callback = Proc.new {|err, data|
|
|
153
240
|
puts data
|
154
241
|
}
|
155
242
|
|
156
|
-
wsclient.
|
243
|
+
wsclient.get_spot_trading_balances(my_callback)
|
157
244
|
|
158
245
|
# catch authorization error
|
159
246
|
# to catch an authorization error on client connection, a on_error function must be defined on the client
|
160
|
-
wsclient = TradingClient(
|
247
|
+
wsclient = TradingClient(api_key, api_secret)
|
161
248
|
wsclient.onerror = Proc.new {|error| puts "error", error}
|
162
249
|
wsclient.connect
|
163
|
-
|
164
|
-
|
165
250
|
```
|
251
|
+
|
166
252
|
# Checkout our other SDKs
|
167
253
|
|
168
254
|
[node sdk](https://github.com/cryptomkt/cryptomkt-node)
|