cryptomarket-sdk 1.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,732 +1,1242 @@
1
- require_relative "HttpManager"
2
- require_relative "utils"
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Layout/LineLength
4
+ require_relative 'http_manager'
3
5
 
4
6
  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 getEstimateWithdrawFee(currency, amount)
634
- params = {amount:amount, currency:currency}
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
7
+ # Creates a new rest client
8
+ #
9
+ # ==== Params
10
+ # +String+ +api_key+:: the user api key
11
+ # +String+ +api_secret+:: the user api secret
12
+ # +Integer+ +window+:: Maximum difference between the creation of the request and the moment of request processing in milliseconds. Max is 60_000. Defaul is 10_000
13
+ class Client # rubocop:disable Metrics/ClassLength
14
+ def initialize(api_key: nil, api_secret: nil, window: nil)
15
+ @http_manager = HttpManager.new api_key: api_key, api_secret: api_secret, window: window
16
+ end
17
+
18
+ def public_get(endpoint, params = nil)
19
+ @http_manager.make_request(method: 'get', endpoint: endpoint, params: params, public: true)
20
+ end
21
+
22
+ def get(endpoint, params = nil)
23
+ @http_manager.make_request(method: 'get', endpoint: endpoint, params: params)
24
+ end
25
+
26
+ def post(endpoint, params = nil)
27
+ @http_manager.make_post_request(method: 'post', endpoint: endpoint, params: params)
28
+ end
29
+
30
+ def put(endpoint, params = nil)
31
+ @http_manager.make_request(method: 'put', endpoint: endpoint, params: params)
32
+ end
33
+
34
+ def patch(endpoint, params = nil)
35
+ @http_manager.make_request(method: 'patch', endpoint: endpoint, params: params)
36
+ end
37
+
38
+ def delete(endpoint, params = nil)
39
+ @http_manager.make_request(method: 'delete', endpoint: endpoint, params: params)
40
+ end
41
+
42
+ ###########
43
+ # aliases #
44
+ ###########
45
+
46
+ # market data
47
+
48
+ # alias of get ticker
49
+ alias get_ticker_by_symbol get_ticker
50
+ alias get_ticker_of_symbol get_ticker
51
+ alias get_ticker_price_by_symbol get_ticker_price
52
+ alias get_ticker_price_of_symbol get_ticker_price
53
+ alias get_trades_of_symbol get_trades_by_symbol
54
+ alias get_orderbook_by_symbol get_orderbook
55
+ alias get_orderbook_of_symbol get_orderbook
56
+ alias get_orderbook_volume_by_symbol get_orderbook_volume
57
+ alias get_orderbook_volume_of_symbol get_orderbook_volume
58
+ alias get_candles_of_symbol get_candles_by_symbol
59
+ alias get_converted_candles_of_symbol get_converted_candles_by_symbol
60
+ # spot trading
61
+ alias get_spot_trading_balance_of_currency get_spot_trading_balance
62
+ alias get_spot_trading_balance_by_currency get_spot_trading_balance
63
+ alias get_all_trading_commissions get_all_trading_commission
64
+ alias get_trading_commission get_all_trading_commission
65
+ alias get_trading_commission_of_symbol get_trading_commission
66
+ alias get_trading_commission_by_symbol get_trading_commission
67
+ # wallet management
68
+ alias get_wallet_balance_of_currency get_wallet_balance
69
+ alias get_wallet_balance_by_currency get_wallet_balance
70
+ alias get_deposit_crypto_address_of_cyrrency get_deposit_crypto_address
71
+ alias get_deposit_crypto_address_by_cyrrency get_deposit_crypto_address
72
+
73
+ ################
74
+ # public calls #
75
+ ################
76
+
77
+ # Get a Hash of all currencies or specified currencies. indexed by id
78
+ #
79
+ # Requires no API key Access Rights
80
+ #
81
+ # https://api.exchange.cryptomkt.com/#currencies
82
+ #
83
+ # ==== Params
84
+ # +Array[String]+ +currencies+:: Optional. A list of currencies ids
85
+ # +String+ +preferred_network+:: Optional. Code of de default network code of currencies
86
+
87
+ def get_currencies(currencies: nil, preferred_network: nil)
88
+ public_get('public/currency/', {
89
+ currencies: currencies,
90
+ preferred_network: preferred_network
91
+ })
92
+ end
93
+
94
+ # Get the data of a currency
95
+ #
96
+ # Requires no API key Access Rights
97
+ #
98
+ # https://api.exchange.cryptomkt.com/#currencies
99
+ #
100
+ # ==== Params
101
+ # +String+ +currency+:: A currency id
102
+
103
+ def get_currency(currency:)
104
+ public_get("public/currency/#{currency}")
105
+ end
106
+
107
+ # Get a Hash of all symbols or for specified symbols. indexed by id
108
+ # A symbol is the combination of the base currency (first one) and quote currency (second one)
109
+ #
110
+ # Requires no API key Access Rights
111
+ #
112
+ # https://api.exchange.cryptomkt.com/#symbols
113
+ #
114
+ # ==== Params
115
+ # +Array[String]+ +symbols+:: Optional. A list of symbol ids
116
+
117
+ def get_symbols(symbols: nil)
118
+ public_get('public/symbol', { symbols: symbols })
119
+ end
120
+
121
+ # Get a symbol by its id
122
+ # A symbol is the combination of the base currency (first one) and quote currency (second one)
123
+ #
124
+ # Requires no API key Access Rights
125
+ #
126
+ # https://api.exchange.cryptomkt.com/#symbols
127
+ #
128
+ # ==== Params
129
+ # +String+ +symbol+:: A symbol id
130
+
131
+ def get_symbol(symbol:)
132
+ public_get("public/symbol/#{symbol}")
133
+ end
134
+
135
+ # Get a Hash of tickers for all symbols or for specified symbols. indexed by symbol
136
+ #
137
+ # Requires no API key Access Rights
138
+ #
139
+ # https://api.exchange.cryptomkt.com/#tickers
140
+ #
141
+ # ==== Params
142
+ # +Array[String]+ +symbols+:: Optional. A list of symbol ids
143
+
144
+ def get_tickers(symbols: nil)
145
+ public_get('public/ticker', { symbols: symbols })
146
+ end
147
+
148
+ # Get the ticker of a symbol
149
+ #
150
+ # Requires no API key Access Rights
151
+ #
152
+ # https://api.exchange.cryptomkt.com/#tickers
153
+ #
154
+ # ==== Params
155
+ # +String+ +symbol+:: A symbol id
156
+
157
+ def get_ticker(symbol:)
158
+ public_get("public/ticker/#{symbol}")
159
+ end
160
+
161
+ # Get a Hash of quotation prices of currencies
162
+ #
163
+ # Requires no API key Access Rights
164
+ #
165
+ # https://api.exchange.cryptomkt.com/#prices
166
+ #
167
+ # ==== Params
168
+ # +String+ +to+:: Target currency code
169
+ # +String+ +from+:: Optional. Source currency rate
170
+
171
+ def get_prices(to:, from: nil)
172
+ public_get('public/price/rate', { to: to, from: from })
173
+ end
174
+
175
+ # Get quotation prices history
176
+ #
177
+ # Requires no API key Access Rights
178
+ #
179
+ # https://api.exchange.cryptomkt.com/#prices
180
+ #
181
+ # ==== Params
182
+ # +String+ +to+:: Target currency code
183
+ # +String+ +from+:: Optional. Source currency rate
184
+ # +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'
185
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
186
+ # +String+ +since+:: Optional. Initial value of the queried interval
187
+ # +String+ +until+:: Optional. Last value of the queried interval
188
+ # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 1. Min is 1. Max is 1_000
189
+
190
+ def get_price_history(to:, from: nil, till: nil, since: nil, limit: nil, period: nil, sort: nil) # rubocop:disable Metrics/ParameterLists
191
+ public_get(
192
+ 'public/price/history',
193
+ { to: to, from: from, till: till, since: since, limit: limit, period: period, sort: sort }
194
+ )
195
+ end
196
+
197
+ # Get a Hash of the ticker's last prices for all symbols or for the specified symbols
198
+ #
199
+ # Requires no API key Access Rights
200
+ #
201
+ # https://api.exchange.cryptomkt.com/#prices
202
+ #
203
+ # ==== Params
204
+ # +Array[String]+ +symbols+:: Optional. A list of symbol ids
205
+
206
+ def get_ticker_prices(symbols: nil)
207
+ public_get('public/price/ticker', { symbols: symbols })
208
+ end
209
+
210
+ # Get ticker's last prices of a symbol
211
+ #
212
+ # Requires no API key Access Rights
213
+ #
214
+ # https://api.exchange.cryptomkt.com/#prices
215
+ #
216
+ # ==== Params
217
+ # +String+ +symbol+:: A symbol id
218
+
219
+ def get_ticker_price(symbol:)
220
+ public_get("public/price/ticker/#{symbol}")
221
+ end
222
+
223
+ # Get a Hash of trades for all symbols or for specified symbols
224
+ # 'from' param and 'till' param must have the same format, both id or both timestamp
225
+ #
226
+ # Requires no API key Access Rights
227
+ #
228
+ # https://api.exchange.cryptomkt.com/#trades
229
+ #
230
+ # ==== Params
231
+ # +Array[String]+ +symbols+:: Optional. A list of symbol ids
232
+ # +String+ +by+:: Optional. Sorting parameter. 'id' or 'timestamp'. Default is 'timestamp'
233
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
234
+ # +String+ +since+:: Optional. Initial value of the queried interval
235
+ # +String+ +until+:: Optional. Last value of the queried interval
236
+ # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1_000
237
+
238
+ def get_trades(symbols: nil, by: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
239
+ public_get(
240
+ 'public/trades/',
241
+ { symbols: symbols, by: by, sort: sort, from: from, till: till, limit: limit, offset: offset }
242
+ )
243
+ end
244
+
245
+ # Get trades of a symbol
246
+ # 'from' param and 'till' param must have the same format, both id or both timestamp
247
+ #
248
+ # Requires no API key Access Rights
249
+ #
250
+ # https://api.exchange.cryptomkt.com/#trades
251
+ #
252
+ # ==== Params
253
+ # +String+ +symbol+:: A symbol id
254
+ # +String+ +by+:: Optional. Sorting parameter. 'id' or 'timestamp'. Default is 'timestamp'
255
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
256
+ # +String+ +since+:: Optional. Initial value of the queried interval
257
+ # +String+ +until+:: Optional. Last value of the queried interval
258
+ # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1_000
259
+ # +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100_000
260
+
261
+ def get_trades_by_symbol(symbol: nil, by: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
262
+ public_get(
263
+ "public/trades/#{symbol}",
264
+ { by: by, sort: sort, from: from, till: till, limit: limit, offset: offset }
265
+ )
266
+ end
267
+
268
+ # Get a Hash of orderbooks for all symbols or for the specified symbols
269
+ # An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level
270
+ #
271
+ # Requires no API key Access Rights
272
+ #
273
+ # https://api.exchange.cryptomkt.com/#order-books
274
+ #
275
+ # ==== Params
276
+ # +Array[String]+ +symbols+:: Optional. A list of symbol ids
277
+ # +Integer+ +depth+:: Optional. Order Book depth. Default value is 100. Set to 0 to view the full Order Book
278
+
279
+ def get_orderbooks(symbols: nil, depth: nil)
280
+ public_get('public/orderbook', { symbols: symbols, depth: depth })
281
+ end
282
+
283
+ # Get order book of a symbol
284
+ # An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level
285
+ #
286
+ # Requires no API key Access Rights
287
+ #
288
+ # https://api.exchange.cryptomkt.com/#order-books
289
+ #
290
+ # ==== Params
291
+ # +String+ +symbol+:: A symbol id
292
+ # +Integer+ +depth+:: Optional. Order Book depth. Default value is 100. Set to 0 to view the full Order Book
293
+
294
+ def get_orderbook(symbol:, depth: nil)
295
+ public_get("public/orderbook/#{symbol}", { depth: depth })
296
+ end
297
+
298
+ # Get order book of a symbol with the desired volume for market depth search
299
+ # An Order Book is an electronic list of buy and sell orders for a specific symbol, structured by price level
300
+ #
301
+ # Requires no API key Access Rights
302
+ #
303
+ # https://api.exchange.cryptomkt.com/#order-books
304
+ #
305
+ # ==== Params
306
+ # +String+ +symbol+:: A symbol id
307
+ # +float+ +volume+:: Optional. Desired volume for market depth search
308
+
309
+ def get_orderbook_volume(symbol:, volume: nil)
310
+ public_get("public/orderbook/#{symbol}", { volume: volume })
311
+ end
312
+
313
+ # Get a Hash of candles for all symbols or for specified symbols
314
+ # Candles are used for OHLC representation
315
+ # The result contains candles with non-zero volume only (no trades = no candles)
316
+ #
317
+ # Requires no API key Access Rights
318
+ #
319
+ # https://api.exchange.cryptomkt.com/#candles
320
+ #
321
+ # ==== Params
322
+ # +String+ +symbol+:: A symbol id
323
+ # +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'
324
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
325
+ # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime
326
+ # +String+ +till+:: Optional. Last value of the queried interval. As DateTime
327
+ # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 10. Min is 1. Max is 1_000
328
+
329
+ def get_candles(symbols: nil, period: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
330
+ public_get(
331
+ 'public/candles/',
332
+ { symbols: symbols, period: period, sort: sort, from: from, till: till, limit: limit, offset: offset }
333
+ )
334
+ end
335
+
336
+ # Get candles of a symbol
337
+ # Candles are used for OHLC representation
338
+ # The result contains candles with non-zero volume only (no trades = no candles)
339
+ #
340
+ # Requires no API key Access Rights
341
+ #
342
+ # https://api.exchange.cryptomkt.com/#candles
343
+ #
344
+ # ==== Params
345
+ # +String+ +symbol+:: A symbol id
346
+ # +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'
347
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
348
+ # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime
349
+ # +String+ +till+:: Optional. Last value of the queried interval. As DateTime
350
+ # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000
351
+ # +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100_000
352
+
353
+ def get_candles_by_symbol(symbol:, period: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
354
+ public_get(
355
+ "public/candles/#{symbol}",
356
+ { period: period, sort: sort, from: from, till: till, limit: limit, offset: offset }
357
+ )
358
+ end
359
+
360
+ # Gets OHLCV data regarding the last price converted to the target currency for all symbols or for the specified symbols
361
+ #
362
+ # Candles are used for OHLC representation
363
+ #
364
+ # The result contains candles with non-zero volume only (no trades = no candles)
365
+ #
366
+ # Conversion from the symbol quote currency to the target currency is the mean of "best" bid price and "best" ask price in the order book. If there is no "best" bid or ask price, the last price is returned.
367
+ #
368
+ # Requires no API key Access Rights
369
+ #
370
+ # https://api.exchange.cryptomkt.com/#candles
371
+ #
372
+ # +String+ +target_currency+:: Target currency for conversion
373
+ # +Array[String]+ +symbols+:: Optional. A list of symbols
374
+ # +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'
375
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
376
+ # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime
377
+ # +String+ +till+:: Optional. Last value of the queried interval. As DateTime
378
+ # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000
379
+
380
+ def get_converted_candles(target_currency:, symbols: nil, period: nil, sort: nil, from: nil, till: nil, limit: nil) # rubocop:disable Metrics/ParameterLists
381
+ public_get(
382
+ 'public/converted/candles',
383
+ { target_currency: target_currency, symbols: symbols, period: period, sort: sort, from: from, till: till, limit: limit }
384
+ )
385
+ end
386
+
387
+ # Gets OHLCV data regarding the last price converted to the target currency for the specified symbol
388
+ #
389
+ # Candles are used for OHLC representation
390
+ #
391
+ # The result contains candles with non-zero volume only (no trades = no candles)
392
+ #
393
+ # Conversion from the symbol quote currency to the target currency is the mean of "best" bid price and "best" ask price in the order book. If there is no "best" bid or ask price, the last price is returned.
394
+ #
395
+ # Requires no API key Access Rights
396
+ #
397
+ # https://api.exchange.cryptomkt.com/#candles
398
+ #
399
+ # +String+ +target_currency+:: Target currency for conversion
400
+ # +String+ +symbol+:: A symbol id
401
+ # +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'
402
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
403
+ # +String+ +from+:: Optional. Initial value of the queried interval. As DateTime
404
+ # +String+ +till+:: Optional. Last value of the queried interval. As DateTime
405
+ # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Min is 1. Max is 1_000
406
+ # +Integer+ +offset+:: Optional. Default is 0. Min is 0. Max is 100_000
407
+
408
+ def get_converted_candles_by_symbol(target_currency:, symbol:, period: nil, sort: nil, from: nil, till: nil, limit: nil, offset: nil) # rubocop:disable Metrics/ParameterLists
409
+ public_get(
410
+ "public/converted/candles/#{symbol}",
411
+ { target_currency: target_currency, period: period, sort: sort, from: from, till: till, limit: limit, offset: offset }
412
+ )
413
+ end
414
+
415
+ ######################
416
+ # Spot Trading calls #
417
+ ######################
418
+
419
+ # Get the user's spot trading balance for all currencies with balance
420
+ #
421
+ # Requires the "Orderbook, History, Trading balance" API key Access Right
422
+ #
423
+ # https://api.exchange.cryptomkt.com/#get-spot-trading-balance
424
+
425
+ def get_spot_trading_balances # rubocop:disable Naming/AccessorMethodName
426
+ get('spot/balance')
427
+ end
428
+
429
+ # Get the user spot trading balance of a currency
430
+ #
431
+ # Requires the "Orderbook, History, Trading balance" API key Access Right
432
+ #
433
+ # https://api.exchange.cryptomkt.com/#get-spot-trading-balance
434
+ #
435
+ # ==== Params
436
+ # +String+ +currency+:: The currency code to query the balance
437
+
438
+ def get_spot_trading_balance(currency:)
439
+ balance = get("spot/balance/#{currency}")
440
+ balance['currency'] = currency
441
+ balance
442
+ end
443
+
444
+ # Get the user's active spot orders
445
+ #
446
+ # Requires the "Place/cancel orders" API key Access Right
447
+ #
448
+ # https://api.exchange.cryptomkt.com/#get-all-active-spot-orders
449
+ #
450
+ # ==== Params
451
+ # +String+ +symbol+:: Optional. A symbol for filtering the active spot orders
452
+
453
+ def get_all_active_spot_orders(symbol: nil)
454
+ get('spot/order', { symbol: symbol })
455
+ end
456
+
457
+ # Get an active spot order by its client order id
458
+ #
459
+ # Requires the "Place/cancel orders" API key Access Right
460
+ #
461
+ # https://api.exchange.cryptomkt.com/#get-active-spot-order
462
+ #
463
+ # ==== Params
464
+ # +String+ +client_order_id+:: The client order id of the order
465
+
466
+ def get_active_spot_order(client_order_id:)
467
+ get("spot/order/#{client_order_id}")
468
+ end
469
+
470
+ # Creates a new spot order
471
+ # For fee, for price accuracy and quantity, and for order status information see the api docs
472
+ #
473
+ # Requires the "Place/cancel orders" API key Access Right
474
+ #
475
+ # https://api.exchange.cryptomkt.com/#create-new-spot-order
476
+ #
477
+ # ==== Params
478
+ # +String+ +symbol+:: Trading symbol
479
+ # +String+ +side+:: Either 'buy' or 'sell'
480
+ # +String+ +quantity+:: Order quantity
481
+ # +String+ +client_order_id+:: Optional. If given must be unique within the trading day, including all active orders. If not given, is generated by the server
482
+ # +String+ +type+:: Optional. 'limit', 'market', 'stopLimit', 'stopMarket', 'takeProfitLimit' or 'takeProfitMarket'. Default is 'limit'
483
+ # +String+ +time_in_force+:: Optional. 'GTC', 'IOC', 'FOK', 'Day', 'GTD'. Default is 'GTC' if 'limit', 'stopLimit' or 'takeProfitLimit' order, Default is 'FOK' if 'market', 'stopMarket' or 'takeProfitMarket' order
484
+ # +String+ +price+:: Optional. Required for 'limit' and 'stopLimit'. limit price of the order
485
+ # +String+ +stop_price+:: Optional. Required for 'stopLimit' and 'stopMarket' orders. stop price of the order
486
+ # +String+ +expire_time+:: Optional. Required for orders with timeInForce = GDT
487
+ # +bool+ +strict_validate+:: 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
488
+ # +bool+ +post_only+:: Optional. If True, your post_only order causes a match with a pre-existing order as a taker, then the order will be cancelled
489
+ # +String+ +take_rate+:: Optional. Liquidity taker fee, a fraction of order volume, such as 0.001 (for 0.1% fee). Can only increase the fee. Used for fee markup.
490
+ # +String+ +make_rate+:: Optional. Liquidity provider fee, a fraction of order volume, such as 0.001 (for 0.1% fee). Can only increase the fee. Used for fee markup.
491
+
492
+ def create_spot_order( # rubocop:disable Metrics/ParameterLists
493
+ symbol:, side:, quantity:, client_order_id: nil, type: nil, time_in_force: nil, price: nil,
494
+ stop_price: nil, expire_time: nil, strict_validate: nil, post_only: nil, take_rate: nil,
495
+ make_rate: nil
496
+ )
497
+ post(
498
+ 'spot/order',
499
+ { client_order_id: client_order_id, symbol: symbol, side: side, quantity: quantity, type: type,
500
+ time_in_force: time_in_force, price: price, stop_price: stop_price, expire_time: expire_time,
501
+ strict_validate: strict_validate, post_only: post_only, take_rate: take_rate, make_rate: make_rate }
502
+ )
503
+ end
504
+
505
+ # creates a list of spot orders
506
+ #
507
+ # = Types or contingency
508
+ # - 'allOrNone' (AON)
509
+ # - 'oneCancelAnother' (OCO)
510
+ # - 'oneTriggerOther' (OTO)
511
+ # - 'oneTriggerOneCancelOther' (OTOCO)
512
+ #
513
+ # = Restriction in the number of orders:
514
+ # - An AON list must have 2 or 3 orders
515
+ # - An OCO list must have 2 or 3 orders
516
+ # - An OTO list must have 2 or 3 orders
517
+ # - An OTOCO must have 3 or 4 orders
518
+ #
519
+ # = Symbol restrictions
520
+ # - For an AON order list, the symbol code of orders must be unique for each order in the list.
521
+ # - For an OCO order list, there are no symbol code restrictions.
522
+ # - For an OTO order list, there are no symbol code restrictions.
523
+ # - For an OTOCO order list, the symbol code of orders must be the same for all orders in the list (placing orders in different order books is not supported).
524
+ #
525
+ # = OrderType restrictions
526
+ # - For an AON order list, orders must be 'limit' or 'market'
527
+ # - For an OCO order list, orders must be 'limit', 'stopLimit', 'stopMarket', takeProfitLimit or takeProfitMarket.
528
+ # - An OCO order list cannot include more than one limit order (the same
529
+ # applies to secondary orders in an OTOCO order list).
530
+ # - For OTO order list, there are no order type restrictions.
531
+ # - For an OTOCO order list, the first order must be 'limit', 'market', 'stopLimit', 'stopMarket', takeProfitLimit or takeProfitMarket.
532
+ # - For an OTOCO order list, the secondary orders have the same restrictions as an OCO order
533
+ # - Default is 'limit'
534
+ #
535
+ # https://api.exchange.cryptomkt.com/#create-new-spot-order-list
536
+ #
537
+ # ==== Params
538
+ # +String+ +order_list_id+:: order list identifier. If ommited, it will be generated by the system. Must be equal to the client order id of the first order in the request
539
+ # +String+ +contingency_type+:: order list type. 'allOrNone', 'oneCancelOther' or 'oneTriggerOneCancelOther'
540
+ # +Array[]+ +orders+:: the list of orders. aech order in the list has the same parameters of a new spot order
541
+
542
+ def create_spot_order_list(
543
+ contingency_type:,
544
+ orders:,
545
+ order_list_id: nil
546
+ )
547
+ post(
548
+ 'spot/order/list',
549
+ {
550
+ order_list_id: order_list_id,
551
+ contingency_type: contingency_type,
552
+ orders: orders
553
+ }
554
+ )
555
+ end
556
+
557
+ # Replaces a spot order
558
+ # For fee, for price accuracy and quantity, and for order status information see the api docs
559
+ #
560
+ # Requires the "Place/cancel orders" API key Access Right
561
+ #
562
+ # https://api.exchange.cryptomkt.com/#replace-spot-order
563
+ #
564
+ # ==== Params
565
+ # +String+ +client_order_id+:: client order id of the old order
566
+ # +String+ +new client order id+:: client order id for the new order
567
+ # +String+ +quantity+:: Order quantity
568
+ # +bool+ +strict_validate+:: Price and quantity will be checked for incrementation within the symbol’s tick size and quantity step. See the symbol's tick_size and quantity_increment
569
+ # +String+ +price+:: Required if order type is 'limit', 'stopLimit', or 'takeProfitLimit'. Order price
570
+
571
+ def replace_spot_order(
572
+ client_order_id:,
573
+ new_client_order_id:,
574
+ quantity:,
575
+ price: nil,
576
+ strict_validate: nil
577
+ )
578
+ patch(
579
+ "spot/order/#{client_order_id}",
580
+ {
581
+ new_client_order_id: new_client_order_id,
582
+ price: price,
583
+ quantity: quantity,
584
+ strict_validate: strict_validate
585
+ }
586
+ )
587
+ end
588
+
589
+ # Cancel all active spot orders
590
+ #
591
+ # Requires the "Place/cancel orders" API key Access Right
592
+ #
593
+ # https://api.exchange.cryptomkt.com/#cancel-all-spot-orders
594
+ #
595
+
596
+ def cancel_all_spot_orders
597
+ delete('spot/order')
598
+ end
599
+
600
+ # Cancel the order with the client order id
601
+ #
602
+ # Requires the "Place/cancel orders" API key Access Right
603
+ #
604
+ # https://api.exchange.cryptomkt.com/#cancel-spot-order
605
+ #
606
+ # ==== Params
607
+ # +String+ +client_order_id+:: client order id of the order to cancel
608
+
609
+ def cancel_spot_order(client_order_id:)
610
+ delete("spot/order/#{client_order_id}")
611
+ end
612
+
613
+ # Get the personal trading commission rates for all symbols
614
+ #
615
+ # Requires the "Place/cancel orders" API key Access Right
616
+ #
617
+ # https://api.exchange.cryptomkt.com/#get-all-trading-commissions
618
+
619
+ def get_all_trading_commission # rubocop:disable Naming/AccessorMethodName
620
+ get('spot/fee')
621
+ end
622
+
623
+ # Get the personal trading commission rate of a symbol
624
+ #
625
+ # Requires the "Place/cancel orders" API key Access Right
626
+ #
627
+ # https://api.exchange.cryptomkt.com/#get-trading-commission
628
+ #
629
+ # ==== Params
630
+ # +String+ +symbol+:: The symbol of the commission rate
631
+
632
+ def get_trading_commission(symbol:)
633
+ commission = get("spot/fee/#{symbol}")
634
+ commission['symbol'] = symbol
635
+ commission
636
+ end
637
+
638
+ ########################
639
+ # spot trading history #
640
+ ########################
641
+
642
+ # Get all the spot orders
643
+ # Orders without executions are deleted after 24 hours
644
+ # 'from' param and 'till' param must have the same format, both id or both timestamp
645
+ #
646
+ # Requires the "Orderbook, History, Trading balance" API key Access Right
647
+ #
648
+ # https://api.exchange.cryptomkt.com/#spot-orders-history
649
+ #
650
+ # ==== Params
651
+ # +String+ +symbol+:: Optional. Filter orders by symbol
652
+ # +String+ +by+:: Optional. Sorting parameter. 'id' or 'timestamp'. Default is 'timestamp'
653
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
654
+ # +String+ +from+:: Optional. Initial value of the queried interval
655
+ # +String+ +till+:: Optional. Last value of the queried interval
656
+ # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1_000
657
+ # +Integer+ +offset+:: Optional. Default is 0. Max is 100_000
658
+
659
+ def get_spot_orders_history( # rubocop:disable Metrics/ParameterLists
660
+ client_order_id: nil, symbol: nil, sort: nil, by: nil, from: nil,
661
+ till: nil, limit: nil, offset: nil
662
+ )
663
+ get(
664
+ 'spot/history/order',
665
+ { client_order_id: client_order_id, symbol: symbol, sort: sort,
666
+ by: by, from: from, till: till, limit: limit, offset: offset }
667
+ )
668
+ end
669
+
670
+ # Get the user's spot trading history
671
+ #
672
+ # Requires the "Orderbook, History, Trading balance" API key Access Right
673
+ #
674
+ # https://api.exchange.cryptomkt.com/#spot-trades-history
675
+ #
676
+ # ==== Params
677
+ # +String+ +order id+:: Optional. Order unique identifier as assigned by the exchange
678
+ # +String+ +symbol+:: Optional. Filter orders by symbol
679
+ # +String+ +by+:: Optional. Sorting parameter. 'id' or 'timestamp'. Default is 'timestamp'
680
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
681
+ # +String+ +from+:: Optional. Initial value of the queried interval
682
+ # +String+ +till+:: Optional. Last value of the queried interval
683
+ # +Integer+ +limit+:: Optional. Prices per currency pair. Defaul is 100. Max is 1_000
684
+ # +Integer+ +offset+:: Optional. Default is 0. Max is 100_000
685
+
686
+ def get_spot_trades_history( # rubocop:disable Metrics/ParameterLists
687
+ order_id: nil, symbol: nil, sort: nil, by: nil, from: nil,
688
+ till: nil, limit: nil, offset: nil
689
+ )
690
+ get(
691
+ 'spot/history/trade',
692
+ { order_id: order_id, symbol: symbol, sort: sort,
693
+ by: by, from: from, till: till, limit: limit, offset: offset }
694
+ )
695
+ end
696
+
697
+ #####################
698
+ # Wallet Management #
699
+ #####################
700
+
701
+ # Get the user's wallet balance for all currencies with balance
702
+ #
703
+ # Requires the "Payment information" API key Access Right
704
+ #
705
+ # https://api.exchange.cryptomkt.com/#wallet-balance
706
+
707
+ def get_wallet_balances # rubocop:disable Naming/AccessorMethodName
708
+ get('wallet/balance')
709
+ end
710
+
711
+ # Get the user's wallet balance of a currency
712
+ #
713
+ # Requires the "Payment information" API key Access Right
714
+ #
715
+ # https://api.exchange.cryptomkt.com/#wallet-balance
716
+ #
717
+ # ==== Params
718
+ # +String+ +currency+:: The currency code to query the balance
719
+
720
+ def get_wallet_balance(currency:)
721
+ get("wallet/balance/#{currency}")
722
+ end
723
+
724
+ # Get a list with the current addresses of the user
725
+ #
726
+ # Requires the "Payment information" API key Access Right
727
+ #
728
+ # https://api.exchange.cryptomkt.com/#get-deposit-crypto-address
729
+
730
+ def get_deposit_crypto_addresses # rubocop:disable Naming/AccessorMethodName
731
+ get('wallet/crypto/address')
732
+ end
733
+
734
+ # Get the current addresses of a currency of the user
735
+ #
736
+ # Getting the address of a new currency will create an address
737
+ #
738
+ # Requires the "Payment information" API key Access Right
739
+ #
740
+ # https://api.exchange.cryptomkt.com/#get-deposit-crypto-address
741
+ #
742
+ # ==== Params
743
+ # +String+ +currency+:: Currency to get the address
744
+ # +String+ +network_code+:: Optional. network code
745
+
746
+ def get_deposit_crypto_address(currency: nil, network_code: nil)
747
+ result = get('wallet/crypto/address', { currency: currency, network_code: network_code })
748
+ raise CryptomarketSDKException 'Too many currencies recieved, expected 1 currency' if result.length != 1
749
+
750
+ result[0]
751
+ end
752
+
753
+ # Creates a new address for a currency
754
+ #
755
+ # Requires the "Payment information" API key Access Right
756
+ #
757
+ # https://api.exchange.cryptomkt.com/#generate-deposit-crypto-address
758
+ #
759
+ # ==== Params
760
+ # +String+ +currency+:: currency to create a new address
761
+ # +String+ +network_code+:: Optional. network code
762
+
763
+ def create_deposit_crypto_address(currency:, network_code: nil)
764
+ post('wallet/crypto/address', { currency: currency, network_code: network_code })
765
+ end
766
+
767
+ # Get the last 10 unique addresses used for deposit, by currency
768
+ # Addresses used a long time ago may be omitted, even if they are among the last 10 unique addresses
769
+ #
770
+ # Requires the "Payment information" API key Access Right
771
+ #
772
+ # https://api.exchange.cryptomkt.com/#last-10-deposit-crypto-addresses
773
+ #
774
+ # ==== Params
775
+ # +String+ +currency+:: currency to get the list of addresses
776
+ # +String+ +network_code+:: Optional. network code
777
+
778
+ def get_last_10_deposit_crypto_addresses(currency:, network_code: nil)
779
+ get('wallet/crypto/address/recent-deposit', { currency: currency, network_code: network_code })
780
+ end
781
+
782
+ # Get the last 10 unique addresses used for withdrawals, by currency
783
+ # Addresses used a long time ago may be omitted, even if they are among the last 10 unique addresses
784
+ #
785
+ # Requires the "Payment information" API key Access Right
786
+ #
787
+ # https://api.exchange.cryptomkt.com/#last-10-withdrawal-crypto-addresses
788
+ #
789
+ # ==== Params
790
+ # +String+ +currency+:: currency to get the list of addresses
791
+ # +String+ +network_code+:: Optional. network code
792
+
793
+ def get_last_10_withdrawal_crypto_addresses(currency:, network_code: nil)
794
+ get('wallet/crypto/address/recent-withdraw', { currency: currency, network_code: network_code })
795
+ end
796
+
797
+ # Please take note that changing security settings affects withdrawals:
798
+ # - It is impossible to withdraw funds without enabling the two-factor authentication (2FA)
799
+ # - Password reset blocks withdrawals for 72 hours
800
+ # - Each time a new address is added to the whitelist, it takes 48 hours before that address becomes active for withdrawal
801
+ # Successful response to the request does not necessarily mean the resulting transaction got executed immediately. It has to be processed first and may eventually be rolled back
802
+ # To see whether a transaction has been finalized, call #get_transaction
803
+ #
804
+ # Requires the "Withdraw cryptocurrencies" API key Access Right
805
+ #
806
+ # https://api.exchange.cryptomkt.com/#withdraw-crypto
807
+ #
808
+ # ==== Params
809
+ # +String+ +currency+:: currency code of the crypto to withdraw
810
+ # +float+ +amount+:: amount to be sent to the specified address
811
+ # +String+ +address+:: address identifier
812
+ # +String+ +network_code+:: Optional. network code
813
+ # +String+ +payment id+:: Optional.
814
+ # +bool+ +include fee+:: Optional. If true then the amount includes fees. Default is false
815
+ # +bool+ +auto commit+:: Optional. If false then you should commit or rollback the transaction in an hour. Used in two phase commit schema. Default is true
816
+ # +String+ +use offchain+:: Optional. Whether the withdrawal may be comitted offchain. Accepted values are 'never', 'optionaly' and 'required'.
817
+ # +String+ +public comment+:: Optional. Maximum lenght is 255
818
+
819
+ def withdraw_crypto( # rubocop:disable Metrics/ParameterLists
820
+ currency:, amount:, address:, network_code: nil, payment_id: nil,
821
+ include_fee: nil, auto_commit: nil, use_offchain: nil, public_comment: nil
822
+ )
823
+ post(
824
+ 'wallet/crypto/withdraw',
825
+ { currency: currency, amount: amount, address: address, network_code: network_code,
826
+ payment_id: payment_id, include_fee: include_fee, auto_commit: auto_commit,
827
+ use_offchain: use_offchain, public_comment: public_comment }
828
+ )['id']
829
+ end
830
+
831
+ # Commit a withdrawal
832
+ #
833
+ # Requires the "Withdraw cryptocurrencies" API key Access Right
834
+ #
835
+ # https://api.exchange.cryptomkt.com/#withdraw-crypto-commit-or-rollback
836
+ #
837
+ # ==== Params
838
+ # +String+ +id+:: the withdrawal transaction identifier
839
+
840
+ def withdraw_crypto_commit(id:)
841
+ put("wallet/crypto/withdraw/#{id}")['result']
842
+ end
843
+
844
+ # Rollback a withdrawal
845
+ #
846
+ # Requires the "Withdraw cryptocurrencies" API key Access Right
847
+ #
848
+ # https://api.exchange.cryptomkt.com/#withdraw-crypto-commit-or-rollback
849
+ #
850
+ # ==== Params
851
+ # +String+ +id+:: the withdrawal transaction identifier
852
+
853
+ def withdraw_crypto_rollback(id:)
854
+ delete("wallet/crypto/withdraw/#{id}")['result']
855
+ end
856
+
857
+ # Get an estimates for withdrawal fees of currencies
858
+ #
859
+ # Requires the "Payment information" API key Access Right
860
+ #
861
+ # https://api.exchange.cryptomkt.com/#estimate-withdrawal-fees
862
+ #
863
+ # ==== Params
864
+ # +Array[]+ +fee_requests+:: the list of fee requests, each request is a Hash in the form {currency:"string", amount:"string", network_code:"optional string"}
865
+
866
+ def get_estimate_withdrawal_fees(fee_requests)
867
+ params = fee_requests
868
+ post('wallet/crypto/fees/estimate', params)
869
+ end
870
+
871
+ # Get an estimate of the withdrawal fee
872
+ #
873
+ # Requires the "Payment information" API key Access Right
874
+ #
875
+ # https://api.exchange.cryptomkt.com/#estimate-withdrawal-fee
876
+ #
877
+ # ==== Params
878
+ # +String+ +currency+:: the currency code for withdrawal
879
+ # +float+ +amount+:: the expected withdraw amount
880
+
881
+ def get_estimate_withdrawal_fee(currency:, amount:, network_code: nil)
882
+ params = { amount: amount, currency: currency, network_code: network_code }
883
+ get('wallet/crypto/fee/estimate', params)['fee']
884
+ end
885
+
886
+ # Converts between currencies
887
+ # Successful response to the request does not necessarily mean the resulting transaction got executed immediately. It has to be processed first and may eventually be rolled back
888
+ # To see whether a transaction has been finalized, call #get_transaction
889
+ #
890
+ # Requires the "Payment information" API key Access Right
891
+ #
892
+ # https://api.exchange.cryptomkt.com/#convert-between-currencies
893
+ #
894
+ # ==== Params
895
+ # +String+ +from currency+:: currency code of origin
896
+ # +String+ +to currency+:: currency code of destiny
897
+ # +float+ +amount+:: the amount to be converted
898
+
899
+ def convert_between_currencies(from_currency:, to_currency:, amount:)
900
+ post(
901
+ 'wallet/convert',
902
+ {
903
+ from_currency: from_currency,
904
+ to_currency: to_currency,
905
+ amount: amount
906
+ }
907
+ )['result']
908
+ end
909
+
910
+ # Check if an address is from this account
911
+ #
912
+ # Requires the "Payment information" API key Access Right
913
+ #
914
+ # https://api.exchange.cryptomkt.com/#check-if-crypto-address-belongs-to-current-account
915
+ #
916
+ # ==== Params
917
+ # +String+ +address+:: address to check
918
+
919
+ def crypto_address_belongs_to_current_account?(address:)
920
+ get('wallet/crypto/address/check-mine', { address: address })['result']
921
+ end
922
+
923
+ # Transfer funds between account types
924
+ # 'source' param and 'destination' param must be different account types
925
+ #
926
+ # Requires the "Payment information" API key Access Right
927
+ #
928
+ # https://api.exchange.cryptomkt.com/#transfer-between-wallet-and-exchange
929
+ #
930
+ # ==== Params
931
+ # +String+ +currency+:: currency code for transfering
932
+ # +float+ +amount+:: amount to be transfered
933
+ # +String+ +source+:: transfer source account type. Either 'wallet' or 'spot'
934
+ # +String+ +destination+:: transfer source account type. Either 'wallet' or 'spot'
935
+
936
+ def transfer_between_wallet_and_exchange(currency:, amount:, source:, destination:)
937
+ post(
938
+ 'wallet/transfer',
939
+ {
940
+ currency: currency,
941
+ amount: amount,
942
+ source: source,
943
+ destination: destination
944
+ }
945
+ )
946
+ end
947
+
948
+ # Transfer funds to another user
949
+ #
950
+ # Requires the "Withdraw cryptocurrencies" API key Access Right
951
+ #
952
+ # https://api.exchange.cryptomkt.com/#transfer-money-to-another-user
953
+ #
954
+ # ==== Params
955
+ # +String+ +currency+:: currency code
956
+ # +float+ +amount+:: amount to be transfered
957
+ # +String+ +transfer by+:: type of identifier. Either 'email' or 'username'
958
+ # +String+ +identifier+:: the email or username of the recieving user
959
+
960
+ def transfer_money_to_another_user(currency:, amount:, by:, identifier:)
961
+ post(
962
+ 'wallet/internal/withdraw',
963
+ {
964
+ currency: currency,
965
+ amount: amount,
966
+ by: by,
967
+ identifier: identifier
968
+ }
969
+ )
970
+ end
971
+
972
+ # Get the transaction history of the account
973
+ # Important:
974
+ # - The list of supported transaction types may be expanded in future versions
975
+ # - Some transaction subtypes are reserved for future use and do not purport to provide any functionality on the platform
976
+ # - The list of supported transaction subtypes may be expanded in future versions
977
+ #
978
+ # Requires the "Payment information" API key Access Right
979
+ #
980
+ # https://api.exchange.cryptomkt.com/#get-transactions-history
981
+ #
982
+ # ==== Params
983
+ # +Array[String]+ +tx_ids+:: Optional. List of transaction identifiers to query
984
+ # +Array[String]+ +types+:: Optional. List of transaction types to query. valid types are: 'DEPOSIT', 'WITHDRAW', 'TRANSFER' and 'SWAP'
985
+ # +Array[String]+ +subtyes+:: Optional. List of transaction subtypes to query. valid subtypes are: 'UNCLASSIFIED', 'BLOCKCHAIN', 'AIRDROP', 'AFFILIATE', 'STAKING', 'BUY_CRYPTO', 'OFFCHAIN', 'FIAT', 'SUB_ACCOUNT', 'WALLET_TO_SPOT', 'SPOT_TO_WALLET', 'WALLET_TO_DERIVATIVES', 'DERIVATIVES_TO_WALLET', 'CHAIN_SWITCH_FROM', 'CHAIN_SWITCH_TO' and 'INSTANT_EXCHANGE'
986
+ # +Array[String]+ +statuses+:: Optional. List of statuses to query. valid subtypes are: 'CREATED', 'PENDING', 'FAILED', 'SUCCESS' and 'ROLLED_BACK'
987
+ # +Array[String]+ +currencies+:: Optional. Currency codes of the transactions to fetch
988
+ # +Array[String]+ +networks+:: Optional. Network codes of the transactions to fetch
989
+ # +String+ +order_by+:: Optional. sorting parameter.'created_at' or 'id'. Default is 'created_at'
990
+ # +String+ +from+:: Optional. Interval initial value when ordering by 'created_at'. As Datetime
991
+ # +String+ +till+:: Optional. Interval end value when ordering by 'created_at'. As Datetime
992
+ # +String+ +id_from+:: Optional. Interval initial value when ordering by id. Min is 0
993
+ # +String+ +id_till+:: Optional. Interval end value when ordering by id. Min is 0
994
+ # +String+ +sort+:: Optional. Sort direction. 'ASC' or 'DESC'. Default is 'DESC'
995
+ # +Integer+ +limit+:: Optional. Transactions per query. Defaul is 100. Max is 1_000
996
+ # +Integer+ +offset+:: Optional. Default is 0. Max is 100_000
997
+ # +bool+ +group_transactions+:: Optional. Flag indicating whether the returned transactions will be parts of a single operation. Default is false
998
+
999
+ def get_transaction_history( # rubocop:disable Metrics/ParameterLists
1000
+ currency: nil, from: nil, till: nil, types: nil, subtypes: nil, statuses: nil,
1001
+ currencies: nil, networks: nil, id_from: nil, id_till: nil, tx_ids: nil, order_by: nil,
1002
+ sort: nil, limit: nil, offset: nil, group_transactions: nil
1003
+ )
1004
+ get(
1005
+ 'wallet/transactions',
1006
+ { currency: currency, from: from, till: till, types: types, subtypes: subtypes, statuses: statuses,
1007
+ currencies: currencies, networks: networks, id_from: id_from, id_till: id_till, tx_ids: tx_ids,
1008
+ order_by: order_by, sort: sort, limit: limit, offset: offset, group_transactions: group_transactions }
1009
+ )
1010
+ end
1011
+
1012
+ # Get a transaction by its identifier
1013
+ #
1014
+ # Requires the "Payment information" API key Access Right
1015
+ #
1016
+ # https://api.exchange.cryptomkt.com/#get-transactions-history
1017
+ #
1018
+ # ==== Params
1019
+ # +String+ +id+:: The identifier of the transaction
1020
+
1021
+ def get_transaction(id:)
1022
+ get("wallet/transactions/#{id}")
1023
+ end
1024
+
1025
+ # get the status of the offchain
1026
+ #
1027
+ # Requires the "Payment information" API key Access Right
1028
+ #
1029
+ # https://api.exchange.cryptomkt.com/#check-if-offchain-is-available
1030
+ #
1031
+ # ==== Params
1032
+ # +String+ +currency+:: currency code
1033
+ # +String+ +address+:: address identifier
1034
+ # +String+ +payment id+:: Optional.
1035
+
1036
+ def offchain_available?(
1037
+ currency:,
1038
+ address:,
1039
+ payment_id: nil
1040
+ )
1041
+ post(
1042
+ 'wallet/crypto/check-offchain-available',
1043
+ {
1044
+ currency: currency,
1045
+ address: address,
1046
+ payment_id: payment_id
1047
+ }
1048
+ )['result']
1049
+ end
1050
+
1051
+ # Get the list of amount locks
1052
+ #
1053
+ # Requires the "Payment information" API key Access Right
1054
+ #
1055
+ # https://api.exchange.cryptomkt.com/#get-amount-locks
1056
+ #
1057
+ # ==== Params
1058
+ # +String+ +currency+:: Optional. Currency code
1059
+ # +bool+ +active+:: Optional. value showing whether the lock is active
1060
+ # +Integer+ +limit+:: Optional. Dafault is 100. Min is 0. Max is 1_000
1061
+ # +Integer+ +offset+:: Optional. Default is 0. Min is 0
1062
+ # +String+ +from+:: Optional. Interval initial value. As Datetime
1063
+ # +String+ +till+:: Optional. Interval end value. As Datetime
1064
+
1065
+ def get_amount_locks( # rubocop:disable Metrics/ParameterLists
1066
+ currency: nil, active: nil, limit: nil, offset: nil, from: nil, till: nil
1067
+ )
1068
+ get(
1069
+ 'wallet/amount-locks',
1070
+ { currency: currency, active: active, limit: limit, offset: offset, from: from, till: till }
1071
+ )
1072
+ end
1073
+
1074
+ # Returns list of sub-accounts per a super account.
1075
+ #
1076
+ # Requires no API key Access Rights.
1077
+ #
1078
+ # https://api.exchange.cryptomkt.com/#sub-accounts
1079
+
1080
+ def get_sub_account_list # rubocop:disable Naming/AccessorMethodName
1081
+ get(
1082
+ 'sub-account'
1083
+ )['result']
1084
+ end
1085
+
1086
+ # Freezes sub-accounts listed
1087
+ # Sub-accounts frozen wouldn't be able to:
1088
+ # * login
1089
+ # * withdraw funds
1090
+ # * trade
1091
+ # * complete pending orders
1092
+ # * use API keys
1093
+ #
1094
+ # For any sub-account listed, all orders will be canceled and all funds will be transferred form the Trading balance
1095
+ #
1096
+ # Requires no API key Access Rights
1097
+ #
1098
+ # https://api.exchange.cryptomkt.com/#freeze-sub-account
1099
+ #
1100
+ # ==== Params
1101
+ # +Array[String]+ +sub_account_ids+:: A list of sub-account ids to freeze
1102
+ def freeze_sub_accounts(
1103
+ sub_account_ids:
1104
+ )
1105
+ post(
1106
+ 'sub-account/freeze',
1107
+ {
1108
+ sub_account_ids: sub_account_ids
1109
+ }
1110
+ )['result']
1111
+ end
1112
+
1113
+ # Activates sub-accounts listed. It would make sub-accounts active after being frozen
1114
+ #
1115
+ # Requires no API key Access Rights
1116
+ #
1117
+ # https://api.exchange.cryptomkt.com/#activate-sub-account
1118
+ #
1119
+ # ==== Params
1120
+ # +Array[String]+ +sub_account_ids+:: A list of sub-account ids to activate
1121
+ def activate_sub_accounts(
1122
+ sub_account_ids:
1123
+ )
1124
+ post(
1125
+ 'sub-account/activate',
1126
+ {
1127
+ sub_account_ids: sub_account_ids
1128
+ }
1129
+ )['result']
1130
+ end
1131
+
1132
+ # Transfers funds from the super-account to a sub-account or from a sub-account to the super-account
1133
+ # and returns the transaction id
1134
+ #
1135
+ # Requires the "Withdraw cryptocurrencies" API key Access Right
1136
+ #
1137
+ # https://api.exchange.cryptomkt.com/#transfer-funds
1138
+ #
1139
+ # ==== Params
1140
+ # +String+ +sub_account_ids+:: id of the sub-account to transfer funds from/to
1141
+ # +String+ +amount+:: amount to transfer
1142
+ # +String+ +currency+:: currency to transfer
1143
+ # +String+ +type+:: Direction of transfer, "to_sub_account" or "from_sub_account"
1144
+ def transfer_funds(
1145
+ sub_account_id:,
1146
+ amount:,
1147
+ currency:,
1148
+ type:
1149
+ )
1150
+ post(
1151
+ 'sub-account/transfer',
1152
+ {
1153
+ sub_account_id: sub_account_id,
1154
+ amount: amount,
1155
+ currency: currency,
1156
+ type: type
1157
+ }
1158
+ )['result']
1159
+ end
1160
+
1161
+ # Returns a list of withdrawal settings for sub-accounts listed
1162
+ #
1163
+ # Requires the "Payment information" API key Access Right
1164
+ #
1165
+ # https://api.exchange.cryptomkt.com/#get-acl-settings
1166
+ #
1167
+ # ==== Params
1168
+ # +Array[String]+ +sub_account_ids+:: A list of sub-account ids to get the acl settings
1169
+
1170
+ def get_acl_settings(
1171
+ sub_account_ids:
1172
+ )
1173
+ get(
1174
+ 'sub-account/acl',
1175
+ {
1176
+ sub_account_ids: sub_account_ids
1177
+ }
1178
+ )['result']
1179
+ end
1180
+
1181
+ # Returns a list of withdrawal settings for sub-accounts listed
1182
+ #
1183
+ # Requires the "Payment information" API key Access Right
1184
+ #
1185
+ # https://api.exchange.cryptomkt.com/#get-acl-settings
1186
+ #
1187
+ # ==== Params
1188
+ # +Array[String]+ +sub_account_ids+:: A list of sub-account ids to get the acl settings
1189
+ # +bool+ +deposit_address_generation_enabled+:: Optional. Enables deposits
1190
+ # +bool+ +withdraw_enabled+:: Optional. Enables withdrawals
1191
+ # +String+ +description+:: Optional. Textual description
1192
+ # +String+ +created_at+:: Optional. ACL creation time
1193
+ # +String+ +updated_at+:: Optional. ACL update time
1194
+
1195
+ def change_acl_settings( # rubocop:disable Metrics/ParameterLists
1196
+ sub_account_ids:, deposit_address_generation_enabled: nil, withdraw_enabled: nil,
1197
+ description: nil, created_at: nil, updated_at: nil
1198
+ )
1199
+ post(
1200
+ 'sub-account/acl',
1201
+ { sub_account_ids: sub_account_ids, deposit_address_generation_enabled: deposit_address_generation_enabled,
1202
+ withdraw_enabled: withdraw_enabled, description: description, created_at: created_at, updated_at: updated_at }
1203
+ )['result']
1204
+ end
1205
+
1206
+ # Returns non-zero balance values by sub-account
1207
+ # Report will include the wallet and Trading balances for each currency
1208
+ # It is functional with no regard to the state of a sub-account
1209
+ #
1210
+ # Requires the "Payment information" API key Access Right
1211
+ #
1212
+ # https://api.exchange.cryptomkt.com/#get-sub-account-balance
1213
+ #
1214
+ # ==== Params
1215
+ # +String+ +sub_account_id+:: The id of the sub-account
1216
+ def get_sub_account_balance(
1217
+ sub_account_id:
1218
+ )
1219
+ get(
1220
+ "sub-account/balance/#{sub_account_id}"
1221
+ )['result']
1222
+ end
1223
+
1224
+ # Returns sub-account crypto address for currency
1225
+ #
1226
+ # Requires the "Payment information" API key Access Right
1227
+ #
1228
+ # https://api.exchange.cryptomkt.com/#get-sub-account-crypto-address
1229
+ #
1230
+ # ==== Params
1231
+ # +String+ +sub_account_id+:: The id of the sub-account
1232
+ # +String+ +currency+:: The currency of the address
1233
+ def get_sub_account_crypto_address(
1234
+ sub_account_id:,
1235
+ currency:
1236
+ )
1237
+ get(
1238
+ "sub-account/crypto/address/#{sub_account_id}/#{currency}"
1239
+ )['result']['address']
1240
+ end
1241
+ end
1242
+ end