cryptomarket-sdk 1.0.1 → 3.0.0

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