ccxt 4.4.64__py2.py3-none-any.whl → 4.4.68__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. ccxt/__init__.py +5 -3
  2. ccxt/abstract/cryptomus.py +20 -0
  3. ccxt/abstract/derive.py +117 -0
  4. ccxt/abstract/tradeogre.py +1 -0
  5. ccxt/abstract/whitebit.py +16 -0
  6. ccxt/async_support/__init__.py +5 -3
  7. ccxt/async_support/base/exchange.py +6 -5
  8. ccxt/async_support/binance.py +5 -3
  9. ccxt/async_support/bitget.py +22 -12
  10. ccxt/async_support/bitrue.py +6 -3
  11. ccxt/async_support/bybit.py +1 -1
  12. ccxt/async_support/coinbase.py +73 -2
  13. ccxt/async_support/cryptocom.py +2 -0
  14. ccxt/async_support/cryptomus.py +1041 -0
  15. ccxt/async_support/derive.py +2530 -0
  16. ccxt/async_support/gate.py +5 -1
  17. ccxt/async_support/htx.py +19 -5
  18. ccxt/async_support/hyperliquid.py +108 -68
  19. ccxt/async_support/luno.py +113 -1
  20. ccxt/async_support/paradex.py +51 -12
  21. ccxt/async_support/tradeogre.py +132 -13
  22. ccxt/async_support/whitebit.py +276 -2
  23. ccxt/base/errors.py +0 -6
  24. ccxt/base/exchange.py +13 -4
  25. ccxt/binance.py +5 -3
  26. ccxt/bitget.py +22 -12
  27. ccxt/bitrue.py +6 -3
  28. ccxt/bybit.py +1 -1
  29. ccxt/coinbase.py +73 -2
  30. ccxt/cryptocom.py +2 -0
  31. ccxt/cryptomus.py +1041 -0
  32. ccxt/derive.py +2529 -0
  33. ccxt/gate.py +5 -1
  34. ccxt/htx.py +19 -5
  35. ccxt/hyperliquid.py +108 -68
  36. ccxt/luno.py +113 -1
  37. ccxt/paradex.py +51 -12
  38. ccxt/pro/__init__.py +3 -3
  39. ccxt/pro/bybit.py +3 -2
  40. ccxt/pro/derive.py +704 -0
  41. ccxt/pro/gate.py +5 -2
  42. ccxt/pro/hyperliquid.py +3 -3
  43. ccxt/test/tests_async.py +36 -3
  44. ccxt/test/tests_sync.py +36 -3
  45. ccxt/tradeogre.py +132 -13
  46. ccxt/whitebit.py +276 -2
  47. {ccxt-4.4.64.dist-info → ccxt-4.4.68.dist-info}/METADATA +16 -12
  48. {ccxt-4.4.64.dist-info → ccxt-4.4.68.dist-info}/RECORD +51 -48
  49. ccxt/abstract/currencycom.py +0 -68
  50. ccxt/async_support/currencycom.py +0 -2070
  51. ccxt/currencycom.py +0 -2070
  52. ccxt/pro/currencycom.py +0 -536
  53. {ccxt-4.4.64.dist-info → ccxt-4.4.68.dist-info}/LICENSE.txt +0 -0
  54. {ccxt-4.4.64.dist-info → ccxt-4.4.68.dist-info}/WHEEL +0 -0
  55. {ccxt-4.4.64.dist-info → ccxt-4.4.68.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1041 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ # https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+
6
+ from ccxt.async_support.base.exchange import Exchange
7
+ from ccxt.abstract.cryptomus import ImplicitAPI
8
+ from ccxt.base.types import Any, Balances, Currencies, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade
9
+ from typing import List
10
+ from ccxt.base.errors import ExchangeError
11
+ from ccxt.base.errors import ArgumentsRequired
12
+ from ccxt.base.errors import InsufficientFunds
13
+ from ccxt.base.errors import InvalidOrder
14
+ from ccxt.base.decimal_to_precision import TICK_SIZE
15
+ from ccxt.base.precise import Precise
16
+
17
+
18
+ class cryptomus(Exchange, ImplicitAPI):
19
+
20
+ def describe(self) -> Any:
21
+ return self.deep_extend(super(cryptomus, self).describe(), {
22
+ 'id': 'cryptomus',
23
+ 'name': 'Cryptomus',
24
+ 'countries': ['CA'],
25
+ 'rateLimit': 100, # todo check
26
+ 'version': 'v1',
27
+ 'certified': False,
28
+ 'pro': False,
29
+ 'has': {
30
+ 'CORS': None,
31
+ 'spot': True,
32
+ 'margin': False,
33
+ 'swap': False,
34
+ 'future': False,
35
+ 'option': False,
36
+ 'addMargin': False,
37
+ 'cancelAllOrders': False,
38
+ 'cancelAllOrdersAfter': False,
39
+ 'cancelOrder': True,
40
+ 'cancelOrders': False,
41
+ 'cancelWithdraw': False,
42
+ 'closePosition': False,
43
+ 'createConvertTrade': False,
44
+ 'createDepositAddress': False,
45
+ 'createMarketBuyOrderWithCost': False,
46
+ 'createMarketOrder': False,
47
+ 'createMarketOrderWithCost': False,
48
+ 'createMarketSellOrderWithCost': False,
49
+ 'createOrder': True,
50
+ 'createOrderWithTakeProfitAndStopLoss': False,
51
+ 'createReduceOnlyOrder': False,
52
+ 'createStopLimitOrder': False,
53
+ 'createStopLossOrder': False,
54
+ 'createStopMarketOrder': False,
55
+ 'createStopOrder': False,
56
+ 'createTakeProfitOrder': False,
57
+ 'createTrailingAmountOrder': False,
58
+ 'createTrailingPercentOrder': False,
59
+ 'createTriggerOrder': False,
60
+ 'fetchAccounts': False,
61
+ 'fetchBalance': True,
62
+ 'fetchCanceledAndClosedOrders': True,
63
+ 'fetchCanceledOrders': False,
64
+ 'fetchClosedOrder': False,
65
+ 'fetchClosedOrders': False,
66
+ 'fetchConvertCurrencies': False,
67
+ 'fetchConvertQuote': False,
68
+ 'fetchConvertTrade': False,
69
+ 'fetchConvertTradeHistory': False,
70
+ 'fetchCurrencies': True,
71
+ 'fetchDepositAddress': False,
72
+ 'fetchDeposits': False,
73
+ 'fetchDepositsWithdrawals': False,
74
+ 'fetchFundingHistory': False,
75
+ 'fetchFundingRate': False,
76
+ 'fetchFundingRateHistory': False,
77
+ 'fetchFundingRates': False,
78
+ 'fetchIndexOHLCV': False,
79
+ 'fetchLedger': False,
80
+ 'fetchLeverage': False,
81
+ 'fetchLeverageTiers': False,
82
+ 'fetchMarginAdjustmentHistory': False,
83
+ 'fetchMarginMode': False,
84
+ 'fetchMarkets': True,
85
+ 'fetchMarkOHLCV': False,
86
+ 'fetchMyTrades': False,
87
+ 'fetchOHLCV': False,
88
+ 'fetchOpenInterestHistory': False,
89
+ 'fetchOpenOrder': False,
90
+ 'fetchOpenOrders': True,
91
+ 'fetchOrder': True,
92
+ 'fetchOrderBook': True,
93
+ 'fetchOrders': False,
94
+ 'fetchOrderTrades': False,
95
+ 'fetchPosition': False,
96
+ 'fetchPositionHistory': False,
97
+ 'fetchPositionMode': False,
98
+ 'fetchPositions': False,
99
+ 'fetchPositionsForSymbol': False,
100
+ 'fetchPositionsHistory': False,
101
+ 'fetchPremiumIndexOHLCV': False,
102
+ 'fetchStatus': False,
103
+ 'fetchTicker': False,
104
+ 'fetchTickers': True,
105
+ 'fetchTime': False,
106
+ 'fetchTrades': True,
107
+ 'fetchTradingFee': False,
108
+ 'fetchTradingFees': False,
109
+ 'fetchTransactions': False,
110
+ 'fetchTransfers': False,
111
+ 'fetchWithdrawals': False,
112
+ 'reduceMargin': False,
113
+ 'sandbox': False,
114
+ 'setLeverage': False,
115
+ 'setMargin': False,
116
+ 'setPositionMode': False,
117
+ 'transfer': False,
118
+ 'withdraw': False,
119
+ },
120
+ 'timeframes': {},
121
+ 'urls': {
122
+ 'logo': 'https://github.com/user-attachments/assets/8e0b1c48-7c01-4177-9224-f1b01d89d7e7',
123
+ 'api': {
124
+ 'public': 'https://api.cryptomus.com',
125
+ 'private': 'https://api.cryptomus.com',
126
+ },
127
+ 'www': 'https://cryptomus.com',
128
+ 'doc': 'https://doc.cryptomus.com/personal',
129
+ 'fees': 'https://cryptomus.com/tariffs', # todo check
130
+ 'referral': 'https://app.cryptomus.com/signup/?ref=JRP4yj', # todo
131
+ },
132
+ 'api': {
133
+ 'public': {
134
+ 'get': {
135
+ 'v2/user-api/exchange/markets': 1, # done
136
+ 'v2/user-api/exchange/market/price': 1, # not used
137
+ 'v1/exchange/market/assets': 1, # done
138
+ 'v1/exchange/market/order-book/{currencyPair}': 1, # done
139
+ 'v1/exchange/market/tickers': 1, # done
140
+ 'v1/exchange/market/trades/{currencyPair}': 1, # done
141
+ },
142
+ },
143
+ 'private': {
144
+ 'get': {
145
+ 'v2/user-api/exchange/orders': 1, # done
146
+ 'v2/user-api/exchange/orders/history': 1,
147
+ 'v2/user-api/exchange/account/balance': 1, # done
148
+ 'v2/user-api/exchange/account/tariffs': 1,
149
+ 'v2/user-api/payment/services': 1,
150
+ 'v2/user-api/payout/services': 1,
151
+ 'v2/user-api/transaction/list': 1,
152
+ },
153
+ 'post': {
154
+ 'v2/user-api/exchange/orders': 1, # done
155
+ 'v2/user-api/exchange/orders/market': 1, # done
156
+ },
157
+ 'delete': {
158
+ 'v2/user-api/exchange/orders/{orderId}': 1, # done
159
+ },
160
+ },
161
+ },
162
+ 'fees': {
163
+ 'trading': {
164
+ 'percentage': True,
165
+ 'feeSide': 'get',
166
+ 'maker': self.parse_number('0.02'),
167
+ 'taker': self.parse_number('0.02'),
168
+ },
169
+ },
170
+ 'options': {
171
+ 'createMarketBuyOrderRequiresPrice': True,
172
+ 'networks': {
173
+ 'BEP20': 'bsc',
174
+ 'DASH': 'dash',
175
+ 'POLYGON': 'polygon',
176
+ 'ARB': 'arbitrum',
177
+ 'SOL': 'sol',
178
+ 'TON': 'ton',
179
+ 'ERC20': 'eth',
180
+ 'TRC20': 'tron',
181
+ 'LTC': 'ltc',
182
+ 'XMR': 'xmr',
183
+ 'BCH': 'bch',
184
+ 'DOGE': 'doge',
185
+ 'AVAX': 'avalanche',
186
+ 'BTC': 'btc',
187
+ 'RUB': 'rub',
188
+ },
189
+ 'networksById': {
190
+ 'bsc': 'BEP20',
191
+ 'dash': 'DASH',
192
+ 'polygon': 'POLYGON',
193
+ 'arbitrum': 'ARB',
194
+ 'sol': 'SOL',
195
+ 'ton': 'TON',
196
+ 'eth': 'ERC20',
197
+ 'tron': 'TRC20',
198
+ 'ltc': 'LTC',
199
+ 'xmr': 'XMR',
200
+ 'bch': 'BCH',
201
+ 'doge': 'DOGE',
202
+ 'avalanche': 'AVAX',
203
+ 'btc': 'BTC',
204
+ 'rub': 'RUB',
205
+ },
206
+ 'fetchOrderBook': {
207
+ 'level': 0, # 0, 1, 2, 4 or 5
208
+ },
209
+ },
210
+ 'commonCurrencies': {},
211
+ 'exceptions': {
212
+ 'exact': {
213
+ '500': ExchangeError,
214
+ '6': InsufficientFunds, # {"code":6,"message":"Insufficient funds."}
215
+ 'Insufficient funds.': InsufficientFunds,
216
+ 'Minimum amount 15 USDT': InvalidOrder,
217
+ # {"code":500,"message":"Server error."}
218
+ # {"message":"Minimum amount 15 USDT","state":1}
219
+ # {"message":"Insufficient funds. USDT wallet balance is 35.21617400.","state":1}
220
+ },
221
+ 'broad': {},
222
+ },
223
+ 'precisionMode': TICK_SIZE,
224
+ 'requiredCredentials': {
225
+ 'apiKey': False,
226
+ 'uid': True,
227
+ },
228
+ 'features': {},
229
+ })
230
+
231
+ async def fetch_markets(self, params={}) -> List[Market]:
232
+ """
233
+ retrieves data on all markets for the exchange
234
+ https://doc.cryptomus.com/personal/market-cap/tickers
235
+ :param dict [params]: extra parameters specific to the exchange API endpoint
236
+ :returns dict[]: an array of objects representing market data
237
+ """
238
+ response = await self.publicGetV2UserApiExchangeMarkets(params)
239
+ #
240
+ # {
241
+ # "result": [
242
+ # {
243
+ # "id": "01JHN5EFT64YC4HR9KCGM5M65D",
244
+ # "symbol": "POL_USDT",
245
+ # "baseCurrency": "POL",
246
+ # "quoteCurrency": "USDT",
247
+ # "baseMinSize": "1.00000000",
248
+ # "quoteMinSize": "5.00000000",
249
+ # "baseMaxSize": "50000.00000000",
250
+ # "quoteMaxSize": "10000000000.00000000",
251
+ # "basePrec": "1",
252
+ # "quotePrec": "4"
253
+ # },
254
+ # ...
255
+ # ]
256
+ # }
257
+ #
258
+ result = self.safe_list(response, 'result', [])
259
+ return self.parse_markets(result)
260
+
261
+ def parse_market(self, market: dict) -> Market:
262
+ #
263
+ # {
264
+ # "id": "01JHN5EFT64YC4HR9KCGM5M65D",
265
+ # "symbol": "POL_USDT",
266
+ # "baseCurrency": "POL",
267
+ # "quoteCurrency": "USDT",
268
+ # "baseMinSize": "1.00000000",
269
+ # "quoteMinSize": "5.00000000",
270
+ # "baseMaxSize": "50000.00000000",
271
+ # "quoteMaxSize": "10000000000.00000000",
272
+ # "basePrec": "1",
273
+ # "quotePrec": "4"
274
+ # }
275
+ #
276
+ marketId = self.safe_string(market, 'symbol')
277
+ parts = marketId.split('_')
278
+ baseId = parts[0]
279
+ quoteId = parts[1]
280
+ base = self.safe_currency_code(baseId)
281
+ quote = self.safe_currency_code(quoteId)
282
+ fees = self.safe_dict(self.fees, 'trading')
283
+ return self.safe_market_structure({
284
+ 'id': marketId,
285
+ 'symbol': base + '/' + quote,
286
+ 'base': base,
287
+ 'quote': quote,
288
+ 'baseId': baseId,
289
+ 'quoteId': quoteId,
290
+ 'active': True,
291
+ 'type': 'spot',
292
+ 'subType': None,
293
+ 'spot': True,
294
+ 'margin': False,
295
+ 'swap': False,
296
+ 'future': False,
297
+ 'option': False,
298
+ 'contract': False,
299
+ 'settle': None,
300
+ 'settleId': None,
301
+ 'contractSize': None,
302
+ 'linear': None,
303
+ 'inverse': None,
304
+ 'taker': self.safe_number(fees, 'taker'),
305
+ 'maker': self.safe_number(fees, 'maker'),
306
+ 'percentage': self.safe_bool(fees, 'percentage'),
307
+ 'tierBased': None,
308
+ 'feeSide': self.safe_string(fees, 'feeSide'),
309
+ 'expiry': None,
310
+ 'expiryDatetime': None,
311
+ 'strike': None,
312
+ 'optionType': None,
313
+ 'precision': {
314
+ 'amount': self.parse_number(self.parse_precision(self.safe_string(market, 'quotePrec'))),
315
+ 'price': self.parse_number(self.parse_precision(self.safe_string(market, 'basePrec'))),
316
+ },
317
+ 'limits': {
318
+ 'amount': {
319
+ 'min': self.safe_number(market, 'quoteMinSize'),
320
+ 'max': self.safe_number(market, 'quoteMaxSize'),
321
+ },
322
+ 'price': {
323
+ 'min': self.safe_number(market, 'baseMinSize'),
324
+ 'max': self.safe_number(market, 'baseMaxSize'),
325
+ },
326
+ 'leverage': {
327
+ 'min': None,
328
+ 'max': None,
329
+ },
330
+ 'cost': {
331
+ 'min': None,
332
+ 'max': None,
333
+ },
334
+ },
335
+ 'created': None,
336
+ 'info': market,
337
+ })
338
+
339
+ async def fetch_currencies(self, params={}) -> Currencies:
340
+ """
341
+ fetches all available currencies on an exchange
342
+ https://doc.cryptomus.com/personal/market-cap/assets
343
+ :param dict [params]: extra parameters specific to the exchange API endpoint
344
+ :returns dict: an associative dictionary of currencies
345
+ """
346
+ response = await self.publicGetV1ExchangeMarketAssets(params)
347
+ #
348
+ # {
349
+ # 'state': '0',
350
+ # 'result': [
351
+ # {
352
+ # 'currency_code': 'USDC',
353
+ # 'network_code': 'bsc',
354
+ # 'can_withdraw': True,
355
+ # 'can_deposit': True,
356
+ # 'min_withdraw': '1.00000000',
357
+ # 'max_withdraw': '10000000.00000000',
358
+ # 'max_deposit': '10000000.00000000',
359
+ # 'min_deposit': '1.00000000'
360
+ # },
361
+ # ...
362
+ # ]
363
+ # }
364
+ #
365
+ coins = self.safe_list(response, 'result')
366
+ result: dict = {}
367
+ for i in range(0, len(coins)):
368
+ currency = coins[i]
369
+ currencyId = self.safe_string(currency, 'currency_code')
370
+ code = self.safe_currency_code(currencyId)
371
+ allowWithdraw = self.safe_bool(currency, 'can_withdraw')
372
+ allowDeposit = self.safe_bool(currency, 'can_deposit')
373
+ isActive = allowWithdraw and allowDeposit
374
+ networkId = self.safe_string(currency, 'network_code')
375
+ networksById = self.safe_dict(self.options, 'networksById')
376
+ networkName = self.safe_string(networksById, networkId, networkId)
377
+ minWithdraw = self.safe_number(currency, 'min_withdraw')
378
+ maxWithdraw = self.safe_number(currency, 'max_withdraw')
379
+ minDeposit = self.safe_number(currency, 'min_deposit')
380
+ maxDeposit = self.safe_number(currency, 'max_deposit')
381
+ network = {
382
+ 'id': networkId,
383
+ 'network': networkName,
384
+ 'limits': {
385
+ 'withdraw': {
386
+ 'min': minWithdraw,
387
+ 'max': maxWithdraw,
388
+ },
389
+ 'deposit': {
390
+ 'min': minDeposit,
391
+ 'max': maxDeposit,
392
+ },
393
+ },
394
+ 'active': isActive,
395
+ 'deposit': allowDeposit,
396
+ 'withdraw': allowWithdraw,
397
+ 'fee': None,
398
+ 'precision': None,
399
+ 'info': currency,
400
+ }
401
+ networks = {}
402
+ networks[networkName] = network
403
+ if not (code in result):
404
+ result[code] = {
405
+ 'id': currencyId,
406
+ 'code': code,
407
+ 'precision': None,
408
+ 'type': None,
409
+ 'name': None,
410
+ 'active': isActive,
411
+ 'deposit': allowDeposit,
412
+ 'withdraw': allowWithdraw,
413
+ 'fee': None,
414
+ 'limits': {
415
+ 'withdraw': {
416
+ 'min': minWithdraw,
417
+ 'max': maxWithdraw,
418
+ },
419
+ 'deposit': {
420
+ 'min': minDeposit,
421
+ 'max': maxDeposit,
422
+ },
423
+ },
424
+ 'networks': networks,
425
+ 'info': currency,
426
+ }
427
+ else:
428
+ parsed = result[code]
429
+ parsedNetworks = self.safe_dict(parsed, 'networks')
430
+ parsed['networks'] = self.extend(parsedNetworks, networks)
431
+ if isActive:
432
+ parsed['active'] = True
433
+ parsed['deposit'] = True
434
+ parsed['withdraw'] = True
435
+ else:
436
+ if allowWithdraw:
437
+ parsed['withdraw'] = True
438
+ if allowDeposit:
439
+ parsed['deposit'] = True
440
+ parsedLimits = self.safe_dict(parsed, 'limits')
441
+ withdrawLimits = {
442
+ 'min': None,
443
+ 'max': None,
444
+ }
445
+ parsedWithdrawLimits = self.safe_dict(parsedLimits, 'withdraw', withdrawLimits)
446
+ depositLimits = {
447
+ 'min': None,
448
+ 'max': None,
449
+ }
450
+ parsedDepositLimits = self.safe_dict(parsedLimits, 'deposit', depositLimits)
451
+ if minWithdraw:
452
+ withdrawLimits['min'] = min(parsedWithdrawLimits['min'], minWithdraw) if parsedWithdrawLimits['min'] else minWithdraw
453
+ if maxWithdraw:
454
+ withdrawLimits['max'] = max(parsedWithdrawLimits['max'], maxWithdraw) if parsedWithdrawLimits['max'] else maxWithdraw
455
+ if minDeposit:
456
+ depositLimits['min'] = min(parsedDepositLimits['min'], minDeposit) if parsedDepositLimits['min'] else minDeposit
457
+ if maxDeposit:
458
+ depositLimits['max'] = max(parsedDepositLimits['max'], maxDeposit) if parsedDepositLimits['max'] else maxDeposit
459
+ limits = {
460
+ 'withdraw': withdrawLimits,
461
+ 'deposit': depositLimits,
462
+ }
463
+ parsed['limits'] = limits
464
+ return result
465
+
466
+ async def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
467
+ """
468
+ fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
469
+ https://doc.cryptomus.com/personal/market-cap/tickers
470
+ :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
471
+ :param dict [params]: extra parameters specific to the exchange API endpoint
472
+ :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
473
+ """
474
+ await self.load_markets()
475
+ symbols = self.market_symbols(symbols)
476
+ response = await self.publicGetV1ExchangeMarketTickers(params)
477
+ #
478
+ # {
479
+ # "data": [
480
+ # {
481
+ # "currency_pair": "MATIC_USDT",
482
+ # "last_price": "0.342",
483
+ # "base_volume": "1676.84092771",
484
+ # "quote_volume": "573.48033609043"
485
+ # },
486
+ # ...
487
+ # }
488
+ #
489
+ data = self.safe_list(response, 'data')
490
+ return self.parse_tickers(data, symbols)
491
+
492
+ def parse_ticker(self, ticker, market: Market = None) -> Ticker:
493
+ #
494
+ # {
495
+ # "currency_pair": "XMR_USDT",
496
+ # "last_price": "158.04829771",
497
+ # "base_volume": "0.35185785",
498
+ # "quote_volume": "55.523761128544"
499
+ # }
500
+ #
501
+ marketId = self.safe_string(ticker, 'currency_pair')
502
+ market = self.safe_market(marketId, market)
503
+ symbol = market['symbol']
504
+ last = self.safe_string(ticker, 'last_price')
505
+ return self.safe_ticker({
506
+ 'symbol': symbol,
507
+ 'timestamp': None,
508
+ 'datetime': None,
509
+ 'high': None,
510
+ 'low': None,
511
+ 'bid': None,
512
+ 'bidVolume': None,
513
+ 'ask': None,
514
+ 'askVolume': None,
515
+ 'vwap': None,
516
+ 'open': None,
517
+ 'close': last,
518
+ 'last': last,
519
+ 'previousClose': None,
520
+ 'change': None,
521
+ 'percentage': None,
522
+ 'average': None,
523
+ 'baseVolume': self.safe_string(ticker, 'base_volume'),
524
+ 'quoteVolume': self.safe_string(ticker, 'quote_volume'),
525
+ 'info': ticker,
526
+ }, market)
527
+
528
+ async def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
529
+ """
530
+ fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
531
+ https://doc.cryptomus.com/personal/market-cap/orderbook
532
+ :param str symbol: unified symbol of the market to fetch the order book for
533
+ :param int [limit]: the maximum amount of order book entries to return
534
+ :param dict [params]: extra parameters specific to the exchange API endpoint
535
+ :param int [params.level]: 0 or 1 or 2 or 3 or 4 or 5 - the level of volume
536
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
537
+ """
538
+ await self.load_markets()
539
+ market = self.market(symbol)
540
+ request: dict = {
541
+ 'currencyPair': market['id'],
542
+ }
543
+ level = 0
544
+ level, params = self.handle_option_and_params(params, 'fetchOrderBook', 'level', level)
545
+ request['level'] = level
546
+ response = await self.publicGetV1ExchangeMarketOrderBookCurrencyPair(self.extend(request, params))
547
+ #
548
+ # {
549
+ # "data": {
550
+ # "timestamp": "1730138702",
551
+ # "bids": [
552
+ # {
553
+ # "price": "2250.00",
554
+ # "quantity": "1.00000"
555
+ # }
556
+ # ],
557
+ # "asks": [
558
+ # {
559
+ # "price": "2428.69",
560
+ # "quantity": "0.16470"
561
+ # }
562
+ # ]
563
+ # }
564
+ # }
565
+ #
566
+ data = self.safe_dict(response, 'data', {})
567
+ timestamp = self.safe_timestamp(data, 'timestamp')
568
+ return self.parse_order_book(data, symbol, timestamp, 'bids', 'asks', 'price', 'quantity')
569
+
570
+ async def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
571
+ """
572
+ get the list of most recent trades for a particular symbol
573
+ https://doc.cryptomus.com/personal/market-cap/trades
574
+ :param str symbol: unified symbol of the market to fetch trades for
575
+ :param int [since]: timestamp in ms of the earliest trade to fetch
576
+ :param int [limit]: the maximum amount of trades to fetch(maximum value is 100)
577
+ :param dict [params]: extra parameters specific to the exchange API endpoint
578
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
579
+ """
580
+ await self.load_markets()
581
+ market = self.market(symbol)
582
+ request: dict = {
583
+ 'currencyPair': market['id'],
584
+ }
585
+ response = await self.publicGetV1ExchangeMarketTradesCurrencyPair(self.extend(request, params))
586
+ #
587
+ # {
588
+ # "data": [
589
+ # {
590
+ # "trade_id": "01J829C3RAXHXHR09HABGQ1YAT",
591
+ # "price": "2315.6320500000000000",
592
+ # "base_volume": "21.9839623057260000",
593
+ # "quote_volume": "0.0094937200000000",
594
+ # "timestamp": 1726653796,
595
+ # "type": "sell"
596
+ # }
597
+ # ]
598
+ # }
599
+ #
600
+ data = self.safe_list(response, 'data')
601
+ return self.parse_trades(data, market, since, limit)
602
+
603
+ def parse_trade(self, trade: dict, market: Market = None) -> Trade:
604
+ #
605
+ # {
606
+ # "trade_id": "01J017Q6B3JGHZRP9D2NZHVKFX",
607
+ # "price": "59498.63487492",
608
+ # "base_volume": "94.00784310",
609
+ # "quote_volume": "0.00158000",
610
+ # "timestamp": 1718028573,
611
+ # "type": "sell"
612
+ # }
613
+ #
614
+ timestamp = self.safe_timestamp(trade, 'timestamp')
615
+ return self.safe_trade({
616
+ 'id': self.safe_string(trade, 'trade_id'),
617
+ 'timestamp': timestamp,
618
+ 'datetime': self.iso8601(timestamp),
619
+ 'symbol': market['symbol'],
620
+ 'side': self.safe_string(trade, 'type'),
621
+ 'price': self.safe_string(trade, 'price'),
622
+ 'amount': self.safe_string(trade, 'quote_volume'), # quote_volume is amount
623
+ 'cost': self.safe_string(trade, 'base_volume'), # base_volume is cost
624
+ 'takerOrMaker': None,
625
+ 'type': None,
626
+ 'order': None,
627
+ 'fee': {
628
+ 'currency': None,
629
+ 'cost': None,
630
+ },
631
+ 'info': trade,
632
+ }, market)
633
+
634
+ async def fetch_balance(self, params={}) -> Balances:
635
+ """
636
+ query for balance and get the amount of funds available for trading or funds locked in orders
637
+ https://doc.cryptomus.com/personal/converts/balance
638
+ :param dict [params]: extra parameters specific to the exchange API endpoint
639
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
640
+ """
641
+ await self.load_markets()
642
+ request: dict = {}
643
+ response = await self.privateGetV2UserApiExchangeAccountBalance(self.extend(request, params))
644
+ #
645
+ # {
646
+ # "result": [
647
+ # {
648
+ # "ticker": "AVAX",
649
+ # "available": "0.00000000",
650
+ # "held": "0.00000000"
651
+ # }
652
+ # ]
653
+ # }
654
+ #
655
+ result = self.safe_list(response, 'result', [])
656
+ return self.parse_balance(result)
657
+
658
+ def parse_balance(self, balance) -> Balances:
659
+ #
660
+ # {
661
+ # "ticker": "AVAX",
662
+ # "available": "0.00000000",
663
+ # "held": "0.00000000"
664
+ # }
665
+ #
666
+ result: dict = {
667
+ 'info': balance,
668
+ }
669
+ for i in range(0, len(balance)):
670
+ balanceEntry = balance[i]
671
+ currencyId = self.safe_string(balanceEntry, 'ticker')
672
+ code = self.safe_currency_code(currencyId)
673
+ account = self.account()
674
+ account['free'] = self.safe_string(balanceEntry, 'available')
675
+ account['used'] = self.safe_string(balanceEntry, 'held')
676
+ result[code] = account
677
+ return self.safe_balance(result)
678
+
679
+ async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}) -> Order:
680
+ """
681
+ create a trade order
682
+ https://doc.cryptomus.com/personal/exchange/market-order-creation
683
+ https://doc.cryptomus.com/personal/exchange/limit-order-creation
684
+ :param str symbol: unified symbol of the market to create an order in
685
+ :param str type: 'market' or 'limit' or for spot
686
+ :param str side: 'buy' or 'sell'
687
+ :param float amount: how much of you want to trade in units of the base currency
688
+ :param float [price]: the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders(only for limit orders)
689
+ :param dict [params]: extra parameters specific to the exchange API endpoint
690
+ :param float [params.cost]: *market buy only* the quote quantity that can be used alternative for the amount
691
+ :param dict [params]: extra parameters specific to the exchange API endpoint
692
+ :param str [params.clientOrderId]: a unique identifier for the order(optional)
693
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
694
+ """
695
+ await self.load_markets()
696
+ market = self.market(symbol)
697
+ request: dict = {
698
+ 'market': market['id'],
699
+ 'direction': side,
700
+ 'tag': 'ccxt',
701
+ }
702
+ clientOrderId = self.safe_string(params, 'clientOrderId')
703
+ if clientOrderId is not None:
704
+ params = self.omit(params, 'clientOrderId')
705
+ request['client_order_id'] = clientOrderId
706
+ sideBuy = side == 'buy'
707
+ amountToString = self.number_to_string(amount)
708
+ priceToString = self.number_to_string(price)
709
+ cost = None
710
+ cost, params = self.handle_param_string(params, 'cost')
711
+ response = None
712
+ if type == 'market':
713
+ if sideBuy:
714
+ createMarketBuyOrderRequiresPrice = True
715
+ createMarketBuyOrderRequiresPrice, params = self.handle_option_and_params(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', True)
716
+ if createMarketBuyOrderRequiresPrice:
717
+ if (price is None) and (cost is None):
718
+ raise InvalidOrder(self.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option of param to False and pass the cost to spend in the amount argument')
719
+ elif cost is None:
720
+ cost = Precise.string_mul(amountToString, priceToString)
721
+ else:
722
+ cost = cost if cost else amountToString
723
+ request['value'] = cost
724
+ else:
725
+ request['quantity'] = amountToString
726
+ response = await self.privatePostV2UserApiExchangeOrdersMarket(self.extend(request, params))
727
+ elif type == 'limit':
728
+ if price is None:
729
+ raise ArgumentsRequired(self.id + ' createOrder() requires a price parameter for a ' + type + ' order')
730
+ request['quantity'] = amountToString
731
+ request['price'] = price
732
+ response = await self.privatePostV2UserApiExchangeOrders(self.extend(request, params))
733
+ else:
734
+ raise ArgumentsRequired(self.id + ' createOrder() requires a type parameter(limit or market)')
735
+ #
736
+ # {
737
+ # "order_id": "01JEXAFCCC5ZVJPZAAHHDKQBNG"
738
+ # }
739
+ #
740
+ return self.parse_order(response, market)
741
+
742
+ async def cancel_order(self, id: str, symbol: Str = None, params={}):
743
+ """
744
+ cancels an open limit order
745
+ https://doc.cryptomus.com/personal/exchange/limit-order-cancellation
746
+ :param str id: order id
747
+ :param str symbol: unified symbol of the market the order was made in(not used in cryptomus)
748
+ :param dict [params]: extra parameters specific to the exchange API endpoint
749
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
750
+ """
751
+ await self.load_markets()
752
+ request: dict = {}
753
+ request['orderId'] = id
754
+ response = await self.privateDeleteV2UserApiExchangeOrdersOrderId(self.extend(request, params))
755
+ #
756
+ # {
757
+ # "success": True
758
+ # }
759
+ #
760
+ return response
761
+
762
+ async def fetch_canceled_and_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
763
+ """
764
+ fetches information on multiple orders made by the user
765
+ https://doc.cryptomus.com/personal/exchange/history-of-completed-orders
766
+ :param str symbol: unified market symbol of the market orders were made in(not used in cryptomus)
767
+ :param int [since]: the earliest time in ms to fetch orders for(not used in cryptomus)
768
+ :param int [limit]: the maximum number of order structures to retrieve(not used in cryptomus)
769
+ :param dict [params]: extra parameters specific to the exchange API endpoint
770
+ :param str [params.direction]: order direction 'buy' or 'sell'
771
+ :param str [params.order_id]: order id
772
+ :param str [params.client_order_id]: client order id
773
+ :param str [params.limit]: A special parameter that sets the maximum number of records the request will return
774
+ :param str [params.offset]: A special parameter that sets the number of records from the beginning of the list
775
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
776
+ """
777
+ await self.load_markets()
778
+ request: dict = {}
779
+ market = None
780
+ if symbol is not None:
781
+ market = self.market(symbol)
782
+ request['market'] = market['id']
783
+ if limit is not None:
784
+ request['limit'] = limit
785
+ response = await self.privateGetV2UserApiExchangeOrdersHistory(self.extend(request, params))
786
+ #
787
+ # {
788
+ # "result": [
789
+ # {
790
+ # "id": "01JEXAPY04JDFBVFC2D23BCKMK",
791
+ # "type": "market",
792
+ # "direction": "sell",
793
+ # "symbol": "TRX_USDT",
794
+ # "quantity": "67.5400000000000000",
795
+ # "filledQuantity": "67.5400000000000000",
796
+ # "filledValue": "20.0053480000000000",
797
+ # "state": "completed",
798
+ # "internalState": "filled",
799
+ # "createdAt": "2024-12-12 11:40:19",
800
+ # "finishedAt": "2024-12-12 11:40:21",
801
+ # "deal": {
802
+ # "id": "01JEXAPZ9C9TWENPFZJASZ1YD2",
803
+ # "state": "completed",
804
+ # "createdAt": "2024-12-12 11:40:21",
805
+ # "completedAt": "2024-12-12 11:40:21",
806
+ # "averageFilledPrice": "0.2962000000000000",
807
+ # "transactions": [
808
+ # {
809
+ # "id": "01JEXAPZ9C9TWENPFZJASZ1YD3",
810
+ # "tradeRole": "taker",
811
+ # "filledPrice": "0.2962000000000000",
812
+ # "filledQuantity": "67.5400000000000000",
813
+ # "filledValue": "20.0053480000000000",
814
+ # "fee": "0.0000000000000000",
815
+ # "feeCurrency": "USDT",
816
+ # "committedAt": "2024-12-12 11:40:21"
817
+ # }
818
+ # ]
819
+ # }
820
+ # },
821
+ # ...
822
+ # ]
823
+ # }
824
+ #
825
+ result = self.safe_list(response, 'result', [])
826
+ orders = []
827
+ for i in range(0, len(result)):
828
+ order = result[i]
829
+ orders.append(self.parse_order(order, market))
830
+ return orders
831
+
832
+ async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
833
+ """
834
+ fetch all unfilled currently open orders
835
+ https://doc.cryptomus.com/personal/exchange/list-of-active-orders
836
+ :param str symbol: unified market symbol
837
+ :param int [since]: the earliest time in ms to fetch open orders for(not used in cryptomus)
838
+ :param int [limit]: the maximum number of open orders structures to retrieve(not used in cryptomus)
839
+ :param dict [params]: extra parameters specific to the exchange API endpoint
840
+ :param str [params.direction]: order direction 'buy' or 'sell'
841
+ :param str [params.order_id]: order id
842
+ :param str [params.client_order_id]: client order id
843
+ :param str [params.limit]: A special parameter that sets the maximum number of records the request will return
844
+ :param str [params.offset]: A special parameter that sets the number of records from the beginning of the list
845
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
846
+ """
847
+ await self.load_markets()
848
+ market = None
849
+ if symbol is not None:
850
+ market = self.market(symbol)
851
+ request: dict = {
852
+ }
853
+ if market is not None:
854
+ request['market'] = market['id']
855
+ response = await self.privateGetV2UserApiExchangeOrders(self.extend(request, params))
856
+ #
857
+ # {
858
+ # "result": [
859
+ # {
860
+ # "id": "01JFFG72CBRDP68K179KC9DSTG",
861
+ # "direction": "sell",
862
+ # "symbol": "BTC_USDT",
863
+ # "price": "102.0130000000000000",
864
+ # "quantity": "0.0005000000000000",
865
+ # "value": "0.0510065000000000",
866
+ # "filledQuantity": "0.0000000000000000",
867
+ # "filledValue": "0.0000000000000000",
868
+ # "createdAt": "2024-12-19 09:02:51",
869
+ # "clientOrderId": "987654321",
870
+ # "stopLossPrice": "101.12"
871
+ # },
872
+ # ...
873
+ # ]
874
+ # }
875
+ result = self.safe_list(response, 'result', [])
876
+ return self.parse_orders(result, market, None, None)
877
+
878
+ def parse_order(self, order: dict, market: Market = None) -> Order:
879
+ #
880
+ # createOrder
881
+ # {
882
+ # "order_id": "01JEXAFCCC5ZVJPZAAHHDKQBNG"
883
+ # }
884
+ #
885
+ # fetchOrders
886
+ # {
887
+ # "id": "01JEXAPY04JDFBVFC2D23BCKMK",
888
+ # "type": "market",
889
+ # "direction": "sell",
890
+ # "symbol": "TRX_USDT",
891
+ # "quantity": "67.5400000000000000",
892
+ # "filledQuantity": "67.5400000000000000",
893
+ # "filledValue": "20.0053480000000000",
894
+ # "state": "completed",
895
+ # "internalState": "filled",
896
+ # "createdAt": "2024-12-12 11:40:19",
897
+ # "finishedAt": "2024-12-12 11:40:21",
898
+ # "deal": {
899
+ # "id": "01JEXAPZ9C9TWENPFZJASZ1YD2",
900
+ # "state": "completed",
901
+ # "createdAt": "2024-12-12 11:40:21",
902
+ # "completedAt": "2024-12-12 11:40:21",
903
+ # "averageFilledPrice": "0.2962000000000000",
904
+ # "transactions": [
905
+ # {
906
+ # "id": "01JEXAPZ9C9TWENPFZJASZ1YD3",
907
+ # "tradeRole": "taker",
908
+ # "filledPrice": "0.2962000000000000",
909
+ # "filledQuantity": "67.5400000000000000",
910
+ # "filledValue": "20.0053480000000000",
911
+ # "fee": "0.0000000000000000",
912
+ # "feeCurrency": "USDT",
913
+ # "committedAt": "2024-12-12 11:40:21"
914
+ # }
915
+ # ]
916
+ # }
917
+ # },
918
+ # ...
919
+ #
920
+ # fetchOpenOrders
921
+ # {
922
+ # "id": "01JFFG72CBRDP68K179KC9DSTG",
923
+ # "direction": "sell",
924
+ # "symbol": "BTC_USDT",
925
+ # "price": "102.0130000000000000",
926
+ # "quantity": "0.0005000000000000",
927
+ # "value": "0.0510065000000000",
928
+ # "filledQuantity": "0.0000000000000000",
929
+ # "filledValue": "0.0000000000000000",
930
+ # "createdAt": "2024-12-19 09:02:51",
931
+ # "clientOrderId": "987654321",
932
+ # "stopLossPrice": "101.12"
933
+ # }
934
+ #
935
+ id = self.safe_string_2(order, 'order_id', 'id')
936
+ marketId = self.safe_string(order, 'symbol')
937
+ market = self.safe_market(marketId, market)
938
+ dateTime = self.safe_string(order, 'createdAt')
939
+ timestamp = self.parse8601(dateTime)
940
+ deal = self.safe_dict(order, 'deal', {})
941
+ averageFilledPrice = self.safe_number(deal, 'averageFilledPrice')
942
+ type = self.safe_string(order, 'type')
943
+ side = self.safe_string(order, 'direction')
944
+ price = self.safe_number(order, 'price')
945
+ transaction = self.safe_list(deal, 'transactions', [])
946
+ fee = None
947
+ firstTx = self.safe_dict(transaction, 0)
948
+ feeCurrency = self.safe_string(firstTx, 'feeCurrency')
949
+ if feeCurrency is not None:
950
+ fee = {
951
+ 'currency': self.safe_currency_code(feeCurrency),
952
+ 'cost': self.safe_number(firstTx, 'fee'),
953
+ }
954
+ if price is None:
955
+ price = self.safe_number(firstTx, 'filledPrice')
956
+ amount = self.safe_number(order, 'quantity')
957
+ cost = self.safe_number(order, 'value')
958
+ status = self.parse_order_status(self.safe_string(order, 'state'))
959
+ clientOrderId = self.safe_string(order, 'clientOrderId')
960
+ return self.safe_order({
961
+ 'id': id,
962
+ 'clientOrderId': clientOrderId,
963
+ 'timestamp': timestamp,
964
+ 'datetime': self.iso8601(timestamp),
965
+ 'lastTradeTimestamp': None,
966
+ 'symbol': market['symbol'],
967
+ 'type': type,
968
+ 'timeInForce': None,
969
+ 'postOnly': None,
970
+ 'side': side,
971
+ 'price': price,
972
+ 'stopPrice': self.safe_string(order, 'stopLossPrice'),
973
+ 'triggerPrice': self.safe_string(order, 'stopLossPrice'),
974
+ 'amount': amount,
975
+ 'cost': cost,
976
+ 'average': averageFilledPrice,
977
+ 'filled': self.safe_string(order, 'filledQuantity'),
978
+ 'remaining': None,
979
+ 'status': status,
980
+ 'fee': fee,
981
+ 'trades': None,
982
+ 'info': order,
983
+ }, market)
984
+
985
+ def parse_order_status(self, status: Str = None) -> Str:
986
+ statuses = {
987
+ 'active': 'open',
988
+ 'completed': 'closed',
989
+ 'partially_completed': 'open',
990
+ 'cancelled': 'canceled',
991
+ 'expired': 'expired',
992
+ 'failed': 'failed',
993
+ }
994
+ return self.safe_string(statuses, status, status)
995
+
996
+ def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
997
+ endpoint = self.implode_params(path, params)
998
+ params = self.omit(params, self.extract_params(path))
999
+ url = self.urls['api'][api] + '/' + endpoint
1000
+ if api == 'private':
1001
+ self.check_required_credentials()
1002
+ jsonParams = ''
1003
+ headers = {
1004
+ 'userId': self.uid,
1005
+ }
1006
+ if method != 'GET':
1007
+ body = self.json(params)
1008
+ jsonParams = body
1009
+ headers['Content-Type'] = 'application/json'
1010
+ else:
1011
+ query = self.urlencode(params)
1012
+ if len(query) != 0:
1013
+ url += '?' + query
1014
+ jsonParamsBase64 = self.string_to_base64(jsonParams)
1015
+ stringToSign = jsonParamsBase64 + self.secret
1016
+ signature = self.hash(self.encode(stringToSign), 'md5')
1017
+ headers['sign'] = signature
1018
+ else:
1019
+ query = self.urlencode(params)
1020
+ if len(query) != 0:
1021
+ url += '?' + query
1022
+ return {'url': url, 'method': method, 'body': body, 'headers': headers}
1023
+
1024
+ def handle_errors(self, httpCode: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
1025
+ if response is None:
1026
+ return None
1027
+ if 'code' in response:
1028
+ code = self.safe_string(response, 'code')
1029
+ feedback = self.id + ' ' + body
1030
+ self.throw_exactly_matched_exception(self.exceptions['exact'], code, feedback)
1031
+ raise ExchangeError(feedback)
1032
+ elif 'message' in response:
1033
+ #
1034
+ # {"message":"Minimum amount 15 USDT","state":1}
1035
+ #
1036
+ message = self.safe_string(response, 'message')
1037
+ feedback = self.id + ' ' + body
1038
+ self.throw_exactly_matched_exception(self.exceptions['exact'], message, feedback)
1039
+ self.throw_broadly_matched_exception(self.exceptions['broad'], message, feedback)
1040
+ raise ExchangeError(feedback) # unknown message
1041
+ return None