cryptomarket-sdk 1.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 +7 -0
- data/LICENSE.md +201 -0
- data/README.md +177 -0
- data/lib/cryptomarket/HttpManager.rb +71 -0
- data/lib/cryptomarket/client.rb +732 -0
- data/lib/cryptomarket/exceptions.rb +24 -0
- data/lib/cryptomarket/utils.rb +57 -0
- data/lib/cryptomarket/websocket/accountClient.rb +110 -0
- data/lib/cryptomarket/websocket/authClient.rb +53 -0
- data/lib/cryptomarket/websocket/callbackCache.rb +51 -0
- data/lib/cryptomarket/websocket/methods.rb +56 -0
- data/lib/cryptomarket/websocket/orderbookCache.rb +123 -0
- data/lib/cryptomarket/websocket/publicClient.rb +239 -0
- data/lib/cryptomarket/websocket/tradingClient.rb +123 -0
- data/lib/cryptomarket/websocket/wsClientBase.rb +157 -0
- data/lib/cryptomarket/websocket/wsManager.rb +59 -0
- metadata +91 -0
@@ -0,0 +1,732 @@
|
|
1
|
+
require_relative "HttpManager"
|
2
|
+
require_relative "utils"
|
3
|
+
|
4
|
+
module Cryptomarket
|
5
|
+
class Client
|
6
|
+
include Utils
|
7
|
+
|
8
|
+
def initialize(apiKey:nil, apiSecret:nil)
|
9
|
+
@httpManager = HttpManager.new apiKey:apiKey, apiSecret:apiSecret
|
10
|
+
end
|
11
|
+
|
12
|
+
def publicGet(endpoint, params=nil)
|
13
|
+
return @httpManager.makeRequest(method:'get', endpoint:endpoint, params:params, public: true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(endpoint, params=nil)
|
17
|
+
return @httpManager.makeRequest(method:'get', endpoint:endpoint, params:params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(endpoint, params=nil)
|
21
|
+
return @httpManager.makeRequest(method:'post', endpoint:endpoint, params:params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def put(endpoint, params=nil)
|
25
|
+
return @httpManager.makeRequest(method:'put', endpoint:endpoint, params:params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete(endpoint, params=nil)
|
29
|
+
return @httpManager.makeRequest(method:'delete', endpoint:endpoint, params:params)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
################
|
34
|
+
# public calls #
|
35
|
+
################
|
36
|
+
|
37
|
+
# Get a list of all currencies or specified currencies
|
38
|
+
#
|
39
|
+
# https://api.exchange.cryptomkt.com/#currencies
|
40
|
+
#
|
41
|
+
# Params:
|
42
|
+
# +Array[String]+ +currencies+:: Optional. A list of currencies ids
|
43
|
+
|
44
|
+
def getCurrencies(currencies=nil)
|
45
|
+
params = Hash.new
|
46
|
+
if not currencies.nil?
|
47
|
+
params['currencies'] = currencies
|
48
|
+
end
|
49
|
+
return publicGet('public/currency/', params)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get the data of a currency
|
53
|
+
#
|
54
|
+
# https://api.exchange.cryptomkt.com/#currencies
|
55
|
+
#
|
56
|
+
# Params:
|
57
|
+
# +String+ +currency+:: A currency id
|
58
|
+
|
59
|
+
def getCurrency(currency)
|
60
|
+
return publicGet("public/currency/#{currency}")
|
61
|
+
end
|
62
|
+
|
63
|
+
# Get a list of all symbols or for specified symbols
|
64
|
+
#
|
65
|
+
# A symbol is the combination of the base currency (first one) and quote currency (second one)
|
66
|
+
#
|
67
|
+
# https://api.exchange.cryptomkt.com/#symbols
|
68
|
+
#
|
69
|
+
# Params:
|
70
|
+
# +Array[String]+ +symbols+:: Optional. A list of symbol ids
|
71
|
+
|
72
|
+
def getSymbols (symbols=nil)
|
73
|
+
params = Hash.new
|
74
|
+
if not symbols.nil?
|
75
|
+
params['symbols'] = symbols
|
76
|
+
end
|
77
|
+
return publicGet('public/symbol/', params)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Get a symbol by its id
|
81
|
+
#
|
82
|
+
# A symbol is the combination of the base currency (first one) and quote currency (second one)
|
83
|
+
#
|
84
|
+
# https://api.exchange.cryptomkt.com/#symbols
|
85
|
+
#
|
86
|
+
# Params:
|
87
|
+
# +String+ +symbol+:: A symbol id
|
88
|
+
|
89
|
+
def getSymbol(symbol)
|
90
|
+
return publicGet("public/symbol/#{symbol}")
|
91
|
+
end
|
92
|
+
|
93
|
+
# Get tickers for all symbols or for specified symbols
|
94
|
+
#
|
95
|
+
# https://api.exchange.cryptomkt.com/#tickers
|
96
|
+
#
|
97
|
+
# Params:
|
98
|
+
# +Array[String]+ +symbols+:: Optional. A list of symbol ids
|
99
|
+
|
100
|
+
def getTickers(symbols=nil)
|
101
|
+
params = Hash.new
|
102
|
+
if not symbols.nil?
|
103
|
+
params['symbols'] = symbols
|
104
|
+
end
|
105
|
+
return publicGet('public/ticker/', params)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Get the ticker of a symbol
|
109
|
+
#
|
110
|
+
# https://api.exchange.cryptomkt.com/#tickers
|
111
|
+
#
|
112
|
+
# Params:
|
113
|
+
# +String+ +symbol+:: A symbol id
|
114
|
+
|
115
|
+
def getTicker(symbol)
|
116
|
+
return publicGet("public/ticker/#{symbol}")
|
117
|
+
end
|
118
|
+
|
119
|
+
# Get trades for all symbols or for specified symbols
|
120
|
+
#
|
121
|
+
# 'from' param and 'till' param must have the same format, both index of both timestamp
|
122
|
+
#
|
123
|
+
# https://api.exchange.cryptomkt.com/#trades
|
124
|
+
#
|
125
|
+
# Params:
|
126
|
+
# +Array[String]+ +symbols+:: Optional. A list of symbol ids
|
127
|
+
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
|
128
|
+
# +String+ +from+:: Optional. Initial value of the queried interval
|
129
|
+
# +String+ +till+:: Optional. Last value of the queried interval
|
130
|
+
# +Integer+ +limit+:: Optional. Trades per query. Defaul is 100. Max is 1000
|
131
|
+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
|
132
|
+
|
133
|
+
def getTrades(symbols:nil, sort:nil, from:nil, till:nil, limit:nil, offset:nil)
|
134
|
+
params = Hash.new
|
135
|
+
if not symbols.nil?
|
136
|
+
params['symbols'] = symbols
|
137
|
+
end
|
138
|
+
extend_hash_with_pagination! params, sort:sort, from:from, till:till, limit:limit, offset:offset
|
139
|
+
return publicGet('public/trades/', params)
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
# Get trades of a symbol
|
145
|
+
#
|
146
|
+
# 'from' param and 'till' param must have the same format, both index of both timestamp
|
147
|
+
#
|
148
|
+
# https://api.exchange.cryptomkt.com/#trades
|
149
|
+
#
|
150
|
+
# Params:
|
151
|
+
# +String+ +symbol+:: A symbol id
|
152
|
+
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
|
153
|
+
# +String+ +from+:: Optional. Initial value of the queried interval
|
154
|
+
# +String+ +till+:: Optional. Last value of the queried interval
|
155
|
+
# +Integer+ +limit+:: Optional. Trades per query. Defaul is 100. Max is 1000
|
156
|
+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
|
157
|
+
|
158
|
+
def getTradesOfSymbol(symbol=nil, sort:nil, from:nil, till:nil, limit:nil, offset:nil)
|
159
|
+
params = Hash.new
|
160
|
+
params['symbol'] = symbol
|
161
|
+
extend_hash_with_pagination! params, sort:sort, from:from, till:till, limit:limit, offset:offset
|
162
|
+
return publicGet('public/trades/', params)
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
# Get orderbooks for all symbols or for the specified symbols
|
168
|
+
#
|
169
|
+
# An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level
|
170
|
+
#
|
171
|
+
# https://api.exchange.cryptomkt.com/#order-book
|
172
|
+
#
|
173
|
+
# Params:
|
174
|
+
# +Array[String]+ +symbols+:: Optional. A list of symbol ids
|
175
|
+
# +Integer+ +limit+:: Optional. Limit of order book levels. Set to 0 to view full list of order book levels
|
176
|
+
|
177
|
+
def getOrderbooks(symbols:nil, limit:nil)
|
178
|
+
params = Hash.new
|
179
|
+
if not symbols.nil?
|
180
|
+
params['symbols'] = symbols
|
181
|
+
end
|
182
|
+
if not limit.nil?
|
183
|
+
params['limit'] = limit
|
184
|
+
end
|
185
|
+
return publicGet('public/orderbook/', params)
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
# Get order book of a symbol
|
191
|
+
#
|
192
|
+
# An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level
|
193
|
+
#
|
194
|
+
# https://api.exchange.cryptomkt.com/#order-book
|
195
|
+
#
|
196
|
+
# Params:
|
197
|
+
# +String+ +symbol+:: The symbol id
|
198
|
+
# +Integer+ +limit+:: Optional. Limit of order book levels. Set to 0 to view full list of order book levels
|
199
|
+
|
200
|
+
def getOrderbook(symbol, limit:nil)
|
201
|
+
params = Hash.new
|
202
|
+
if not limit.nil?
|
203
|
+
params['limit'] = limit
|
204
|
+
end
|
205
|
+
return publicGet("public/orderbook/#{symbol}", params)
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
# Get order book of a symbol with market depth info
|
211
|
+
#
|
212
|
+
# An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level
|
213
|
+
#
|
214
|
+
# https://api.exchange.cryptomkt.com/#order-book
|
215
|
+
#
|
216
|
+
# Params:
|
217
|
+
# +String+ +symbol+:: The symbol id
|
218
|
+
# +Integer+ +volume+:: Desired volume for market depth search
|
219
|
+
|
220
|
+
def getMarketDepth(symbol, volume:nil)
|
221
|
+
params = Hash.new
|
222
|
+
if not limit.nil?
|
223
|
+
params['volume'] = volume
|
224
|
+
end
|
225
|
+
return publicGet("public/orderbook/#{symbol}", params)
|
226
|
+
end
|
227
|
+
|
228
|
+
# Get candles for all symbols or for specified symbols
|
229
|
+
#
|
230
|
+
# Candels are used for OHLC representation
|
231
|
+
#
|
232
|
+
# https://api.exchange.cryptomkt.com/#candles
|
233
|
+
#
|
234
|
+
# Params:
|
235
|
+
# +Array[String]+ +symbols+:: Optional. A list of symbol ids
|
236
|
+
# +String+ +period+:: Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
|
237
|
+
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
|
238
|
+
# +String+ +from+:: Optional. Initial value of the queried interval
|
239
|
+
# +String+ +till+:: Optional. Last value of the queried interval
|
240
|
+
# +Integer+ +limit+:: Optional. Candles per query. Defaul is 100. Max is 1000
|
241
|
+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
|
242
|
+
|
243
|
+
def getCandles(symbols:nil, period:nil, sort:nil, from:nil, till:nil, limit:nil, offset:nil)
|
244
|
+
params = Hash.new
|
245
|
+
if not symbols.nil?
|
246
|
+
params['symbols'] = symbols
|
247
|
+
end
|
248
|
+
if not period.nil?
|
249
|
+
params['period'] = period
|
250
|
+
end
|
251
|
+
extend_hash_with_pagination! params, sort:sort, from:from, till:till, limit:limit, offset:offset
|
252
|
+
return publicGet('public/candles/', params)
|
253
|
+
end
|
254
|
+
|
255
|
+
# Get candle for all symbols or for specified symbols
|
256
|
+
#
|
257
|
+
# Candels are used for OHLC representation
|
258
|
+
#
|
259
|
+
# https://api.exchange.cryptomkt.com/#candles
|
260
|
+
#
|
261
|
+
# Params:
|
262
|
+
# +String+ +symbol+:: A symbol id
|
263
|
+
# +String+ +period+:: Optional. A valid tick interval. 'M1' (one minute), 'M3', 'M5', 'M15', 'M30', 'H1' (one hour), 'H4', 'D1' (one day), 'D7', '1M' (one month). Default is 'M30'
|
264
|
+
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
|
265
|
+
# +String+ +from+:: Optional. Initial value of the queried interval
|
266
|
+
# +String+ +till+:: Optional. Last value of the queried interval
|
267
|
+
# +Integer+ +limit+:: Optional. Candles per query. Defaul is 100. Max is 1000
|
268
|
+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
|
269
|
+
|
270
|
+
def getCandlesOfSymbol(symbol:, period:nil, sort:nil, from:nil, till:nil, limit:nil, offset:nil)
|
271
|
+
params = Hash.new
|
272
|
+
if not period.nil?
|
273
|
+
params['period'] = period
|
274
|
+
end
|
275
|
+
extend_hash_with_pagination! params, sort:sort, from:from, till:till, limit:limit, offset:offset
|
276
|
+
return publicGet("public/candles/#{symbol}", params)
|
277
|
+
end
|
278
|
+
|
279
|
+
#################
|
280
|
+
# Trading calls #
|
281
|
+
#################
|
282
|
+
|
283
|
+
# Get the account trading balance
|
284
|
+
#
|
285
|
+
# Requires authentication
|
286
|
+
#
|
287
|
+
# https://api.exchange.cryptomkt.com/#trading-balance
|
288
|
+
|
289
|
+
def getTradingBalance
|
290
|
+
return get('trading/balance')
|
291
|
+
end
|
292
|
+
|
293
|
+
# Get the account active orders
|
294
|
+
#
|
295
|
+
# Requires authentication
|
296
|
+
#
|
297
|
+
# https://api.exchange.cryptomkt.com/#get-active-orders
|
298
|
+
#
|
299
|
+
# Params:
|
300
|
+
# +String+ +symbol+:: Optional. A symbol for filtering active orders
|
301
|
+
|
302
|
+
def getActiveOrders(symbol=nil)
|
303
|
+
params = Hash.new
|
304
|
+
if not symbol.nil?
|
305
|
+
params['symbol'] = symbol
|
306
|
+
end
|
307
|
+
return get('order', params)
|
308
|
+
end
|
309
|
+
|
310
|
+
# Get an active order by its client order id
|
311
|
+
#
|
312
|
+
# Requires authentication
|
313
|
+
#
|
314
|
+
# https://api.exchange.cryptomkt.com/#get-active-orders
|
315
|
+
#
|
316
|
+
# Params:
|
317
|
+
# +String+ +clientOrderId+:: The clientOrderId of the order
|
318
|
+
# +Integer+ +wait+:: Optional. Time in milliseconds Max value is 60000. Default value is None. While using long polling request: if order is filled, cancelled or expired order info will be returned instantly. For other order statuses, actual order info will be returned after specified wait time.
|
319
|
+
|
320
|
+
def getActiveOrder(clientOrderId, wait=nil)
|
321
|
+
params = Hash.new
|
322
|
+
if not wait.nil?
|
323
|
+
params["wait"] = wait
|
324
|
+
end
|
325
|
+
return get("order/#{clientOrderId}", params)
|
326
|
+
end
|
327
|
+
|
328
|
+
# Creates a new order
|
329
|
+
#
|
330
|
+
# Requires authentication
|
331
|
+
#
|
332
|
+
# https://api.exchange.cryptomkt.com/#create-new-order
|
333
|
+
#
|
334
|
+
# Params:
|
335
|
+
# +String+ +symbol+::Trading symbol
|
336
|
+
# +String+ +side+::'buy' or 'sell'
|
337
|
+
# +String+ +quantity+::Order quantity
|
338
|
+
# +String+ +clientOrderId+:: Optional. If given must be unique within the trading day, including all active orders. If not given, is generated by the server
|
339
|
+
# +String+ +type+:: Optional. 'limit', 'market', 'stopLimit' or 'stopMarket'. Default is 'limit'
|
340
|
+
# +String+ +timeInForce+:: Optional. 'GTC', 'IOC', 'FOK', 'Day', 'GTD'. Default to 'GTC'
|
341
|
+
# +String+ +price+:: Required for 'limit' and 'stopLimit'. limit price of the order
|
342
|
+
# +String+ +stopPrice+:: Required for 'stopLimit' and 'stopMarket' orders. stop price of the order
|
343
|
+
# +String+ +expireTime+:: Required for orders with timeInForce = GDT
|
344
|
+
# +bool+ +strictValidate+:: Optional. If False, the server rounds half down for tickerSize and quantityIncrement. Example of ETHBTC: tickSize = '0.000001', then price '0.046016' is valid, '0.0460165' is invalid
|
345
|
+
# +bool+ +postOnly+:: Optional. If True, your post_only order causes a match with a pre-existing order as a taker, then the order will be cancelled
|
346
|
+
|
347
|
+
def createOrder(symbol:, side:, quantity:, clientOrderId:nil, type:nil, timeInForce:nil, price:nil, stopPrice:nil, expireTime:nil, strictValidate:nil, postOnly:nil)
|
348
|
+
params = {'symbol': symbol, 'side': side, 'quantity': quantity}
|
349
|
+
extend_hash_with_order_params! params, type:type, timeInForce:timeInForce, price:price, stopPrice:stopPrice, expireTime:expireTime, strictValidate:strictValidate, postOnly:postOnly
|
350
|
+
if not clientOrderId.nil?
|
351
|
+
return put("order/#{clientOrderId}", params)
|
352
|
+
end
|
353
|
+
return post("order", params)
|
354
|
+
end
|
355
|
+
|
356
|
+
# Cancel all active orders, or all active orders for a specified symbol
|
357
|
+
#
|
358
|
+
# Requires authentication
|
359
|
+
#
|
360
|
+
# https://api.exchange.cryptomkt.com/#cancel-orders
|
361
|
+
#
|
362
|
+
# +string+ +symbol+:: Optional. If given, cancels all orders of the symbol. If not given, cancels all orders of all symbols
|
363
|
+
|
364
|
+
def cancelAllOrders(symbol=nil)
|
365
|
+
params = Hash.new
|
366
|
+
if not symbol.nil?
|
367
|
+
params['symbol'] = symbol
|
368
|
+
end
|
369
|
+
return delete("order", params)
|
370
|
+
end
|
371
|
+
|
372
|
+
# Cancel the order with clientOrderId
|
373
|
+
#
|
374
|
+
# Requires authentication
|
375
|
+
#
|
376
|
+
# https://api.exchange.cryptomkt.com/#cancel-order-by-clientorderid
|
377
|
+
#
|
378
|
+
# Params:
|
379
|
+
# +String+ +clientOrderId+:: the client id of the order to cancel
|
380
|
+
|
381
|
+
def cancelOrder(clientOrderId)
|
382
|
+
delete("order/#{clientOrderId}")
|
383
|
+
end
|
384
|
+
|
385
|
+
# Get personal trading commission rates for a symbol
|
386
|
+
#
|
387
|
+
# Requires authentication
|
388
|
+
#
|
389
|
+
# https://api.exchange.cryptomkt.com/#get-trading-commission
|
390
|
+
#
|
391
|
+
# +string+ +symbol+:: The symbol of the comission rates
|
392
|
+
|
393
|
+
def tradingFee(symbol)
|
394
|
+
return get("trading/fee/#{symbol}")
|
395
|
+
end
|
396
|
+
|
397
|
+
####################
|
398
|
+
# trading history #
|
399
|
+
####################
|
400
|
+
|
401
|
+
# Get the account order history
|
402
|
+
#
|
403
|
+
# All not active orders older than 24 are deleted
|
404
|
+
#
|
405
|
+
# Requires authentication
|
406
|
+
#
|
407
|
+
# https://api.exchange.cryptomkt.com/#orders-history
|
408
|
+
#
|
409
|
+
# Params:
|
410
|
+
# +String+ +symbol+:: Optional. Filter orders by symbol
|
411
|
+
# +String+ +from+:: Optional. Initial value of the queried interval
|
412
|
+
# +String+ +till+:: Optional. Last value of the queried interval
|
413
|
+
# +Integer+ +limit+:: Optional. Trades per query. Defaul is 100. Max is 1000
|
414
|
+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
|
415
|
+
|
416
|
+
def getOrderHistory(symbol:nil, from:nil, till:nil, limit:nil, offset:nil)
|
417
|
+
params = Hash.new
|
418
|
+
if not symbol.nil?
|
419
|
+
params['symbol'] = symbol
|
420
|
+
end
|
421
|
+
extend_hash_with_pagination! params, from:from, till:till, limit:limit, offset:offset
|
422
|
+
return get('history/order', params)
|
423
|
+
end
|
424
|
+
|
425
|
+
# Get orders with the clientOrderId
|
426
|
+
#
|
427
|
+
# All not active orders older than 24 are deleted
|
428
|
+
#
|
429
|
+
# Requires authentication
|
430
|
+
#
|
431
|
+
# https://api.exchange.cryptomkt.com/#orders-history
|
432
|
+
#
|
433
|
+
# Params:
|
434
|
+
# +String+ +clientOrderId+:: the clientOrderId of the orders
|
435
|
+
|
436
|
+
def getOrders(clientOrderId)
|
437
|
+
params = {clientOrderId:clientOrderId}
|
438
|
+
return get("history/order", params)
|
439
|
+
end
|
440
|
+
|
441
|
+
# Get the user's trading history
|
442
|
+
#
|
443
|
+
# Requires authentication
|
444
|
+
#
|
445
|
+
# https://api.exchange.cryptomkt.com/#orders-history
|
446
|
+
#
|
447
|
+
# Params:
|
448
|
+
# +String+ +symbol:: Optional. Filter trades by symbol
|
449
|
+
# +String+ +sort:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
|
450
|
+
# +String+ +by:: Optional. Defines the sorting type.'timestamp' or 'id'. Default is 'timestamp'
|
451
|
+
# +String+ +from:: Optional. Initial value of the queried interval. Id or datetime
|
452
|
+
# +String+ +till:: Optional. Last value of the queried interval. Id or datetime
|
453
|
+
# +Integer+ +limit:: Optional. Trades per query. Defaul is 100. Max is 1000
|
454
|
+
# +Integer+ +offset:: Optional. Default is 0. Max is 100000
|
455
|
+
# +String+ +margin:: Optional. Filtering of margin orders. 'include', 'only' or 'ignore'. Default is 'include'
|
456
|
+
|
457
|
+
def getTradeHistory(symbol:nil, sort:nil, by:nil, from:nil, till:nil, limit:nil, offset:nil, margin:nil)
|
458
|
+
params = Hash.new
|
459
|
+
if not symbol.nil?
|
460
|
+
params['symbol'] = symbol
|
461
|
+
end
|
462
|
+
if not margin.nil?
|
463
|
+
params['margin'] = margin
|
464
|
+
end
|
465
|
+
extend_hash_with_pagination! params, sort:sort, by:by, from:from, till:till, limit:limit, offset:offset
|
466
|
+
return get('history/trades')
|
467
|
+
end
|
468
|
+
|
469
|
+
# Get the account's trading order with a specified order id
|
470
|
+
#
|
471
|
+
# Requires authentication
|
472
|
+
#
|
473
|
+
# https://api.exchange.cryptomkt.com/#trades-by-order
|
474
|
+
#
|
475
|
+
# Params:
|
476
|
+
# +String+ +id+:: Order unique identifier assigned by exchange
|
477
|
+
#
|
478
|
+
|
479
|
+
def getTradesByOrderId(id)
|
480
|
+
return get("history/order/#{id}/trades")
|
481
|
+
end
|
482
|
+
|
483
|
+
######################
|
484
|
+
# Account Management #
|
485
|
+
######################
|
486
|
+
|
487
|
+
# Get the user account balance
|
488
|
+
#
|
489
|
+
# Requires authentication
|
490
|
+
#
|
491
|
+
# https://api.exchange.cryptomkt.com/#account-balance
|
492
|
+
|
493
|
+
def getAccountBalance
|
494
|
+
return get("account/balance")
|
495
|
+
end
|
496
|
+
|
497
|
+
# Get the current address of a currency
|
498
|
+
#
|
499
|
+
# Requires authentication
|
500
|
+
#
|
501
|
+
# https://api.exchange.cryptomkt.com/#deposit-crypto-address
|
502
|
+
#
|
503
|
+
# Params:
|
504
|
+
# +String+ +currency+:: currency to get the address
|
505
|
+
|
506
|
+
def getDepositCryptoAddress(currency)
|
507
|
+
return get("account/crypto/address/#{currency}")
|
508
|
+
end
|
509
|
+
|
510
|
+
# Creates a new address for the currency
|
511
|
+
#
|
512
|
+
# Requires authentication
|
513
|
+
#
|
514
|
+
# https://api.exchange.cryptomkt.com/#deposit-crypto-address
|
515
|
+
#
|
516
|
+
# Params:
|
517
|
+
# +String+ +currency+:: currency to create a new address
|
518
|
+
|
519
|
+
def createDepositCryptoAddress(currency)
|
520
|
+
return post("account/crypto/address/#{currency}")
|
521
|
+
end
|
522
|
+
|
523
|
+
# Get the last 10 addresses used for deposit by currency
|
524
|
+
#
|
525
|
+
# Requires authentication
|
526
|
+
#
|
527
|
+
# https://api.exchange.cryptomkt.com/#last-10-deposit-crypto-address
|
528
|
+
#
|
529
|
+
# Params:
|
530
|
+
# +String+ +currency+:: currency to get the list of addresses
|
531
|
+
|
532
|
+
def getLast10DepositCryptoAddresses(currency)
|
533
|
+
return get("account/crypto/addresses/#{currency}")
|
534
|
+
end
|
535
|
+
|
536
|
+
# Get the last 10 unique addresses used for withdraw by currency
|
537
|
+
#
|
538
|
+
# Requires authentication
|
539
|
+
#
|
540
|
+
# https://api.exchange.cryptomkt.com/#last-10-used-crypto-address
|
541
|
+
#
|
542
|
+
# Params:
|
543
|
+
# +String+ +currency+:: currency to get the list of addresses
|
544
|
+
|
545
|
+
def getLast10UsedCryptoAddresses(currency)
|
546
|
+
return get("account/crypto/used-addresses/#{currency}")
|
547
|
+
end
|
548
|
+
|
549
|
+
# Withdraw cryptocurrency
|
550
|
+
#
|
551
|
+
# Requires authentication
|
552
|
+
#
|
553
|
+
# https://api.exchange.cryptomkt.com/#withdraw-crypto
|
554
|
+
#
|
555
|
+
# Params:
|
556
|
+
# +String+ +currency+:: currency code of the crypto to withdraw
|
557
|
+
# +Integer+ +amount+:: the amount to be sent to the specified address
|
558
|
+
# +String+ +address+:: the address identifier
|
559
|
+
# +String+ +paymentId+:: Optional.
|
560
|
+
# +bool+ +includeFee+:: Optional. If true then the total spent amount includes fees. Default false
|
561
|
+
# +bool+ +autoCommit+:: Optional. If false then you should commit or rollback transaction in an hour. Used in two phase commit schema. Default true
|
562
|
+
|
563
|
+
def withdrawCrypto(currency:, amount:, address:, paymentId:nil, includeFee:nil, autoCommit:nil)
|
564
|
+
# FORBIDDEN ERROR
|
565
|
+
params = {currency:currency, amount:amount, address:address}
|
566
|
+
if not paymentId.nil?
|
567
|
+
params['paymentId'] = paymentId
|
568
|
+
end
|
569
|
+
if not includeFee.nil?
|
570
|
+
params['includeFee'] = includeFee
|
571
|
+
end
|
572
|
+
if not autoCommit.nil?
|
573
|
+
params['autoCommit'] = autoCommit
|
574
|
+
end
|
575
|
+
return post("account/crypto/withdraw", params)
|
576
|
+
end
|
577
|
+
|
578
|
+
# Converts between currencies
|
579
|
+
#
|
580
|
+
# Requires authentication
|
581
|
+
#
|
582
|
+
# https://api.exchange.cryptomkt.com/#transfer-convert-between-currencies
|
583
|
+
#
|
584
|
+
# Params:
|
585
|
+
# +String+ +fromCurrency+:: currency code of origin
|
586
|
+
# +String+ +toCurrency+:: currency code of destiny
|
587
|
+
# +Integer+ +amount+:: the amount to be sent
|
588
|
+
|
589
|
+
def transferConvert(fromCurrency, toCurrency, amount)
|
590
|
+
#FORBIDDEN ERROR
|
591
|
+
params = {fromCurrency:fromCurrency, toCurrency:toCurrency, amount:amount}
|
592
|
+
return post('account/crypto/transfer-convert', params)
|
593
|
+
end
|
594
|
+
|
595
|
+
# Commit a withdrawal of cryptocurrency
|
596
|
+
#
|
597
|
+
# Requires authentication
|
598
|
+
#
|
599
|
+
# https://api.exchange.cryptomkt.com/#withdraw-crypto-commit-or-rollback
|
600
|
+
#
|
601
|
+
# Params:
|
602
|
+
# +String+ +id+:: the withdrawal transaction identifier
|
603
|
+
|
604
|
+
def commitWithdrawCrypto(id)
|
605
|
+
# cannot be tested <= withdraw crypto is forbidden
|
606
|
+
return put("account/crypto/withdraw/#{id}")
|
607
|
+
end
|
608
|
+
|
609
|
+
# Rollback a withdrawal of cryptocurrency
|
610
|
+
#
|
611
|
+
# Requires authentication
|
612
|
+
#
|
613
|
+
# https://api.exchange.cryptomkt.com/#withdraw-crypto-commit-or-rollback
|
614
|
+
#
|
615
|
+
# Params:
|
616
|
+
# +String+ +id+:: the withdrawal transaction identifier
|
617
|
+
|
618
|
+
def rollbackWithdrawCrypto(id)
|
619
|
+
# cannot be tested <= withdraw crypto is forbidden
|
620
|
+
return delete("account/crypto/withdraw/#{id}")
|
621
|
+
end
|
622
|
+
|
623
|
+
# Get an estimate of the withdrawal fee
|
624
|
+
#
|
625
|
+
# Requires authetication
|
626
|
+
#
|
627
|
+
# https://api.exchange.cryptomkt.com/#estimate-withdraw-fee
|
628
|
+
#
|
629
|
+
# Params:
|
630
|
+
# +String+ +currency+:: the currency code for withdraw
|
631
|
+
# +Integer+ +amount+:: the expected withdraw amount
|
632
|
+
|
633
|
+
def getEstimatesWithdrawFee(currency, amount)
|
634
|
+
params = {currency:currency, amount:amount}
|
635
|
+
return get('account/crypto/estimate-withdraw', params)
|
636
|
+
end
|
637
|
+
|
638
|
+
# Check if an address is from this account
|
639
|
+
#
|
640
|
+
# Requires authentication
|
641
|
+
#
|
642
|
+
# https://api.exchange.cryptomkt.com/#check-if-crypto-address-belongs-to-current-account
|
643
|
+
#
|
644
|
+
# Params:
|
645
|
+
# +String+ +address+:: The address to check
|
646
|
+
|
647
|
+
def checkIfCryptoAddressIsMine(address)
|
648
|
+
return get("account/crypto/is-mine/#{address}")
|
649
|
+
end
|
650
|
+
|
651
|
+
# Transfer money from the trading balance to the account balance
|
652
|
+
#
|
653
|
+
# Requires authentication
|
654
|
+
#
|
655
|
+
# https://api.exchange.cryptomkt.com/#transfer-money-between-trading-account-and-bank-account
|
656
|
+
#
|
657
|
+
# Params:
|
658
|
+
# +String+ +currency+:: Currency code for transfering
|
659
|
+
# +Integer+ +amount+:: Amount to be transfered
|
660
|
+
|
661
|
+
def transferMoneyFromBankToExchange(currency, amount)
|
662
|
+
params = {currency:currency, amount:amount, type:'bankToExchange'}
|
663
|
+
return post('account/transfer', params)
|
664
|
+
end
|
665
|
+
|
666
|
+
# Transfer money from the account balance to the trading balance
|
667
|
+
#
|
668
|
+
# Requires authentication
|
669
|
+
#
|
670
|
+
# https://api.exchange.cryptomkt.com/#transfer-money-between-trading-account-and-bank-account
|
671
|
+
#
|
672
|
+
# Params:
|
673
|
+
# +String+ +currency+:: Currency code for transfering
|
674
|
+
# +Integer+ +amount+:: Amount to be transfered
|
675
|
+
|
676
|
+
def transferMoneyFromExchangeToBank(currency, amount)
|
677
|
+
params = {currency:currency, amount:amount, type:'exchangeToBank'}
|
678
|
+
return post('account/transfer', params)
|
679
|
+
end
|
680
|
+
|
681
|
+
# Transfer money to another user
|
682
|
+
#
|
683
|
+
# Requires authentication
|
684
|
+
#
|
685
|
+
# https://api.exchange.cryptomkt.com/#transfer-money-to-another-user-by-email-or-username
|
686
|
+
#
|
687
|
+
# Params:
|
688
|
+
# +String+ +currency+:: currency code
|
689
|
+
# +Integer+ +amount+:: amount to be transfered between balances
|
690
|
+
# +String+ +by+:: either 'email' or 'username'
|
691
|
+
# +String+ +identifier+:: the email or the username
|
692
|
+
|
693
|
+
def transferMonyToAnotherUser(currency, amount, by, identifier)
|
694
|
+
params = {currency:currency, amount:amount, by:by, identifier:identifier}
|
695
|
+
return post('account/transfer/internal', params)
|
696
|
+
end
|
697
|
+
|
698
|
+
# Get the transactions of the account by currency
|
699
|
+
#
|
700
|
+
# Requires authentication
|
701
|
+
#
|
702
|
+
# https://api.exchange.cryptomkt.com/#get-transactions-history
|
703
|
+
#
|
704
|
+
# Params:
|
705
|
+
# +String+ +currency+:: Currency code to get the transaction history
|
706
|
+
# +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'.
|
707
|
+
# +String+ +by+:: Optional. Defines the sorting type.'timestamp' or 'id'. Default is 'timestamp'
|
708
|
+
# +String+ +from+:: Optional. Initial value of the queried interval. Id or datetime
|
709
|
+
# +String+ +till+:: Optional. Last value of the queried interval. Id or datetime
|
710
|
+
# +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1000
|
711
|
+
# +Integer+ +offset+:: Optional. Default is 0. Max is 100000
|
712
|
+
|
713
|
+
def getTransactionHistory(currency:, sort:nil, by:nil, from:nil, till:nil, limit:nil, offset:nil)
|
714
|
+
params = {currency:currency}
|
715
|
+
extend_hash_with_pagination! params, sort:sort, by:by, from:from, till:till, limit:limit, offset:offset
|
716
|
+
return get("account/transactions", params)
|
717
|
+
end
|
718
|
+
|
719
|
+
# Get the transactions of the account by its identifier
|
720
|
+
#
|
721
|
+
# Requires authentication
|
722
|
+
#
|
723
|
+
# https://api.exchange.cryptomkt.com/#get-transactions-history
|
724
|
+
#
|
725
|
+
# Params:
|
726
|
+
# +String+ +id+:: The identifier of the transaction
|
727
|
+
|
728
|
+
def getTransaction(id)
|
729
|
+
return get("account/transactions/#{id}")
|
730
|
+
end
|
731
|
+
end
|
732
|
+
end
|