Repository navigation
Expand file tree
/
Copy pathliquid.py
More file actions
863 lines (833 loc) · 32.9 KB
/
Copy pathliquid.py
File metadata and controls
863 lines (833 loc) · 32.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
# -*- coding: utf-8 -*-
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
from ccxt.base.exchange import Exchange
import math
from ccxt.base.errors import ExchangeError
from ccxt.base.errors import AuthenticationError
from ccxt.base.errors import ArgumentsRequired
from ccxt.base.errors import InsufficientFunds
from ccxt.base.errors import InvalidOrder
from ccxt.base.errors import OrderNotFound
from ccxt.base.errors import NotSupported
from ccxt.base.errors import DDoSProtection
from ccxt.base.errors import InvalidNonce
class liquid(Exchange):
def describe(self):
return self.deep_extend(super(liquid, self).describe(), {
'id': 'liquid',
'name': 'Liquid',
'countries': ['JP', 'CN', 'TW'],
'version': '2',
'rateLimit': 1000,
'has': {
'CORS': False,
'fetchCurrencies': True,
'fetchTickers': True,
'fetchOrder': True,
'fetchOrders': True,
'fetchOpenOrders': True,
'fetchClosedOrders': True,
'fetchMyTrades': True,
'withdraw': True,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/45798859-1a872600-bcb4-11e8-8746-69291ce87b04.jpg',
'api': 'https://api.liquid.com',
'www': 'https://www.liquid.com',
'doc': [
'https://developers.liquid.com',
],
'fees': 'https://help.liquid.com/getting-started-with-liquid/the-platform/fee-structure',
'referral': 'https://www.liquid.com?affiliate=SbzC62lt30976',
},
'api': {
'public': {
'get': [
'currencies',
'products',
'products/{id}',
'products/{id}/price_levels',
'executions',
'ir_ladders/{currency}',
'fees', # add fetchFees, fetchTradingFees, fetchFundingFees
],
},
'private': {
'get': [
'accounts/balance',
'accounts/main_asset',
'accounts/{id}',
'accounts/{currency}/reserved_balance_details',
'crypto_accounts', # add fetchAccounts
'crypto_withdrawals', # add fetchWithdrawals
'executions/me',
'fiat_accounts', # add fetchAccounts
'fund_infos', # add fetchDeposits
'loan_bids',
'loans',
'orders',
'orders/{id}',
'orders/{id}/trades', # add fetchOrderTrades
'trades',
'trades/{id}/loans',
'trading_accounts',
'trading_accounts/{id}',
'transactions',
'withdrawals', # add fetchWithdrawals
],
'post': [
'crypto_withdrawals',
'fund_infos',
'fiat_accounts',
'loan_bids',
'orders',
'withdrawals',
],
'put': [
'crypto_withdrawal/{id}/cancel',
'loan_bids/{id}/close',
'loans/{id}',
'orders/{id}', # add editOrder
'orders/{id}/cancel',
'trades/{id}',
'trades/{id}/adjust_margin',
'trades/{id}/close',
'trades/close_all',
'trading_accounts/{id}',
'withdrawals/{id}/cancel',
],
},
},
'exceptions': {
'API rate limit exceeded. Please retry after 300s': DDoSProtection,
'API Authentication failed': AuthenticationError,
'Nonce is too small': InvalidNonce,
'Order not found': OrderNotFound,
'Can not update partially filled order': InvalidOrder,
'Can not update non-live order': OrderNotFound,
'not_enough_free_balance': InsufficientFunds,
'must_be_positive': InvalidOrder,
'less_than_order_size': InvalidOrder,
},
'commonCurrencies': {
'WIN': 'WCOIN',
'HOT': 'HOT Token',
},
'options': {
'cancelOrderException': True,
},
})
def fetch_currencies(self, params={}):
response = self.publicGetCurrencies(params)
#
# [
# {
# currency_type: 'fiat',
# currency: 'USD',
# symbol: '$',
# assets_precision: 2,
# quoting_precision: 5,
# minimum_withdrawal: '15.0',
# withdrawal_fee: 5,
# minimum_fee: null,
# minimum_order_quantity: null,
# display_precision: 2,
# depositable: True,
# withdrawable: True,
# discount_fee: 0.5,
# },
# ]
#
result = {}
for i in range(0, len(response)):
currency = response[i]
id = self.safe_string(currency, 'currency')
code = self.safe_currency_code(id)
active = currency['depositable'] and currency['withdrawable']
amountPrecision = self.safe_integer(currency, 'display_precision')
pricePrecision = self.safe_integer(currency, 'quoting_precision')
precision = max(amountPrecision, pricePrecision)
result[code] = {
'id': id,
'code': code,
'info': currency,
'name': code,
'active': active,
'fee': self.safe_float(currency, 'withdrawal_fee'),
'precision': precision,
'limits': {
'amount': {
'min': math.pow(10, -amountPrecision),
'max': math.pow(10, amountPrecision),
},
'price': {
'min': math.pow(10, -pricePrecision),
'max': math.pow(10, pricePrecision),
},
'cost': {
'min': None,
'max': None,
},
'withdraw': {
'min': self.safe_float(currency, 'minimum_withdrawal'),
'max': None,
},
},
}
return result
def fetch_markets(self, params={}):
markets = self.publicGetProducts()
#
# [
# {
# id: '7',
# product_type: 'CurrencyPair',
# code: 'CASH',
# name: ' CASH Trading',
# market_ask: 8865.79147,
# market_bid: 8853.95988,
# indicator: 1,
# currency: 'SGD',
# currency_pair_code: 'BTCSGD',
# symbol: 'S$',
# btc_minimum_withdraw: null,
# fiat_minimum_withdraw: null,
# pusher_channel: 'product_cash_btcsgd_7',
# taker_fee: 0,
# maker_fee: 0,
# low_market_bid: '8803.25579',
# high_market_ask: '8905.0',
# volume_24h: '15.85443468',
# last_price_24h: '8807.54625',
# last_traded_price: '8857.77206',
# last_traded_quantity: '0.00590974',
# quoted_currency: 'SGD',
# base_currency: 'BTC',
# disabled: False,
# },
# ]
#
currencies = self.fetch_currencies()
currenciesByCode = self.index_by(currencies, 'code')
result = []
for i in range(0, len(markets)):
market = markets[i]
id = str(market['id'])
baseId = market['base_currency']
quoteId = market['quoted_currency']
base = self.safe_currency_code(baseId)
quote = self.safe_currency_code(quoteId)
symbol = base + '/' + quote
maker = self.safe_float(market, 'maker_fee')
taker = self.safe_float(market, 'taker_fee')
active = not market['disabled']
baseCurrency = self.safe_value(currenciesByCode, base)
quoteCurrency = self.safe_value(currenciesByCode, quote)
precision = {
'amount': 8,
'price': 8,
}
minAmount = None
if baseCurrency is not None:
minAmount = self.safe_float(baseCurrency['info'], 'minimum_order_quantity')
# precision['amount'] = self.safe_integer(baseCurrency['info'], 'quoting_precision')
minPrice = None
if quoteCurrency is not None:
precision['price'] = self.safe_integer(quoteCurrency['info'], 'quoting_precision')
minPrice = math.pow(10, -precision['price'])
minCost = None
if minPrice is not None:
if minAmount is not None:
minCost = minPrice * minAmount
limits = {
'amount': {
'min': minAmount,
'max': None,
},
'price': {
'min': minPrice,
'max': None,
},
'cost': {
'min': minCost,
'max': None,
},
}
result.append({
'id': id,
'symbol': symbol,
'base': base,
'quote': quote,
'baseId': baseId,
'quoteId': quoteId,
'maker': maker,
'taker': taker,
'limits': limits,
'precision': precision,
'active': active,
'info': market,
})
return result
def fetch_balance(self, params={}):
self.load_markets()
response = self.privateGetAccountsBalance(params)
#
# [
# {"currency":"USD","balance":"0.0"},
# {"currency":"BTC","balance":"0.0"},
# {"currency":"ETH","balance":"0.1651354"}
# ]
#
result = {'info': response}
for i in range(0, len(response)):
balance = response[i]
currencyId = self.safe_string(balance, 'currency')
code = self.safe_currency_code(currencyId)
account = self.account()
account['total'] = self.safe_float(balance, 'balance')
result[code] = account
return self.parse_balance(result)
def fetch_order_book(self, symbol, limit=None, params={}):
self.load_markets()
request = {
'id': self.market_id(symbol),
}
response = self.publicGetProductsIdPriceLevels(self.extend(request, params))
return self.parse_order_book(response, None, 'buy_price_levels', 'sell_price_levels')
def parse_ticker(self, ticker, market=None):
timestamp = self.milliseconds()
last = None
if 'last_traded_price' in ticker:
if ticker['last_traded_price']:
length = len(ticker['last_traded_price'])
if length > 0:
last = self.safe_float(ticker, 'last_traded_price')
symbol = None
if market is None:
marketId = self.safe_string(ticker, 'id')
if marketId in self.markets_by_id:
market = self.markets_by_id[marketId]
else:
baseId = self.safe_string(ticker, 'base_currency')
quoteId = self.safe_string(ticker, 'quoted_currency')
if symbol in self.markets:
market = self.markets[symbol]
else:
symbol = self.safe_currency_code(baseId) + '/' + self.safe_currency_code(quoteId)
if market is not None:
symbol = market['symbol']
change = None
percentage = None
average = None
open = self.safe_float(ticker, 'last_price_24h')
if open is not None and last is not None:
change = last - open
average = self.sum(last, open) / 2
if open > 0:
percentage = change / open * 100
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'high': self.safe_float(ticker, 'high_market_ask'),
'low': self.safe_float(ticker, 'low_market_bid'),
'bid': self.safe_float(ticker, 'market_bid'),
'bidVolume': None,
'ask': self.safe_float(ticker, 'market_ask'),
'askVolume': None,
'vwap': None,
'open': open,
'close': last,
'last': last,
'previousClose': None,
'change': change,
'percentage': percentage,
'average': average,
'baseVolume': self.safe_float(ticker, 'volume_24h'),
'quoteVolume': None,
'info': ticker,
}
def fetch_tickers(self, symbols=None, params={}):
self.load_markets()
response = self.publicGetProducts(params)
result = {}
for i in range(0, len(response)):
ticker = self.parse_ticker(response[i])
symbol = ticker['symbol']
result[symbol] = ticker
return result
def fetch_ticker(self, symbol, params={}):
self.load_markets()
market = self.market(symbol)
request = {
'id': market['id'],
}
response = self.publicGetProductsId(self.extend(request, params))
return self.parse_ticker(response, market)
def parse_trade(self, trade, market):
# { id: 12345,
# quantity: "6.789",
# price: "98765.4321",
# taker_side: "sell",
# created_at: 1512345678,
# my_side: "buy" }
timestamp = self.safe_timestamp(trade, 'created_at')
orderId = self.safe_string(trade, 'order_id')
# 'taker_side' gets filled for both fetchTrades and fetchMyTrades
takerSide = self.safe_string(trade, 'taker_side')
# 'my_side' gets filled for fetchMyTrades only and may differ from 'taker_side'
mySide = self.safe_string(trade, 'my_side')
side = mySide if (mySide is not None) else takerSide
takerOrMaker = None
if mySide is not None:
takerOrMaker = 'taker' if (takerSide == mySide) else 'maker'
cost = None
price = self.safe_float(trade, 'price')
amount = self.safe_float(trade, 'quantity')
if price is not None:
if amount is not None:
cost = price * amount
id = self.safe_string(trade, 'id')
return {
'info': trade,
'id': id,
'order': orderId,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'symbol': market['symbol'],
'type': None,
'side': side,
'takerOrMaker': takerOrMaker,
'price': price,
'amount': amount,
'cost': cost,
'fee': None,
}
def fetch_trades(self, symbol, since=None, limit=None, params={}):
self.load_markets()
market = self.market(symbol)
request = {
'product_id': market['id'],
}
if limit is not None:
request['limit'] = limit
if since is not None:
# timestamp should be in seconds, whereas we use milliseconds in since and everywhere
request['timestamp'] = int(since / 1000)
response = self.publicGetExecutions(self.extend(request, params))
result = response if (since is not None) else response['models']
return self.parse_trades(result, market, since, limit)
def fetch_my_trades(self, symbol=None, since=None, limit=None, params={}):
self.load_markets()
market = self.market(symbol)
# the `with_details` param is undocumented - it adds the order_id to the results
request = {
'product_id': market['id'],
'with_details': True,
}
if limit is not None:
request['limit'] = limit
response = self.privateGetExecutionsMe(self.extend(request, params))
return self.parse_trades(response['models'], market, since, limit)
def create_order(self, symbol, type, side, amount, price=None, params={}):
self.load_markets()
request = {
'order_type': type,
'product_id': self.market_id(symbol),
'side': side,
'quantity': self.amount_to_precision(symbol, amount),
}
if type == 'limit':
request['price'] = self.price_to_precision(symbol, price)
response = self.privatePostOrders(self.extend(request, params))
#
# {
# "id": 2157474,
# "order_type": "limit",
# "quantity": "0.01",
# "disc_quantity": "0.0",
# "iceberg_total_quantity": "0.0",
# "side": "sell",
# "filled_quantity": "0.0",
# "price": "500.0",
# "created_at": 1462123639,
# "updated_at": 1462123639,
# "status": "live",
# "leverage_level": 1,
# "source_exchange": "QUOINE",
# "product_id": 1,
# "product_code": "CASH",
# "funding_currency": "USD",
# "currency_pair_code": "BTCUSD",
# "order_fee": "0.0"
# }
#
return self.parse_order(response)
def cancel_order(self, id, symbol=None, params={}):
self.load_markets()
request = {
'id': id,
}
response = self.privatePutOrdersIdCancel(self.extend(request, params))
order = self.parse_order(response)
if order['status'] == 'closed':
if self.options['cancelOrderException']:
raise OrderNotFound(self.id + ' order closed already: ' + self.json(response))
return order
def edit_order(self, id, symbol, type, side, amount, price=None, params={}):
self.load_markets()
if price is None:
raise ArgumentsRequired(self.id + ' editOrder requires the price argument')
request = {
'order': {
'quantity': self.amount_to_precision(symbol, amount),
'price': self.price_to_precision(symbol, price),
},
'id': id,
}
response = self.privatePutOrdersId(self.extend(request, params))
return self.parse_order(response)
def parse_order_status(self, status):
statuses = {
'live': 'open',
'filled': 'closed',
'cancelled': 'canceled',
}
return self.safe_string(statuses, status, status)
def parse_order(self, order, market=None):
#
# createOrder
#
# {
# "id": 2157474,
# "order_type": "limit",
# "quantity": "0.01",
# "disc_quantity": "0.0",
# "iceberg_total_quantity": "0.0",
# "side": "sell",
# "filled_quantity": "0.0",
# "price": "500.0",
# "created_at": 1462123639,
# "updated_at": 1462123639,
# "status": "live",
# "leverage_level": 1,
# "source_exchange": "QUOINE",
# "product_id": 1,
# "product_code": "CASH",
# "funding_currency": "USD",
# "currency_pair_code": "BTCUSD",
# "order_fee": "0.0"
# }
#
# fetchOrder, fetchOrders, fetchOpenOrders, fetchClosedOrders
#
# {
# "id": 2157479,
# "order_type": "limit",
# "quantity": "0.01",
# "disc_quantity": "0.0",
# "iceberg_total_quantity": "0.0",
# "side": "sell",
# "filled_quantity": "0.01",
# "price": "500.0",
# "created_at": 1462123639,
# "updated_at": 1462123639,
# "status": "filled",
# "leverage_level": 2,
# "source_exchange": "QUOINE",
# "product_id": 1,
# "product_code": "CASH",
# "funding_currency": "USD",
# "currency_pair_code": "BTCUSD",
# "order_fee": "0.0",
# "executions": [
# {
# "id": 4566133,
# "quantity": "0.01",
# "price": "500.0",
# "taker_side": "buy",
# "my_side": "sell",
# "created_at": 1465396785
# }
# ]
# }
#
orderId = self.safe_string(order, 'id')
timestamp = self.safe_timestamp(order, 'created_at')
marketId = self.safe_string(order, 'product_id')
market = self.safe_value(self.markets_by_id, marketId)
status = self.parse_order_status(self.safe_string(order, 'status'))
amount = self.safe_float(order, 'quantity')
filled = self.safe_float(order, 'filled_quantity')
price = self.safe_float(order, 'price')
symbol = None
feeCurrency = None
if market is not None:
symbol = market['symbol']
feeCurrency = market['quote']
type = self.safe_string(order, 'order_type')
tradeCost = 0
tradeFilled = 0
average = self.safe_float(order, 'average_price')
trades = self.parse_trades(self.safe_value(order, 'executions', []), market, None, None, {
'order': orderId,
'type': type,
})
numTrades = len(trades)
for i in range(0, numTrades):
# php copies values upon assignment, but not references them
# todo rewrite self(shortly)
trade = trades[i]
trade['order'] = orderId
trade['type'] = type
tradeFilled = self.sum(tradeFilled, trade['amount'])
tradeCost = self.sum(tradeCost, trade['cost'])
cost = None
lastTradeTimestamp = None
if numTrades > 0:
lastTradeTimestamp = trades[numTrades - 1]['timestamp']
if not average and (tradeFilled > 0):
average = tradeCost / tradeFilled
if cost is None:
cost = tradeCost
if filled is None:
filled = tradeFilled
remaining = None
if amount is not None and filled is not None:
remaining = amount - filled
side = self.safe_string(order, 'side')
return {
'id': orderId,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'lastTradeTimestamp': lastTradeTimestamp,
'type': type,
'status': status,
'symbol': symbol,
'side': side,
'price': price,
'amount': amount,
'filled': filled,
'cost': cost,
'remaining': remaining,
'average': average,
'trades': trades,
'fee': {
'currency': feeCurrency,
'cost': self.safe_float(order, 'order_fee'),
},
'info': order,
}
def fetch_order(self, id, symbol=None, params={}):
self.load_markets()
request = {
'id': id,
}
response = self.privateGetOrdersId(self.extend(request, params))
return self.parse_order(response)
def fetch_orders(self, symbol=None, since=None, limit=None, params={}):
self.load_markets()
market = None
request = {
# 'funding_currency': market['quoteId'], # filter orders based on "funding" currency(quote currency)
# 'product_id': market['id'],
# 'status': 'live', # 'filled', 'cancelled'
# 'trading_type': 'spot', # 'margin', 'cfd'
'with_details': 1, # return full order details including executions
}
if symbol is not None:
market = self.market(symbol)
request['product_id'] = market['id']
if limit is not None:
request['limit'] = limit
response = self.privateGetOrders(self.extend(request, params))
#
# {
# "models": [
# {
# "id": 2157474,
# "order_type": "limit",
# "quantity": "0.01",
# "disc_quantity": "0.0",
# "iceberg_total_quantity": "0.0",
# "side": "sell",
# "filled_quantity": "0.0",
# "price": "500.0",
# "created_at": 1462123639,
# "updated_at": 1462123639,
# "status": "live",
# "leverage_level": 1,
# "source_exchange": "QUOINE",
# "product_id": 1,
# "product_code": "CASH",
# "funding_currency": "USD",
# "currency_pair_code": "BTCUSD",
# "order_fee": "0.0",
# "executions": [], # optional
# }
# ],
# "current_page": 1,
# "total_pages": 1
# }
#
orders = self.safe_value(response, 'models', [])
return self.parse_orders(orders, market, since, limit)
def fetch_open_orders(self, symbol=None, since=None, limit=None, params={}):
request = {'status': 'live'}
return self.fetch_orders(symbol, since, limit, self.extend(request, params))
def fetch_closed_orders(self, symbol=None, since=None, limit=None, params={}):
request = {'status': 'filled'}
return self.fetch_orders(symbol, since, limit, self.extend(request, params))
def withdraw(self, code, amount, address, tag=None, params={}):
self.check_address(address)
self.load_markets()
currency = self.currency(code)
request = {
# 'auth_code': '', # optional 2fa code
'currency': currency['id'],
'address': address,
'amount': self.currency_to_precision(code, amount),
# 'payment_id': tag, # for XRP only
# 'memo_type': 'text', # 'text', 'id' or 'hash', for XLM only
# 'memo_value': tag, # for XLM only
}
if tag is not None:
if code == 'XRP':
request['payment_id'] = tag
elif code == 'XLM':
request['memo_type'] = 'text' # overrideable via params
request['memo_value'] = tag
else:
raise NotSupported(self.id + ' withdraw() only supports a tag along the address for XRP or XLM')
response = self.privatePostCryptoWithdrawals(self.extend(request, params))
#
# {
# "id": 1353,
# "address": "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2",
# "amount": 1.0,
# "state": "pending",
# "currency": "BTC",
# "withdrawal_fee": 0.0,
# "created_at": 1568016450,
# "updated_at": 1568016450,
# "payment_id": null
# }
#
return self.parse_transaction(response, currency)
def parse_transaction_status(self, status):
statuses = {
'pending': 'pending',
'cancelled': 'canceled',
'approved': 'ok',
}
return self.safe_string(statuses, status, status)
def parse_transaction(self, transaction, currency=None):
#
# withdraw
#
# {
# "id": 1353,
# "address": "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2",
# "amount": 1.0,
# "state": "pending",
# "currency": "BTC",
# "withdrawal_fee": 0.0,
# "created_at": 1568016450,
# "updated_at": 1568016450,
# "payment_id": null
# }
#
# fetchDeposits, fetchWithdrawals
#
# ...
#
id = self.safe_string(transaction, 'id')
address = self.safe_string(transaction, 'address')
tag = self.safe_string_2(transaction, 'payment_id', 'memo_value')
txid = None
currencyId = self.safe_string(transaction, 'asset')
code = self.safe_currency_code(currencyId, currency)
timestamp = self.safe_timestamp(transaction, 'created_at')
updated = self.safe_timestamp(transaction, 'updated_at')
type = 'withdrawal'
status = self.parse_transaction_status(self.safe_string(transaction, 'state'))
amount = self.safe_float(transaction, 'amount')
return {
'info': transaction,
'id': id,
'txid': txid,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'address': address,
'tag': tag,
'type': type,
'amount': amount,
'currency': code,
'status': status,
'updated': updated,
'fee': None,
}
def nonce(self):
return self.milliseconds()
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
url = '/' + self.implode_params(path, params)
query = self.omit(params, self.extract_params(path))
headers = {
'X-Quoine-API-Version': self.version,
'Content-Type': 'application/json',
}
if api == 'private':
self.check_required_credentials()
if method == 'GET':
if query:
url += '?' + self.urlencode(query)
elif query:
body = self.json(query)
nonce = self.nonce()
request = {
'path': url,
'nonce': nonce,
'token_id': self.apiKey,
'iat': int(math.floor(nonce / 1000)), # issued at
}
headers['X-Quoine-Auth'] = self.jwt(request, self.encode(self.secret))
else:
if query:
url += '?' + self.urlencode(query)
url = self.urls['api'] + url
return {'url': url, 'method': method, 'body': body, 'headers': headers}
def handle_errors(self, code, reason, url, method, headers, body, response, requestHeaders, requestBody):
if code >= 200 and code < 300:
return
if code == 401:
# expected non-json response
self.throw_exactly_matched_exception(self.exceptions, body, body)
return
if code == 429:
raise DDoSProtection(self.id + ' ' + body)
if response is None:
return
feedback = self.id + ' ' + body
message = self.safe_string(response, 'message')
errors = self.safe_value(response, 'errors')
if message is not None:
#
# {"message": "Order not found"}
#
self.throw_exactly_matched_exception(self.exceptions, message, feedback)
elif errors is not None:
#
# {"errors": {"user": ["not_enough_free_balance"]}}
# {"errors": {"quantity": ["less_than_order_size"]}}
# {"errors": {"order": ["Can not update partially filled order"]}}
#
types = list(errors.keys())
for i in range(0, len(types)):
type = types[i]
errorMessages = errors[type]
for j in range(0, len(errorMessages)):
message = errorMessages[j]
self.throw_exactly_matched_exception(self.exceptions, message, feedback)
else:
raise ExchangeError(feedback)