cryptomarket-sdk 1.0.0 → 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 +161 -78
- 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 -71
- data/lib/cryptomarket/utils.rb +0 -57
- data/lib/cryptomarket/websocket/accountClient.rb +0 -110
- 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 -239
- data/lib/cryptomarket/websocket/tradingClient.rb +0 -123
- data/lib/cryptomarket/websocket/wsClientBase.rb +0 -157
- 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,131 +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
|
-
gem install cryptomarket
|
12
|
+
gem install cryptomarket-sdk
|
11
13
|
```
|
12
|
-
# Documentation
|
13
14
|
|
14
|
-
|
15
|
+
# Documentation
|
15
16
|
|
17
|
+
This sdk makes use of the [api version 3](https://api.exchange.cryptomkt.com/) of cryptomarket
|
16
18
|
|
17
19
|
# Quick Start
|
18
20
|
|
19
21
|
## rest client
|
22
|
+
|
20
23
|
```ruby
|
21
|
-
require "cryptomarket"
|
24
|
+
require "cryptomarket-sdk"
|
22
25
|
|
23
26
|
# instance a client
|
24
27
|
api_key='AB32B3201'
|
25
28
|
api_secret='21b12401'
|
26
|
-
client = Cryptomarket::Client.new
|
29
|
+
client = Cryptomarket::Client.new api_key:api_key, api_secret:api_secret
|
27
30
|
|
28
31
|
# get currencies
|
29
|
-
currencies = client.
|
32
|
+
currencies = client.get_currencies
|
30
33
|
|
31
34
|
# get order books
|
32
|
-
order_book = client.
|
35
|
+
order_book = client.get_orderbooks symbols:['EOSETH']
|
33
36
|
|
34
37
|
# get your account balances
|
35
|
-
account_balance = client.
|
38
|
+
account_balance = client.get_wallet_balances
|
36
39
|
|
37
40
|
# get your trading balances
|
38
|
-
trading_balance = client.
|
41
|
+
trading_balance = client.get_spot_trading_balances
|
39
42
|
|
40
43
|
# move balance from account bank to account trading
|
41
|
-
result = client.
|
44
|
+
result = @client.transfer_between_wallet_and_exchange(
|
45
|
+
currency: "CRO",
|
46
|
+
amount: "0.1",
|
47
|
+
source:"wallet",
|
48
|
+
destination:"spot",
|
49
|
+
)
|
42
50
|
|
43
51
|
# get your active orders
|
44
|
-
orders = client.
|
52
|
+
orders = client.get_all_active_spot_orders('EOSETH')
|
45
53
|
|
46
54
|
# create a new order
|
47
|
-
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
|
+
)
|
48
61
|
```
|
49
62
|
|
50
|
-
##
|
63
|
+
## Websocket Clients
|
51
64
|
|
52
|
-
|
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.
|
53
66
|
|
54
|
-
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.
|
55
68
|
|
56
|
-
|
57
|
-
|
58
|
-
```ruby
|
59
|
-
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'
|
60
70
|
|
61
|
-
|
71
|
+
The documentation of a specific subscriptions explains with of this types of notification uses.
|
62
72
|
|
63
|
-
|
73
|
+
### Websocket Market Data Client
|
64
74
|
|
65
|
-
|
75
|
+
There are no unsubscriptions methods for the `MarketDataClient`. To stop recieving messages is recomended to close the `MarketDataClient`.
|
66
76
|
|
67
|
-
|
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|
|
68
97
|
if not err.nil?
|
69
|
-
|
70
|
-
|
98
|
+
puts err
|
99
|
+
else
|
100
|
+
puts result
|
71
101
|
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
+
```
|
85
124
|
|
86
|
-
|
125
|
+
### Websocket Trading Client
|
87
126
|
|
88
|
-
|
127
|
+
Subscription callback to spot trading balances takes only one argument, a list of balances (see example below)
|
89
128
|
|
90
|
-
|
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)
|
91
174
|
|
92
|
-
|
175
|
+
```
|
93
176
|
|
94
|
-
|
95
|
-
wsclient.getTradingBalance(my_callback)
|
177
|
+
### Websocket Wallet Management Client
|
96
178
|
|
97
|
-
|
98
|
-
wsclient.getActinveOrders(my_callback)
|
179
|
+
Subscription callback to transactions takes only one argument, a transaction (see example below)
|
99
180
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
price:"10",
|
107
|
-
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
|
108
187
|
|
109
|
-
#
|
188
|
+
# subscribe to wallet transactions
|
189
|
+
def callback(transaction):
|
190
|
+
->(transaction) { puts(transaction) }
|
110
191
|
|
111
|
-
|
192
|
+
client.subscribe_to_transactions(callback)
|
112
193
|
|
113
|
-
|
194
|
+
# unsubscribe from wallet transactions
|
195
|
+
client.unsubscribe_to_transactions(lambda { |is_success|
|
196
|
+
puts('successful unsubscription') if is_success
|
197
|
+
})
|
114
198
|
|
115
|
-
|
199
|
+
# get wallet balances
|
200
|
+
client.get_wallet_balances(->(balances){ puts balances})
|
116
201
|
```
|
117
202
|
|
118
|
-
|
119
203
|
## exception handling
|
204
|
+
|
120
205
|
```ruby
|
121
206
|
require "cryptomarket-sdk"
|
122
207
|
|
123
|
-
client = Cryptomarket::Client.new
|
208
|
+
client = Cryptomarket::Client.new api_key:api_key, api_secret:api_secret
|
124
209
|
|
125
|
-
# catch a wrong argument
|
210
|
+
# catch a wrong argument
|
126
211
|
begin
|
127
|
-
order = client.
|
128
|
-
symbol='EOSETH',
|
212
|
+
order = client.create_spot_order(
|
213
|
+
symbol='EOSETH',
|
129
214
|
side='selllll', # wrong
|
130
215
|
quantity='3'
|
131
216
|
)
|
@@ -135,18 +220,18 @@ end
|
|
135
220
|
|
136
221
|
# catch a failed transaction
|
137
222
|
begin
|
138
|
-
order = client.
|
223
|
+
order = client.create_spot_order(
|
139
224
|
symbol='eosehtt', # non existant symbol
|
140
225
|
side='sell',
|
141
|
-
quantity='10',
|
226
|
+
quantity='10',
|
142
227
|
)
|
143
228
|
rescue Cryptomarket::SDKException => e:
|
144
229
|
puts e
|
145
230
|
end
|
146
231
|
|
147
|
-
wsclient = Cryptomarket::Websocket::TradingClient.new
|
232
|
+
wsclient = Cryptomarket::Websocket::TradingClient.new api_key:api_key, api_secret:api_secret
|
148
233
|
|
149
|
-
# 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
|
150
235
|
my_callback = Proc.new {|err, data|
|
151
236
|
if not err.nil?
|
152
237
|
puts err # deal with error
|
@@ -155,23 +240,21 @@ my_callback = Proc.new {|err, data|
|
|
155
240
|
puts data
|
156
241
|
}
|
157
242
|
|
158
|
-
wsclient.
|
243
|
+
wsclient.get_spot_trading_balances(my_callback)
|
159
244
|
|
160
245
|
# catch authorization error
|
161
246
|
# to catch an authorization error on client connection, a on_error function must be defined on the client
|
162
|
-
wsclient = TradingClient(
|
247
|
+
wsclient = TradingClient(api_key, api_secret)
|
163
248
|
wsclient.onerror = Proc.new {|error| puts "error", error}
|
164
249
|
wsclient.connect
|
165
|
-
|
166
|
-
|
167
250
|
```
|
251
|
+
|
168
252
|
# Checkout our other SDKs
|
169
|
-
<!-- agregar links -->
|
170
253
|
|
171
|
-
|
254
|
+
[node sdk](https://github.com/cryptomkt/cryptomkt-node)
|
172
255
|
|
173
|
-
|
256
|
+
[java sdk](https://github.com/cryptomkt/cryptomkt-java)
|
174
257
|
|
175
|
-
|
258
|
+
[go sdk](https://github.com/cryptomkt/cryptomkt-go)
|
176
259
|
|
177
|
-
|
260
|
+
[python sdk](https://github.com/cryptomkt/cryptomkt-python)
|