ccxt 4.3.44__py2.py3-none-any.whl → 4.3.45__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.
@@ -0,0 +1,2773 @@
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.oxfun import ImplicitAPI
8
+ import asyncio
9
+ import hashlib
10
+ from ccxt.base.types import Account, Balances, Bool, Currencies, Currency, Int, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
11
+ from typing import List
12
+ from ccxt.base.errors import ExchangeError
13
+ from ccxt.base.errors import AuthenticationError
14
+ from ccxt.base.errors import AccountNotEnabled
15
+ from ccxt.base.errors import ArgumentsRequired
16
+ from ccxt.base.errors import BadRequest
17
+ from ccxt.base.errors import BadSymbol
18
+ from ccxt.base.errors import MarketClosed
19
+ from ccxt.base.errors import InsufficientFunds
20
+ from ccxt.base.errors import InvalidOrder
21
+ from ccxt.base.errors import OrderNotFound
22
+ from ccxt.base.errors import NotSupported
23
+ from ccxt.base.errors import OperationFailed
24
+ from ccxt.base.errors import NetworkError
25
+ from ccxt.base.errors import RateLimitExceeded
26
+ from ccxt.base.errors import RequestTimeout
27
+ from ccxt.base.decimal_to_precision import TICK_SIZE
28
+ from ccxt.base.precise import Precise
29
+
30
+
31
+ class oxfun(Exchange, ImplicitAPI):
32
+
33
+ def describe(self):
34
+ return self.deep_extend(super(oxfun, self).describe(), {
35
+ 'id': 'oxfun',
36
+ 'name': 'Oxfun',
37
+ 'countries': ['PA'], # Panama todo check
38
+ 'version': 'v3',
39
+ 'rateLimit': 120, # 100 requests per second and 25000 per 5 minutes
40
+ 'pro': True,
41
+ 'has': {
42
+ 'CORS': None,
43
+ 'spot': True,
44
+ 'margin': False,
45
+ 'swap': True,
46
+ 'future': False,
47
+ 'option': False,
48
+ 'addMargin': False,
49
+ 'cancelAllOrders': True,
50
+ 'cancelOrder': True,
51
+ 'cancelOrders': True,
52
+ 'closeAllPositions': False,
53
+ 'closePosition': False,
54
+ 'createDepositAddress': False,
55
+ 'createMarketBuyOrderWithCost': True,
56
+ 'createMarketOrderWithCost': False,
57
+ 'createMarketSellOrderWithCost': False,
58
+ 'createOrder': True,
59
+ 'createOrders': True,
60
+ 'createPostOnlyOrder': True,
61
+ 'createReduceOnlyOrder': False,
62
+ 'createStopLimitOrder': True,
63
+ 'createStopMarketOrder': True,
64
+ 'createStopOrder': True,
65
+ 'deposit': False,
66
+ 'editOrder': False,
67
+ 'fetchAccounts': True,
68
+ 'fetchBalance': True,
69
+ 'fetchBidsAsks': False,
70
+ 'fetchBorrowInterest': False,
71
+ 'fetchBorrowRateHistories': False,
72
+ 'fetchBorrowRateHistory': False,
73
+ 'fetchCanceledOrders': False,
74
+ 'fetchClosedOrder': False,
75
+ 'fetchClosedOrders': False,
76
+ 'fetchCrossBorrowRate': False,
77
+ 'fetchCrossBorrowRates': False,
78
+ 'fetchCurrencies': True,
79
+ 'fetchDeposit': False,
80
+ 'fetchDepositAddress': False,
81
+ 'fetchDepositAddresses': False,
82
+ 'fetchDepositAddressesByNetwork': False,
83
+ 'fetchDeposits': True,
84
+ 'fetchDepositWithdrawFee': False,
85
+ 'fetchDepositWithdrawFees': False,
86
+ 'fetchFundingHistory': True,
87
+ 'fetchFundingRate': False,
88
+ 'fetchFundingRateHistory': True,
89
+ 'fetchFundingRates': True,
90
+ 'fetchIndexOHLCV': False,
91
+ 'fetchIsolatedBorrowRate': False,
92
+ 'fetchIsolatedBorrowRates': False,
93
+ 'fetchL3OrderBook': False,
94
+ 'fetchLedger': False,
95
+ 'fetchLeverage': False,
96
+ 'fetchLeverageTiers': True,
97
+ 'fetchMarketLeverageTiers': False,
98
+ 'fetchMarkets': True,
99
+ 'fetchMarkOHLCV': False,
100
+ 'fetchMyTrades': True,
101
+ 'fetchOHLCV': True,
102
+ 'fetchOpenInterestHistory': False,
103
+ 'fetchOpenOrder': False,
104
+ 'fetchOpenOrders': True,
105
+ 'fetchOrder': True,
106
+ 'fetchOrderBook': True,
107
+ 'fetchOrderBooks': False,
108
+ 'fetchOrders': False,
109
+ 'fetchOrderTrades': False,
110
+ 'fetchPosition': False,
111
+ 'fetchPositionHistory': False,
112
+ 'fetchPositionMode': False,
113
+ 'fetchPositions': True,
114
+ 'fetchPositionsForSymbol': False,
115
+ 'fetchPositionsHistory': False,
116
+ 'fetchPositionsRisk': False,
117
+ 'fetchPremiumIndexOHLCV': False,
118
+ 'fetchStatus': False,
119
+ 'fetchTicker': True,
120
+ 'fetchTickers': True,
121
+ 'fetchTime': False,
122
+ 'fetchTrades': True,
123
+ 'fetchTradingFee': False,
124
+ 'fetchTradingFees': False,
125
+ 'fetchTradingLimits': False,
126
+ 'fetchTransactionFee': False,
127
+ 'fetchTransactionFees': False,
128
+ 'fetchTransactions': False,
129
+ 'fetchTransfers': True,
130
+ 'fetchWithdrawal': False,
131
+ 'fetchWithdrawals': True,
132
+ 'fetchWithdrawalWhitelist': False,
133
+ 'reduceMargin': False,
134
+ 'repayCrossMargin': False,
135
+ 'repayIsolatedMargin': False,
136
+ 'setLeverage': False,
137
+ 'setMargin': False,
138
+ 'setMarginMode': False,
139
+ 'setPositionMode': False,
140
+ 'signIn': False,
141
+ 'transfer': True,
142
+ 'withdraw': True,
143
+ 'ws': True,
144
+ },
145
+ 'timeframes': {
146
+ '1m': '60s',
147
+ '5m': '300s',
148
+ '15m': '900s',
149
+ '30m': '1800s',
150
+ '1h': '3600s',
151
+ '2h': '7200s',
152
+ '4h': '14400s',
153
+ '1d': '86400s',
154
+ },
155
+ 'urls': {
156
+ 'logo': 'https://github.com/ccxt/ccxt/assets/43336371/9c7114b3-ec32-4cf7-a716-f807d7d071cd',
157
+ 'referral': 'https://ox.fun/register?shareAccountId=5ZUD4a7G',
158
+ 'api': {
159
+ 'public': 'https://api.ox.fun',
160
+ 'private': 'https://api.ox.fun',
161
+ },
162
+ 'test': {
163
+ 'public': 'https://stgapi.ox.fun',
164
+ 'private': 'https://stgapi.ox.fun',
165
+ },
166
+ 'www': 'https://ox.fun/',
167
+ 'doc': 'https://docs.ox.fun/',
168
+ 'fees': 'https://support.ox.fun/en/articles/8819866-trading-fees',
169
+ },
170
+ 'api': {
171
+ 'public': {
172
+ 'get': {
173
+ 'v3/markets': 1,
174
+ 'v3/assets': 1,
175
+ 'v3/tickers': 1,
176
+ 'v3/funding/estimates': 1,
177
+ 'v3/candles': 1,
178
+ 'v3/depth': 1,
179
+ 'v3/markets/operational': 1,
180
+ 'v3/exchange-trades': 1,
181
+ 'v3/funding/rates': 1,
182
+ 'v3/leverage/tiers': 1,
183
+ },
184
+ },
185
+ 'private': {
186
+ 'get': {
187
+ 'v3/account': 1,
188
+ 'v3/account/names': 1,
189
+ 'v3/wallet': 1, # retruns only FUNDING in OX
190
+ 'v3/transfer': 1,
191
+ 'v3/balances': 1,
192
+ 'v3/positions': 1,
193
+ 'v3/funding': 1,
194
+ 'v3/deposit-addresses': 1,
195
+ 'v3/deposit': 1,
196
+ 'v3/withdrawal-addresses': 1,
197
+ 'v3/withdrawal': 1,
198
+ 'v3/withdrawal-fees': 1,
199
+ 'v3/orders/status': 1,
200
+ 'v3/orders/working': 1,
201
+ 'v3/trades': 1,
202
+ },
203
+ 'post': {
204
+ 'v3/transfer': 1,
205
+ 'v3/withdrawal': 1,
206
+ 'v3/orders/place': 1,
207
+ },
208
+ 'delete': {
209
+ 'v3/orders/cancel': 1,
210
+ 'v3/orders/cancel-all': 1,
211
+ },
212
+ },
213
+ },
214
+ 'fees': {
215
+ 'trading': {
216
+ 'tierBased': True,
217
+ 'percentage': True,
218
+ 'maker': self.parse_number('0.00020'),
219
+ 'taker': self.parse_number('0.00070'),
220
+ 'tiers': {
221
+ 'maker': [
222
+ [self.parse_number('0'), self.parse_number('0.00020')],
223
+ [self.parse_number('2500000'), self.parse_number('0.00010')],
224
+ [self.parse_number('25000000'), self.parse_number('0')],
225
+ ],
226
+ 'taker': [
227
+ [self.parse_number('0'), self.parse_number('0.00070')],
228
+ [self.parse_number('2500000'), self.parse_number('0.00050')],
229
+ [self.parse_number('25000000'), self.parse_number('0.00040')],
230
+ ],
231
+ },
232
+ },
233
+ },
234
+ 'precisionMode': TICK_SIZE,
235
+ # exchange-specific options
236
+ 'options': {
237
+ 'sandboxMode': False,
238
+ 'networks': {
239
+ 'BTC': 'Bitcoin',
240
+ 'ERC20': 'Ethereum',
241
+ 'AVAX': 'Avalanche',
242
+ 'SOL': 'Solana',
243
+ 'ARB': 'Arbitrum',
244
+ 'MATIC': 'Polygon',
245
+ 'FTM': 'Fantom',
246
+ 'BNB': 'BNBSmartChain',
247
+ 'OPTIMISM': 'Optimism',
248
+ },
249
+ 'networksById': {
250
+ 'Bitcoin': 'BTC',
251
+ 'Ethereum': 'ERC20',
252
+ 'Avalanche': 'AVAX',
253
+ 'Solana': 'SOL',
254
+ 'Arbitrum': 'ARB',
255
+ 'Polygon': 'MATIC',
256
+ 'Fantom': 'FTM',
257
+ 'Base': 'BASE',
258
+ 'BNBSmartChain': 'BNB',
259
+ 'Optimism': 'OPTIMISM',
260
+ },
261
+ },
262
+ 'exceptions': {
263
+ 'exact': {
264
+ '-0010': OperationFailed, # {"event":null,"success":false,"message":"Validation failed","code":"0010","data":null} - failed transfer
265
+ '-429': RateLimitExceeded, # Rate limit reached
266
+ '-05001': AuthenticationError, # Your operation authority is invalid
267
+ '-10001': ExchangeError, # General networking failure
268
+ '-20000': BadRequest, # Signature is invalid
269
+ '-20001': BadRequest, # "success":false,"code":"20001","message":"marketCode is invalid"
270
+ '-20002': BadRequest, # Unexpected error, please check if your request data complies with the specification.
271
+ '-20003': NotSupported, # Unrecognized operation
272
+ '-20005': AuthenticationError, # Already logged in
273
+ '-20006': BadRequest, # Quantity must be greater than zero
274
+ '-20007': AuthenticationError, # You are accessing server too rapidly
275
+ '-20008': BadRequest, # clientOrderId must be greater than zero if provided
276
+ '-20009': BadRequest, # JSON data format is invalid
277
+ '-20010': ArgumentsRequired, # Either clientOrderId or orderId is required
278
+ '-20011': ArgumentsRequired, # marketCode is required
279
+ '-20012': ArgumentsRequired, # side is required
280
+ '-20013': ArgumentsRequired, # orderType is required
281
+ '-20014': BadRequest, # clientOrderId is not long type
282
+ '-20015': BadSymbol, # marketCode is invalid
283
+ '-20016': BadRequest, # side is invalid
284
+ '-20017': BadRequest, # orderType is invalid
285
+ '-20018': BadRequest, # timeInForce is invalid
286
+ '-20019': BadRequest, # orderId is invalid
287
+ '-20020': BadRequest, # stopPrice or limitPrice is invalid
288
+ '-20021': BadRequest, # price is invalid
289
+ '-20022': ArgumentsRequired, # price is required for LIMIT order
290
+ '-20023': ArgumentsRequired, # timestamp is required
291
+ '-20024': ExchangeError, # timestamp exceeds the threshold
292
+ '-20025': AuthenticationError, # API key is invalid
293
+ '-20026': BadRequest, # Token is invalid or expired
294
+ '-20027': BadRequest, # The length of the message exceeds the maximum length
295
+ '-20028': BadRequest, # price or stopPrice or limitPrice must be greater than zero
296
+ '-20029': BadRequest, # stopPrice must be less than limitPrice for Buy Stop Order
297
+ '-20030': BadRequest, # limitPrice must be less than stopPrice for Sell Stop Order
298
+ '-20031': MarketClosed, # The marketCode is closed for trading temporarily
299
+ '-20032': NetworkError, # Failed to submit due to timeout in server side
300
+ '-20033': BadRequest, # triggerType is invalid
301
+ '-20034': BadRequest, # The size of tag must be less than 32
302
+ '-20050': ExchangeError, # selfTradePreventionMode is invalid
303
+ '-30001': BadRequest, # {"success":false,"code":"30001","message":"Required parameter 'marketCode' is missing"}
304
+ '-35034': AuthenticationError, # {"success":false,"code":"35034","message":"Wallet API is not functioning properly, please try again or contact support."}
305
+ '-35046': AuthenticationError, # {"success":false,"code":"35046","message":"Error. Please refresh the page."}
306
+ '-40001': ExchangeError, # Alert from the server
307
+ '-50001': ExchangeError, # Unknown server error
308
+ '-300001': AccountNotEnabled, # Invalid account status xxx, please contact administration if any questions
309
+ '-300011': InvalidOrder, # Repo market orders are not allowed during the auction window
310
+ '-300012': InvalidOrder, # Repo bids above 0 and offers below 0 are not allowed during the auction window
311
+ '-100005': OrderNotFound, # Open order not found
312
+ '-100006': InvalidOrder, # Open order is not owned by the user
313
+ '-100008': BadRequest, # Quantity cannot be less than the quantity increment xxx
314
+ '-100015': NetworkError, # recvWindow xxx has expired
315
+ '-710001': ExchangeError, # System failure, exception thrown -> xxx
316
+ '-710002': BadRequest, # The price is lower than the minimum
317
+ '-710003': BadRequest, # The price is higher than the maximum
318
+ '-710004': BadRequest, # Position quantity exceeds the limit
319
+ '-710005': InsufficientFunds, # Insufficient margin
320
+ '-710006': InsufficientFunds, # Insufficient balance
321
+ '-710007': InsufficientFunds, # Insufficient position
322
+ '-000101': NetworkError, # Internal server is unavailable temporary, try again later
323
+ '-000201': NetworkError, # Trade service is busy, try again later
324
+ },
325
+ 'broad': {
326
+ '-20001': OperationFailed, # Operation failed, please contact system administrator
327
+ '-200050': RequestTimeout, # The market is not active
328
+ },
329
+ },
330
+ })
331
+
332
+ async def fetch_markets(self, params={}) -> List[Market]:
333
+ """
334
+ retrieves data on all markets for bitmex
335
+ :see: https://docs.ox.fun/?json#get-v3-markets
336
+ :param dict [params]: extra parameters specific to the exchange API endpoint
337
+ :returns dict[]: an array of objects representing market data
338
+ """
339
+ responseFromMarkets, responseFromTickers = await asyncio.gather(*[self.publicGetV3Markets(params), self.publicGetV3Tickers(params)])
340
+ marketsFromMarkets = self.safe_list(responseFromMarkets, 'data', [])
341
+ #
342
+ # {
343
+ # success: True,
344
+ # data: [
345
+ # {
346
+ # marketCode: 'OX-USD-SWAP-LIN',
347
+ # name: 'OX/USD Perp',
348
+ # referencePair: 'OX/USDT',
349
+ # base: 'OX',
350
+ # counter: 'USD',
351
+ # type: 'FUTURE',
352
+ # tickSize: '0.00001',
353
+ # minSize: '1',
354
+ # listedAt: '1704766320000',
355
+ # upperPriceBound: '0.02122',
356
+ # lowerPriceBound: '0.01142',
357
+ # markPrice: '0.01632',
358
+ # indexPrice: '0.01564',
359
+ # lastUpdatedAt: '1714762235569'
360
+ # },
361
+ # {
362
+ # marketCode: 'BTC-USD-SWAP-LIN',
363
+ # name: 'BTC/USD Perp',
364
+ # referencePair: 'BTC/USDT',
365
+ # base: 'BTC',
366
+ # counter: 'USD',
367
+ # type: 'FUTURE',
368
+ # tickSize: '1',
369
+ # minSize: '0.0001',
370
+ # listedAt: '1704686640000',
371
+ # upperPriceBound: '67983',
372
+ # lowerPriceBound: '55621',
373
+ # markPrice: '61802',
374
+ # indexPrice: '61813',
375
+ # lastUpdatedAt: '1714762234765'
376
+ # },
377
+ # {
378
+ # "marketCode": "MILK-OX",
379
+ # "name": "MILK/OX",
380
+ # "referencePair": "MILK/OX",
381
+ # "base": "MILK",
382
+ # "counter": "OX",
383
+ # "type": "SPOT",
384
+ # "tickSize": "0.0001",
385
+ # "minSize": "1",
386
+ # "listedAt": "1706608500000",
387
+ # "upperPriceBound": "1.0000",
388
+ # "lowerPriceBound": "-1.0000",
389
+ # "markPrice": "0.0269",
390
+ # "indexPrice": "0.0269",
391
+ # "lastUpdatedAt": "1714757402185"
392
+ # },
393
+ # ...
394
+ # ]
395
+ # }
396
+ #
397
+ marketsFromTickers = self.safe_list(responseFromTickers, 'data', [])
398
+ #
399
+ # {
400
+ # "success": True,
401
+ # "data": [
402
+ # {
403
+ # "marketCode": "DYM-USD-SWAP-LIN",
404
+ # "markPrice": "3.321",
405
+ # "open24h": "3.315",
406
+ # "high24h": "3.356",
407
+ # "low24h": "3.255",
408
+ # "volume24h": "0",
409
+ # "currencyVolume24h": "0",
410
+ # "openInterest": "1768.1",
411
+ # "lastTradedPrice": "3.543",
412
+ # "lastTradedQuantity": "1.0",
413
+ # "lastUpdatedAt": "1714853388102"
414
+ # },
415
+ # ...
416
+ # ]
417
+ # }
418
+ #
419
+ markets = self.array_concat(marketsFromMarkets, marketsFromTickers)
420
+ return self.parse_markets(markets)
421
+
422
+ def parse_markets(self, markets) -> List[Market]:
423
+ marketIds = []
424
+ result = []
425
+ for i in range(0, len(markets)):
426
+ market = markets[i]
427
+ marketId = self.safe_string(market, 'marketCode')
428
+ if not (self.in_array(marketId, marketIds)):
429
+ marketIds.append(marketId)
430
+ result.append(self.parse_market(market))
431
+ return result
432
+
433
+ def parse_market(self, market) -> Market:
434
+ id = self.safe_string(market, 'marketCode', '')
435
+ parts = id.split('-')
436
+ baseId = self.safe_string(parts, 0)
437
+ quoteId = self.safe_string(parts, 1)
438
+ base = self.safe_currency_code(baseId)
439
+ quote = self.safe_currency_code(quoteId)
440
+ symbol = base + '/' + quote
441
+ type = self.safe_string_lower(market, 'type', 'spot') # markets from v3/tickers are spot and have no type
442
+ settleId: Str = None
443
+ settle: Str = None
444
+ isFuture = (type == 'future') # the exchange has only perpetual futures
445
+ if isFuture:
446
+ type = 'swap'
447
+ settleId = 'OX'
448
+ settle = self.safe_currency_code('OX')
449
+ symbol = symbol + ':' + settle
450
+ isSpot = type == 'spot'
451
+ return self.safe_market_structure({
452
+ 'id': id,
453
+ 'numericId': None,
454
+ 'symbol': symbol,
455
+ 'base': base,
456
+ 'quote': quote,
457
+ 'settle': settle,
458
+ 'baseId': baseId,
459
+ 'quoteId': quoteId,
460
+ 'settleId': settleId,
461
+ 'type': type,
462
+ 'spot': isSpot,
463
+ 'margin': False,
464
+ 'swap': isFuture,
465
+ 'future': False,
466
+ 'option': False,
467
+ 'active': True,
468
+ 'contract': isFuture,
469
+ 'linear': True if isFuture else None,
470
+ 'inverse': False if isFuture else None,
471
+ 'taker': self.fees['trading']['taker'],
472
+ 'maker': self.fees['trading']['maker'],
473
+ 'contractSize': 1 if isFuture else None,
474
+ 'expiry': None,
475
+ 'expiryDatetime': None,
476
+ 'strike': None,
477
+ 'optionType': None,
478
+ 'precision': {
479
+ 'amount': None, # todo find it out
480
+ 'price': self.safe_number(market, 'tickSize'),
481
+ },
482
+ 'limits': {
483
+ 'leverage': {
484
+ 'min': None,
485
+ 'max': None,
486
+ },
487
+ 'amount': {
488
+ 'min': self.safe_number(market, 'minSize'),
489
+ 'max': None,
490
+ },
491
+ 'price': {
492
+ 'min': None,
493
+ 'max': None,
494
+ },
495
+ 'cost': {
496
+ 'min': None,
497
+ 'max': None,
498
+ },
499
+ },
500
+ 'created': self.safe_integer(market, 'listedAt'),
501
+ 'index': None,
502
+ 'info': market,
503
+ })
504
+
505
+ async def fetch_currencies(self, params={}) -> Currencies:
506
+ """
507
+ fetches all available currencies on an exchange
508
+ :see: https://docs.ox.fun/?json#get-v3-assets
509
+ :param dict [params]: extra parameters specific to the exchange API endpoint
510
+ :returns dict: an associative dictionary of currencies
511
+ """
512
+ response = await self.publicGetV3Assets(params)
513
+ #
514
+ # {
515
+ # "success": True,
516
+ # "data": [
517
+ # {
518
+ # "asset": "OX",
519
+ # "isCollateral": True,
520
+ # "loanToValue": "1.000000000",
521
+ # "loanToValueFactor": "0.000000000",
522
+ # "networkList": [
523
+ # {
524
+ # "network": "BNBSmartChain",
525
+ # "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
526
+ # "transactionPrecision": "18",
527
+ # "isWithdrawalFeeChargedToUser": True,
528
+ # "canDeposit": True,
529
+ # "canWithdraw": False,
530
+ # "minDeposit": "0.00010",
531
+ # "minWithdrawal": "0.00010"
532
+ # },
533
+ # {
534
+ # "network": "Polygon",
535
+ # "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
536
+ # "transactionPrecision": "18",
537
+ # "isWithdrawalFeeChargedToUser": True,
538
+ # "canDeposit": True,
539
+ # "canWithdraw": False,
540
+ # "minDeposit": "0.00010",
541
+ # "minWithdrawal": "0.00010"
542
+ # },
543
+ # {
544
+ # "network": "Arbitrum",
545
+ # "tokenId": "0xba0Dda8762C24dA9487f5FA026a9B64b695A07Ea",
546
+ # "transactionPrecision": "18",
547
+ # "isWithdrawalFeeChargedToUser": True,
548
+ # "canDeposit": True,
549
+ # "canWithdraw": True,
550
+ # "minDeposit": "0.00010",
551
+ # "minWithdrawal": "0.00010"
552
+ # },
553
+ # {
554
+ # "network": "Ethereum",
555
+ # "tokenId": "0xba0Dda8762C24dA9487f5FA026a9B64b695A07Ea",
556
+ # "transactionPrecision": "18",
557
+ # "isWithdrawalFeeChargedToUser": True,
558
+ # "canDeposit": True,
559
+ # "canWithdraw": True,
560
+ # "minDeposit": "0.00010",
561
+ # "minWithdrawal": "0.00010"
562
+ # },
563
+ # {
564
+ # "network": "Arbitrum",
565
+ # "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
566
+ # "transactionPrecision": "18",
567
+ # "isWithdrawalFeeChargedToUser": True,
568
+ # "canDeposit": True,
569
+ # "canWithdraw": False,
570
+ # "minDeposit": "0.00010",
571
+ # "minWithdrawal": "0.00010"
572
+ # },
573
+ # {
574
+ # "network": "Avalanche",
575
+ # "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
576
+ # "transactionPrecision": "18",
577
+ # "isWithdrawalFeeChargedToUser": True,
578
+ # "canDeposit": True,
579
+ # "canWithdraw": False,
580
+ # "minDeposit": "0.00010",
581
+ # "minWithdrawal": "0.00010"
582
+ # },
583
+ # {
584
+ # "network": "Solana",
585
+ # "tokenId": "DV3845GEAVXfwpyVGGgWbqBVCtzHdCXNCGfcdboSEuZz",
586
+ # "transactionPrecision": "8",
587
+ # "isWithdrawalFeeChargedToUser": True,
588
+ # "canDeposit": True,
589
+ # "canWithdraw": True,
590
+ # "minDeposit": "0.00010",
591
+ # "minWithdrawal": "0.00010"
592
+ # },
593
+ # {
594
+ # "network": "Ethereum",
595
+ # "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
596
+ # "transactionPrecision": "18",
597
+ # "isWithdrawalFeeChargedToUser": True,
598
+ # "canDeposit": True,
599
+ # "canWithdraw": False,
600
+ # "minDeposit": "0.00010",
601
+ # "minWithdrawal": "0.00010"
602
+ # }
603
+ # ]
604
+ # },
605
+ # {
606
+ # "asset": "BTC",
607
+ # "isCollateral": True,
608
+ # "loanToValue": "0.950000000",
609
+ # "loanToValueFactor": "0.000000000",
610
+ # "networkList": [
611
+ # {
612
+ # "network": "Bitcoin",
613
+ # "transactionPrecision": "8",
614
+ # "isWithdrawalFeeChargedToUser": True,
615
+ # "canDeposit": True,
616
+ # "canWithdraw": True,
617
+ # "minDeposit": "0.00010",
618
+ # "minWithdrawal": "0.00010"
619
+ # }
620
+ # ]
621
+ # },
622
+ # {
623
+ # "asset": "USDT.ARB",
624
+ # "isCollateral": True,
625
+ # "loanToValue": "0.950000000",
626
+ # "loanToValueFactor": "0.000000000",
627
+ # "networkList": [
628
+ # {
629
+ # "network": "Arbitrum",
630
+ # "tokenId": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
631
+ # "transactionPrecision": "18",
632
+ # "isWithdrawalFeeChargedToUser": True,
633
+ # "canDeposit": True,
634
+ # "canWithdraw": True,
635
+ # "minDeposit": "0.00010",
636
+ # "minWithdrawal": "0.00010"
637
+ # }
638
+ # ]
639
+ # },
640
+ # ...
641
+ # ]
642
+ # }
643
+ #
644
+ data = self.safe_list(response, 'data', [])
645
+ result: dict = {}
646
+ for i in range(0, len(data)):
647
+ currency = data[i]
648
+ fullId = self.safe_string(currency, 'asset', '')
649
+ parts = fullId.split('.')
650
+ id = parts[0]
651
+ code = self.safe_currency_code(id)
652
+ networks: dict = {}
653
+ chains = self.safe_list(currency, 'networkList', [])
654
+ currencyMaxPrecision: Str = None
655
+ currencyDepositEnabled: Bool = None
656
+ currencyWithdrawEnabled: Bool = None
657
+ for j in range(0, len(chains)):
658
+ chain = chains[j]
659
+ networkId = self.safe_string(chain, 'network')
660
+ networkCode = self.network_id_to_code(networkId)
661
+ deposit = self.safe_bool(chain, 'canDeposit')
662
+ withdraw = self.safe_bool(chain, 'canWithdraw')
663
+ active = (deposit and withdraw)
664
+ minDeposit = self.safe_string(chain, 'minDeposit')
665
+ minWithdrawal = self.safe_string(chain, 'minWithdrawal')
666
+ precision = self.parse_precision(self.safe_string(chain, 'transactionPrecision'))
667
+ networks[networkCode] = {
668
+ 'id': networkId,
669
+ 'network': networkCode,
670
+ 'margin': None,
671
+ 'deposit': deposit,
672
+ 'withdraw': withdraw,
673
+ 'active': active,
674
+ 'fee': None,
675
+ 'precision': self.parse_number(precision),
676
+ 'limits': {
677
+ 'deposit': {
678
+ 'min': minDeposit,
679
+ 'max': None,
680
+ },
681
+ 'withdraw': {
682
+ 'min': minWithdrawal,
683
+ 'max': None,
684
+ },
685
+ },
686
+ 'info': chain,
687
+ }
688
+ if (currencyDepositEnabled is None) or deposit:
689
+ currencyDepositEnabled = deposit
690
+ if (currencyWithdrawEnabled is None) or withdraw:
691
+ currencyWithdrawEnabled = withdraw
692
+ if (currencyMaxPrecision is None) or Precise.string_gt(currencyMaxPrecision, precision):
693
+ currencyMaxPrecision = precision
694
+ if code in result:
695
+ # checking for specific ids.ARB
696
+ networks = self.extend(result[code]['networks'], networks)
697
+ result[code] = {
698
+ 'id': id,
699
+ 'code': code,
700
+ 'name': None,
701
+ 'type': None,
702
+ 'active': None,
703
+ 'deposit': currencyDepositEnabled,
704
+ 'withdraw': currencyWithdrawEnabled,
705
+ 'fee': None,
706
+ 'precision': self.parse_number(currencyMaxPrecision),
707
+ 'limits': {
708
+ 'amount': {
709
+ 'min': None,
710
+ 'max': None,
711
+ },
712
+ 'withdraw': {
713
+ 'min': None,
714
+ 'max': None,
715
+ },
716
+ },
717
+ 'networks': networks,
718
+ 'info': currency,
719
+ }
720
+ return result
721
+
722
+ async def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
723
+ """
724
+ fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
725
+ :see: https://docs.ox.fun/?json#get-v3-tickers
726
+ :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
727
+ :param dict [params]: extra parameters specific to the exchange API endpoint
728
+ :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
729
+ """
730
+ await self.load_markets()
731
+ symbols = self.market_symbols(symbols)
732
+ response = await self.publicGetV3Tickers(params)
733
+ #
734
+ # {
735
+ # "success": True,
736
+ # "data": [
737
+ # {
738
+ # "marketCode": "NII-USDT",
739
+ # "markPrice": "0",
740
+ # "open24h": "0",
741
+ # "high24h": "0",
742
+ # "low24h": "0",
743
+ # "volume24h": "0",
744
+ # "currencyVolume24h": "0",
745
+ # "openInterest": "0",
746
+ # "lastTradedPrice": "0",
747
+ # "lastTradedQuantity": "0",
748
+ # "lastUpdatedAt": "1714853388621"
749
+ # },
750
+ # {
751
+ # "marketCode": "GEC-USDT",
752
+ # "markPrice": "0",
753
+ # "open24h": "0",
754
+ # "high24h": "0",
755
+ # "low24h": "0",
756
+ # "volume24h": "0",
757
+ # "currencyVolume24h": "0",
758
+ # "openInterest": "0",
759
+ # "lastTradedPrice": "0",
760
+ # "lastTradedQuantity": "0",
761
+ # "lastUpdatedAt": "1714853388621"
762
+ # },
763
+ # {
764
+ # "marketCode": "DYM-USD-SWAP-LIN",
765
+ # "markPrice": "3.321",
766
+ # "open24h": "3.315",
767
+ # "high24h": "3.356",
768
+ # "low24h": "3.255",
769
+ # "volume24h": "0",
770
+ # "currencyVolume24h": "0",
771
+ # "openInterest": "1768.1",
772
+ # "lastTradedPrice": "3.543",
773
+ # "lastTradedQuantity": "1.0",
774
+ # "lastUpdatedAt": "1714853388102"
775
+ # },
776
+ # ...
777
+ # ]
778
+ # }
779
+ #
780
+ tickers = self.safe_list(response, 'data', [])
781
+ return self.parse_tickers(tickers, symbols)
782
+
783
+ async def fetch_ticker(self, symbol: str, params={}) -> Ticker:
784
+ """
785
+ fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
786
+ :see: https://docs.ox.fun/?json#get-v3-tickers
787
+ :param str symbol: unified symbol of the market to fetch the ticker for
788
+ :param dict [params]: extra parameters specific to the exchange API endpoint
789
+ :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
790
+ """
791
+ await self.load_markets()
792
+ market = self.market(symbol)
793
+ request: dict = {
794
+ 'marketCode': market['id'],
795
+ }
796
+ response = await self.publicGetV3Tickers(self.extend(request, params))
797
+ #
798
+ # {
799
+ # "success": True,
800
+ # "data": [
801
+ # {
802
+ # "marketCode": "BTC-USD-SWAP-LIN",
803
+ # "markPrice": "64276",
804
+ # "open24h": "63674",
805
+ # "high24h": "64607",
806
+ # "low24h": "62933",
807
+ # "volume24h": "306317655.80000",
808
+ # "currencyVolume24h": "48.06810",
809
+ # "openInterest": "72.39250",
810
+ # "lastTradedPrice": "64300.0",
811
+ # "lastTradedQuantity": "1.0",
812
+ # "lastUpdatedAt": "1714925196034"
813
+ # }
814
+ # ]
815
+ # }
816
+ #
817
+ data = self.safe_list(response, 'data', [])
818
+ ticker = self.safe_dict(data, 0, {})
819
+ return self.parse_ticker(ticker, market)
820
+
821
+ def parse_ticker(self, ticker, market: Market = None) -> Ticker:
822
+ #
823
+ # {
824
+ # "marketCode": "BTC-USD-SWAP-LIN",
825
+ # "markPrice": "64276",
826
+ # "open24h": "63674",
827
+ # "high24h": "64607",
828
+ # "low24h": "62933",
829
+ # "volume24h": "306317655.80000",
830
+ # "currencyVolume24h": "48.06810",
831
+ # "openInterest": "72.39250",
832
+ # "lastTradedPrice": "64300.0",
833
+ # "lastTradedQuantity": "1.0",
834
+ # "lastUpdatedAt": "1714925196034"
835
+ # }
836
+ #
837
+ timestamp = self.safe_integer(ticker, 'lastUpdatedAt')
838
+ marketId = self.safe_string(ticker, 'marketCode')
839
+ market = self.safe_market(marketId, market)
840
+ symbol = market['symbol']
841
+ last = self.safe_string(ticker, 'lastTradedPrice')
842
+ return self.safe_ticker({
843
+ 'symbol': symbol,
844
+ 'timestamp': timestamp,
845
+ 'datetime': self.iso8601(timestamp),
846
+ 'high': self.safe_string(ticker, 'high24h'),
847
+ 'low': self.safe_string(ticker, 'low24h'),
848
+ 'bid': None,
849
+ 'bidVolume': None,
850
+ 'ask': None,
851
+ 'askVolume': None,
852
+ 'vwap': None,
853
+ 'open': self.safe_string(ticker, 'open24h'),
854
+ 'close': last,
855
+ 'last': last,
856
+ 'previousClose': None,
857
+ 'change': None,
858
+ 'percentage': None,
859
+ 'average': None,
860
+ 'baseVolume': self.safe_string(ticker, 'currencyVolume24h'),
861
+ 'quoteVolume': None, # the exchange returns cost in OX
862
+ 'info': ticker,
863
+ }, market)
864
+
865
+ async def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
866
+ """
867
+ fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
868
+ :see: https://docs.ox.fun/?json#get-v3-candles
869
+ :param str symbol: unified symbol of the market to fetch OHLCV data for
870
+ :param str timeframe: the length of time each candle represents
871
+ :param int [since]: timestamp in ms of the earliest candle to fetch(default 24 hours ago)
872
+ :param int [limit]: the maximum amount of candles to fetch(default 200, max 500)
873
+ :param dict [params]: extra parameters specific to the exchange API endpoint
874
+ :param int [params.until]: timestamp in ms of the latest candle to fetch(default now)
875
+ :returns int[][]: A list of candles ordered, open, high, low, close, volume
876
+ """
877
+ await self.load_markets()
878
+ market = self.market(symbol)
879
+ timeframe = self.safe_string(self.timeframes, timeframe, timeframe)
880
+ request: dict = {
881
+ 'marketCode': market['id'],
882
+ 'timeframe': timeframe,
883
+ }
884
+ if since is not None:
885
+ request['startTime'] = since # startTime and endTime must be within 7 days of each other
886
+ if limit is not None:
887
+ request['limit'] = limit
888
+ until = self.safe_integer(params, 'until')
889
+ if until is not None:
890
+ request['endTime'] = until
891
+ params = self.omit(params, 'until')
892
+ elif since is not None:
893
+ request['endTime'] = self.sum(since, 7 * 24 * 60 * 60 * 1000) # for the exchange not to raise an exception if since is younger than 7 days
894
+ response = await self.publicGetV3Candles(self.extend(request, params))
895
+ #
896
+ # {
897
+ # "success": True,
898
+ # "timeframe": "3600s",
899
+ # "data": [
900
+ # {
901
+ # "open": "0.03240000",
902
+ # "high": "0.03240000",
903
+ # "low": "0.03240000",
904
+ # "close": "0.03240000",
905
+ # "volume": "0",
906
+ # "currencyVolume": "0",
907
+ # "openedAt": "1714906800000"
908
+ # },
909
+ # {
910
+ # "open": "0.03240000",
911
+ # "high": "0.03240000",
912
+ # "low": "0.03240000",
913
+ # "close": "0.03240000",
914
+ # "volume": "0",
915
+ # "currencyVolume": "0",
916
+ # "openedAt": "1714903200000"
917
+ # },
918
+ # ...
919
+ # ]
920
+ # }
921
+ #
922
+ result = self.safe_list(response, 'data', [])
923
+ return self.parse_ohlcvs(result, market, timeframe, since, limit)
924
+
925
+ def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
926
+ #
927
+ # {
928
+ # "open": "0.03240000",
929
+ # "high": "0.03240000",
930
+ # "low": "0.03240000",
931
+ # "close": "0.03240000",
932
+ # "volume": "0",
933
+ # "currencyVolume": "0",
934
+ # "openedAt": "1714906800000"
935
+ # }
936
+ #
937
+ return [
938
+ self.safe_integer(ohlcv, 'openedAt'),
939
+ self.safe_number(ohlcv, 'open'),
940
+ self.safe_number(ohlcv, 'high'),
941
+ self.safe_number(ohlcv, 'low'),
942
+ self.safe_number(ohlcv, 'close'),
943
+ self.safe_number(ohlcv, 'currencyVolume'),
944
+ ]
945
+
946
+ async def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
947
+ """
948
+ fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
949
+ :see: https://docs.ox.fun/?json#get-v3-depth
950
+ :param str symbol: unified symbol of the market to fetch the order book for
951
+ :param int [limit]: the maximum amount of order book entries to return(default 5, max 100)
952
+ :param dict [params]: extra parameters specific to the exchange API endpoint
953
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
954
+ """
955
+ await self.load_markets()
956
+ market = self.market(symbol)
957
+ request: dict = {
958
+ 'marketCode': market['id'],
959
+ }
960
+ if limit is not None:
961
+ request['level'] = limit
962
+ response = await self.publicGetV3Depth(self.extend(request, params))
963
+ #
964
+ # {
965
+ # "success": True,
966
+ # "level": "5",
967
+ # "data": {
968
+ # "marketCode": "BTC-USD-SWAP-LIN",
969
+ # "lastUpdatedAt": "1714933499266",
970
+ # "asks": [
971
+ # [64073.0, 8.4622],
972
+ # [64092.0, 8.1912],
973
+ # [64111.0, 8.0669],
974
+ # [64130.0, 11.7195],
975
+ # [64151.0, 10.1798]
976
+ # ],
977
+ # "bids": [
978
+ # [64022.0, 10.1292],
979
+ # [64003.0, 8.1619],
980
+ # [64000.0, 1.0],
981
+ # [63984.0, 12.7724],
982
+ # [63963.0, 11.0073]
983
+ # ]
984
+ # }
985
+ # }
986
+ #
987
+ data = self.safe_dict(response, 'data', {})
988
+ timestamp = self.safe_integer(data, 'lastUpdatedAt')
989
+ return self.parse_order_book(data, market['symbol'], timestamp)
990
+
991
+ async def fetch_funding_rates(self, symbols: Strings = None, params={}):
992
+ """
993
+ :see: https://docs.ox.fun/?json#get-v3-funding-estimates
994
+ fetch the current funding rates
995
+ :param str[] symbols: unified market symbols
996
+ :param dict [params]: extra parameters specific to the exchange API endpoint
997
+ :returns Order[]: an array of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-structure>`
998
+ """
999
+ await self.load_markets()
1000
+ symbols = self.market_symbols(symbols)
1001
+ response = await self.publicGetV3FundingEstimates(params)
1002
+ #
1003
+ # {
1004
+ # "success": True,
1005
+ # "data": [
1006
+ # {
1007
+ # "marketCode": "OX-USD-SWAP-LIN",
1008
+ # "fundingAt": "1715515200000",
1009
+ # "estFundingRate": "0.000200000"
1010
+ # },
1011
+ # {
1012
+ # "marketCode": "BTC-USD-SWAP-LIN",
1013
+ # "fundingAt": "1715515200000",
1014
+ # "estFundingRate": "0.000003"
1015
+ # },
1016
+ # ...
1017
+ # ]
1018
+ # }
1019
+ #
1020
+ data = self.safe_list(response, 'data', [])
1021
+ result = self.parse_funding_rates(data)
1022
+ return self.filter_by_array(result, 'symbol', symbols)
1023
+
1024
+ def parse_funding_rate(self, fundingRate, market: Market = None):
1025
+ #
1026
+ # {
1027
+ # "marketCode": "OX-USD-SWAP-LIN",
1028
+ # "fundingAt": "1715515200000",
1029
+ # "estFundingRate": "0.000200000"
1030
+ # },
1031
+ #
1032
+ #
1033
+ symbol = self.safe_string(fundingRate, 'marketCode')
1034
+ market = self.market(symbol)
1035
+ estFundingRateTimestamp = self.safe_integer(fundingRate, 'fundingAt')
1036
+ return {
1037
+ 'info': fundingRate,
1038
+ 'symbol': market['symbol'],
1039
+ 'markPrice': None,
1040
+ 'indexPrice': None,
1041
+ 'interestRate': self.parse_number('0'),
1042
+ 'estimatedSettlePrice': None,
1043
+ 'timestamp': estFundingRateTimestamp,
1044
+ 'datetime': self.iso8601(estFundingRateTimestamp),
1045
+ 'fundingRate': self.safe_number(fundingRate, 'estFundingRate'),
1046
+ 'fundingTimestamp': None,
1047
+ 'fundingDatetime': None,
1048
+ 'nextFundingRate': None,
1049
+ 'nextFundingTimestamp': None,
1050
+ 'nextFundingDatetime': None,
1051
+ 'previousFundingRate': None,
1052
+ 'previousFundingTimestamp': None,
1053
+ 'previousFundingDatetime': None,
1054
+ }
1055
+
1056
+ async def fetch_funding_rate_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1057
+ """
1058
+ Fetches the history of funding rates
1059
+ :see: https://docs.ox.fun/?json#get-v3-funding-rates
1060
+ :param str symbol: unified symbol of the market to fetch trades for
1061
+ :param int [since]: timestamp in ms of the earliest trade to fetch(default 24 hours ago)
1062
+ :param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
1063
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1064
+ :param int [params.until]: timestamp in ms of the latest trade to fetch(default now)
1065
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
1066
+ """
1067
+ await self.load_markets()
1068
+ market = self.market(symbol)
1069
+ request: dict = {
1070
+ 'marketCode': market['id'],
1071
+ }
1072
+ if since is not None:
1073
+ request['startTime'] = since # startTime and endTime must be within 7 days of each other
1074
+ if limit is not None:
1075
+ request['limit'] = limit
1076
+ until = self.safe_integer(params, 'until')
1077
+ if until is not None:
1078
+ request['endTime'] = until
1079
+ params = self.omit(params, 'until')
1080
+ response = await self.publicGetV3FundingRates(self.extend(request, params))
1081
+ #
1082
+ # {
1083
+ # success: True,
1084
+ # data: [
1085
+ # {
1086
+ # marketCode: 'NEAR-USD-SWAP-LIN',
1087
+ # fundingRate: '-0.000010000',
1088
+ # createdAt: '1715428870755'
1089
+ # },
1090
+ # {
1091
+ # marketCode: 'ENA-USD-SWAP-LIN',
1092
+ # fundingRate: '0.000150000',
1093
+ # createdAt: '1715428868616'
1094
+ # },
1095
+ # ...
1096
+ # }
1097
+ #
1098
+ data = self.safe_list(response, 'data', [])
1099
+ return self.parse_funding_rate_histories(data, market, since, limit)
1100
+
1101
+ def parse_funding_rate_history(self, info, market: Market = None):
1102
+ #
1103
+ # {
1104
+ # success: True,
1105
+ # data: [
1106
+ # {
1107
+ # marketCode: 'NEAR-USD-SWAP-LIN',
1108
+ # fundingRate: '-0.000010000',
1109
+ # createdAt: '1715428870755'
1110
+ # },
1111
+ # {
1112
+ # marketCode: 'ENA-USD-SWAP-LIN',
1113
+ # fundingRate: '0.000150000',
1114
+ # createdAt: '1715428868616'
1115
+ # },
1116
+ # ...
1117
+ # }
1118
+ #
1119
+ marketId = self.safe_string(info, 'marketCode')
1120
+ market = self.safe_market(marketId, market)
1121
+ symbol = market['symbol']
1122
+ timestamp = self.safe_integer(info, 'createdAt')
1123
+ return {
1124
+ 'info': info,
1125
+ 'symbol': symbol,
1126
+ 'fundingRate': self.safe_number(info, 'fundingRate'),
1127
+ 'timestamp': timestamp,
1128
+ 'datetime': self.iso8601(timestamp),
1129
+ }
1130
+
1131
+ async def fetch_funding_history(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1132
+ """
1133
+ fetches the history of funding payments
1134
+ :see: https://docs.ox.fun/?json#get-v3-funding
1135
+ :param str symbol: unified symbol of the market to fetch trades for
1136
+ :param int [since]: timestamp in ms of the earliest trade to fetch(default 24 hours ago)
1137
+ :param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
1138
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1139
+ :param int [params.until]: timestamp in ms of the latest trade to fetch(default now)
1140
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
1141
+ """
1142
+ await self.load_markets()
1143
+ market = self.market(symbol)
1144
+ request: dict = {
1145
+ 'marketCode': market['id'],
1146
+ }
1147
+ if since is not None:
1148
+ request['startTime'] = since # startTime and endTime must be within 7 days of each other
1149
+ if limit is not None:
1150
+ request['limit'] = limit
1151
+ until = self.safe_integer(params, 'until')
1152
+ if until is not None:
1153
+ request['endTime'] = until
1154
+ params = self.omit(params, 'until')
1155
+ response = await self.privateGetV3Funding(self.extend(request, params))
1156
+ #
1157
+ # {
1158
+ # success: True,
1159
+ # data: [
1160
+ # {
1161
+ # id: '966709913041305605',
1162
+ # marketCode: 'ETH-USD-SWAP-LIN',
1163
+ # payment: '-0.00430822',
1164
+ # fundingRate: '0.000014',
1165
+ # position: '0.001',
1166
+ # indexPrice: '3077.3',
1167
+ # createdAt: '1715086852890'
1168
+ # },
1169
+ # {
1170
+ # id: '966698111997509637',
1171
+ # marketCode: 'ETH-USD-SWAP-LIN',
1172
+ # payment: '-0.0067419',
1173
+ # fundingRate: '0.000022',
1174
+ # position: '0.001',
1175
+ # indexPrice: '3064.5',
1176
+ # createdAt: '1715083251516'
1177
+ # },
1178
+ # ...
1179
+ # ]
1180
+ # }
1181
+ #
1182
+ result = self.safe_list(response, 'data', [])
1183
+ return self.parse_incomes(result, market, since, limit)
1184
+
1185
+ def parse_income(self, income, market: Market = None):
1186
+ #
1187
+ # {
1188
+ # id: '966709913041305605',
1189
+ # marketCode: 'ETH-USD-SWAP-LIN',
1190
+ # payment: '-0.00430822',
1191
+ # fundingRate: '0.000014',
1192
+ # position: '0.001',
1193
+ # indexPrice: '3077.3',
1194
+ # createdAt: '1715086852890'
1195
+ # },
1196
+ #
1197
+ marketId = self.safe_string(income, 'marketCode')
1198
+ symbol = self.safe_symbol(marketId, market)
1199
+ amount = self.safe_number(income, 'payment')
1200
+ code = self.safe_currency_code('OX')
1201
+ id = self.safe_string(income, 'id')
1202
+ timestamp = self.safe_timestamp(income, 'createdAt')
1203
+ rate = self.safe_number(income, 'fundingRate')
1204
+ return {
1205
+ 'info': income,
1206
+ 'symbol': symbol,
1207
+ 'code': code,
1208
+ 'timestamp': timestamp,
1209
+ 'datetime': self.iso8601(timestamp),
1210
+ 'id': id,
1211
+ 'amount': amount,
1212
+ 'rate': rate,
1213
+ }
1214
+
1215
+ async def fetch_leverage_tiers(self, symbols: Strings = None, params={}):
1216
+ """
1217
+ retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes, if a market has a leverage tier of 0, then the leverage tiers cannot be obtained for self market
1218
+ :see: https://docs.ox.fun/?json#get-v3-leverage-tiers
1219
+ :param str[] [symbols]: list of unified market symbols
1220
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1221
+ :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`, indexed by market symbols
1222
+ """
1223
+ await self.load_markets()
1224
+ response = await self.publicGetV3LeverageTiers(params)
1225
+ #
1226
+ # {
1227
+ # success: True,
1228
+ # data: [
1229
+ # {
1230
+ # marketCode: 'SOL-USD-SWAP-LIN',
1231
+ # tiers: [
1232
+ # {
1233
+ # tier: '1',
1234
+ # leverage: '10',
1235
+ # positionFloor: '0',
1236
+ # positionCap: '200000000',
1237
+ # initialMargin: '0.1',
1238
+ # maintenanceMargin: '0.05',
1239
+ # maintenanceAmount: '0'
1240
+ # },
1241
+ # {
1242
+ # tier: '2',
1243
+ # leverage: '5',
1244
+ # positionFloor: '200000000',
1245
+ # positionCap: '280000000',
1246
+ # initialMargin: '0.2',
1247
+ # maintenanceMargin: '0.1',
1248
+ # maintenanceAmount: '7000000'
1249
+ # },
1250
+ # {
1251
+ # tier: '3',
1252
+ # leverage: '4',
1253
+ # positionFloor: '280000000',
1254
+ # positionCap: '460000000',
1255
+ # initialMargin: '0.25',
1256
+ # maintenanceMargin: '0.125',
1257
+ # maintenanceAmount: '14000000'
1258
+ # },
1259
+ # ...
1260
+ # ]
1261
+ # },
1262
+ # ...
1263
+ # ]
1264
+ # }
1265
+ #
1266
+ data = self.safe_list(response, 'data', [])
1267
+ return self.parse_leverage_tiers(data, symbols, 'marketCode')
1268
+
1269
+ def parse_market_leverage_tiers(self, info, market: Market = None):
1270
+ #
1271
+ # {
1272
+ # marketCode: 'SOL-USD-SWAP-LIN',
1273
+ # tiers: [
1274
+ # {
1275
+ # tier: '1',
1276
+ # leverage: '10',
1277
+ # positionFloor: '0',
1278
+ # positionCap: '200000000',
1279
+ # initialMargin: '0.1',
1280
+ # maintenanceMargin: '0.05',
1281
+ # maintenanceAmount: '0'
1282
+ # ...
1283
+ # ]
1284
+ # },
1285
+ #
1286
+ marketId = self.safe_string(info, 'marketCode')
1287
+ market = self.safe_market(marketId, market)
1288
+ listOfTiers = self.safe_list(info, 'tiers', [])
1289
+ tiers = []
1290
+ for j in range(0, len(listOfTiers)):
1291
+ tier = listOfTiers[j]
1292
+ tiers.append({
1293
+ 'tier': self.safe_number(tier, 'tier'),
1294
+ 'currency': market['settle'],
1295
+ 'minNotional': self.safe_number(tier, 'positionFloor'),
1296
+ 'maxNotional': self.safe_number(tier, 'positionCap'),
1297
+ 'maintenanceMarginRate': self.safe_number(tier, 'maintenanceMargin'),
1298
+ 'maxLeverage': self.safe_number(tier, 'leverage'),
1299
+ 'info': tier,
1300
+ })
1301
+ return tiers
1302
+
1303
+ async def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
1304
+ """
1305
+ get the list of most recent trades for a particular symbol
1306
+ :see: https://docs.ox.fun/?json#get-v3-exchange-trades
1307
+ :param str symbol: unified symbol of the market to fetch trades for
1308
+ :param int [since]: timestamp in ms of the earliest trade to fetch(default 24 hours ago)
1309
+ :param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
1310
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1311
+ :param int [params.until]: timestamp in ms of the latest trade to fetch(default now)
1312
+ :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
1313
+ """
1314
+ await self.load_markets()
1315
+ market = self.market(symbol)
1316
+ request: dict = {
1317
+ 'marketCode': market['id'],
1318
+ }
1319
+ if since is not None:
1320
+ request['startTime'] = since # startTime and endTime must be within 7 days of each other
1321
+ if limit is not None:
1322
+ request['limit'] = limit
1323
+ until = self.safe_integer(params, 'until')
1324
+ if until is not None:
1325
+ request['endTime'] = until
1326
+ params = self.omit(params, 'until')
1327
+ elif since is not None:
1328
+ request['endTime'] = self.sum(since, 7 * 24 * 60 * 60 * 1000) # for the exchange not to raise an exception if since is younger than 7 days
1329
+ response = await self.publicGetV3ExchangeTrades(self.extend(request, params))
1330
+ #
1331
+ # {
1332
+ # "success": True,
1333
+ # "data": [
1334
+ # {
1335
+ # "marketCode": "BTC-USD-SWAP-LIN",
1336
+ # "matchPrice": "63900",
1337
+ # "matchQuantity": "1",
1338
+ # "side": "SELL",
1339
+ # "matchType": "TAKER",
1340
+ # "matchedAt": "1714934112352"
1341
+ # },
1342
+ # ...
1343
+ # ]
1344
+ # }
1345
+ #
1346
+ data = self.safe_list(response, 'data', [])
1347
+ return self.parse_trades(data, market, since, limit)
1348
+
1349
+ async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1350
+ """
1351
+ fetch all trades made by the user
1352
+ :see: https://docs.ox.fun/?json#get-v3-trades
1353
+ :param str symbol: unified market symbol
1354
+ :param int [since]: the earliest time in ms to fetch trades for
1355
+ :param int [limit]: the maximum amount of trades to fetch(default 200, max 500)
1356
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1357
+ :param int [params.until]: timestamp in ms of the latest trade to fetch(default now)
1358
+ :returns Trade[]: a list of `trade structures <https://github.com/ccxt/ccxt/wiki/Manual#trade-structure>`
1359
+ """
1360
+ await self.load_markets()
1361
+ request: dict = {}
1362
+ market: Market = None
1363
+ if symbol is not None:
1364
+ market = self.market(symbol)
1365
+ request['marketCode'] = market['id']
1366
+ if since is not None: # startTime and endTime must be within 7 days of each other
1367
+ request['startTime'] = since
1368
+ if limit is not None:
1369
+ request['limit'] = limit
1370
+ until = self.safe_integer(params, 'until')
1371
+ if until is not None:
1372
+ request['endTime'] = until
1373
+ params = self.omit(params, 'until')
1374
+ elif since is not None:
1375
+ request['endTime'] = self.sum(since, 7 * 24 * 60 * 60 * 1000) # for the exchange not to raise an exception if since is younger than 7 days
1376
+ response = await self.privateGetV3Trades(self.extend(request, params))
1377
+ #
1378
+ # {
1379
+ # "success": True,
1380
+ # "data": [
1381
+ # {
1382
+ # "orderId": "1000104903698",
1383
+ # "clientOrderId": "1715000260094",
1384
+ # "matchId": "400017129522773178",
1385
+ # "marketCode": "ETH-USD-SWAP-LIN",
1386
+ # "side": "BUY",
1387
+ # "matchedQuantity": "0.001",
1388
+ # "matchPrice": "3100.2",
1389
+ # "total": "310.02",
1390
+ # "orderMatchType": "MAKER",
1391
+ # "feeAsset": "OX",
1392
+ # "fee": "0.062004",
1393
+ # "source": "0",
1394
+ # "matchedAt": "1715000267420"
1395
+ # }
1396
+ # ]
1397
+ # }
1398
+ #
1399
+ result = self.safe_list(response, 'data', [])
1400
+ return self.parse_trades(result, market, since, limit)
1401
+
1402
+ def parse_trade(self, trade, market: Market = None) -> Trade:
1403
+ #
1404
+ # public fetchTrades
1405
+ #
1406
+ # {
1407
+ # "marketCode": "BTC-USD-SWAP-LIN",
1408
+ # "matchPrice": "63900",
1409
+ # "matchQuantity": "1",
1410
+ # "side": "SELL",
1411
+ # "matchType": "TAKER",
1412
+ # "matchedAt": "1714934112352"
1413
+ # }
1414
+ #
1415
+ #
1416
+ # private fetchMyTrades
1417
+ #
1418
+ # {
1419
+ # "orderId": "1000104903698",
1420
+ # "clientOrderId": "1715000260094",
1421
+ # "matchId": "400017129522773178",
1422
+ # "marketCode": "ETH-USD-SWAP-LIN",
1423
+ # "side": "BUY",
1424
+ # "matchedQuantity": "0.001",
1425
+ # "matchPrice": "3100.2",
1426
+ # "total": "310.02",
1427
+ # "orderMatchType": "MAKER",
1428
+ # "feeAsset": "OX",
1429
+ # "fee": "0.062004",
1430
+ # "source": "0",
1431
+ # "matchedAt": "1715000267420"
1432
+ # }
1433
+ #
1434
+ marketId = self.safe_string(trade, 'marketCode')
1435
+ market = self.safe_market(marketId, market)
1436
+ symbol = market['symbol']
1437
+ timestamp = self.safe_integer(trade, 'matchedAt')
1438
+ fee = {
1439
+ 'cost': self.safe_string(trade, 'fee'),
1440
+ 'currency': self.safe_currency_code(self.safe_string(trade, 'feeAsset')),
1441
+ }
1442
+ return self.safe_trade({
1443
+ 'id': self.safe_string(trade, 'matchId'),
1444
+ 'timestamp': timestamp,
1445
+ 'datetime': self.iso8601(timestamp),
1446
+ 'symbol': symbol,
1447
+ 'type': None,
1448
+ 'order': self.safe_string(trade, 'orderId'),
1449
+ 'side': self.safe_string_lower(trade, 'side'),
1450
+ 'takerOrMaker': self.safe_string_lower_2(trade, 'matchType', 'orderMatchType'),
1451
+ 'price': self.safe_string(trade, 'matchPrice'),
1452
+ 'amount': self.safe_string_2(trade, 'matchQuantity', 'matchedQuantity'),
1453
+ 'cost': None, # the exchange returns total cost in OX
1454
+ 'fee': fee,
1455
+ 'info': trade,
1456
+ }, market)
1457
+
1458
+ async def fetch_balance(self, params={}) -> Balances:
1459
+ """
1460
+ query for balance and get the amount of funds available for trading or funds locked in orders
1461
+ :see: https://docs.ox.fun/?json#get-v3-balances
1462
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1463
+ :param str [params.asset]: currency id, if empty the exchange returns info about all currencies
1464
+ :param str [params.subAcc]: Name of sub account. If no subAcc is given, then the response contains only the account linked to the API-Key.
1465
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
1466
+ """
1467
+ await self.load_markets()
1468
+ response = await self.privateGetV3Balances(params)
1469
+ #
1470
+ # {
1471
+ # "success": True,
1472
+ # "data": [
1473
+ # {
1474
+ # "accountId": "106490",
1475
+ # "name": "main",
1476
+ # "balances": [
1477
+ # {
1478
+ # "asset": "OX",
1479
+ # "total": "-7.55145065000",
1480
+ # "available": "-71.16445065000",
1481
+ # "reserved": "0",
1482
+ # "lastUpdatedAt": "1715000448946"
1483
+ # },
1484
+ # {
1485
+ # "asset": "ETH",
1486
+ # "total": "0.01",
1487
+ # "available": "0.01",
1488
+ # "reserved": "0",
1489
+ # "lastUpdatedAt": "1714914512750"
1490
+ # },
1491
+ # ...
1492
+ # ]
1493
+ # },
1494
+ # ...
1495
+ # ]
1496
+ # }
1497
+ #
1498
+ data = self.safe_list(response, 'data', [])
1499
+ balance = data[0]
1500
+ subAcc = self.safe_string(params, 'subAcc')
1501
+ if subAcc is not None:
1502
+ for i in range(0, len(data)):
1503
+ b = data[i]
1504
+ name = self.safe_string(b, 'name')
1505
+ if name == subAcc:
1506
+ balance = b
1507
+ break
1508
+ return self.parse_balance(balance)
1509
+
1510
+ def parse_balance(self, balance) -> Balances:
1511
+ #
1512
+ # {
1513
+ # "accountId": "106490",
1514
+ # "name": "main",
1515
+ # "balances": [
1516
+ # {
1517
+ # "asset": "OX",
1518
+ # "total": "-7.55145065000",
1519
+ # "available": "-71.16445065000",
1520
+ # "reserved": "0",
1521
+ # "lastUpdatedAt": "1715000448946"
1522
+ # },
1523
+ # {
1524
+ # "asset": "ETH",
1525
+ # "total": "0.01",
1526
+ # "available": "0.01",
1527
+ # "reserved": "0",
1528
+ # "lastUpdatedAt": "1714914512750"
1529
+ # },
1530
+ # ...
1531
+ # ]
1532
+ # }
1533
+ #
1534
+ result: dict = {
1535
+ 'info': balance,
1536
+ }
1537
+ balances = self.safe_list(balance, 'balances', [])
1538
+ for i in range(0, len(balances)):
1539
+ balanceEntry = balances[i]
1540
+ currencyId = self.safe_string(balanceEntry, 'asset')
1541
+ code = self.safe_currency_code(currencyId)
1542
+ account = self.account()
1543
+ account['total'] = self.safe_string(balanceEntry, 'total')
1544
+ account['free'] = self.safe_string(balanceEntry, 'available')
1545
+ account['used'] = self.safe_string(balanceEntry, 'reserved')
1546
+ result[code] = account
1547
+ return self.safe_balance(result)
1548
+
1549
+ async def fetch_accounts(self, params={}) -> List[Account]:
1550
+ """
1551
+ fetch subaccounts associated with a profile
1552
+ :see: https://docs.ox.fun/?json#get-v3-account-names
1553
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1554
+ :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
1555
+ """
1556
+ await self.load_markets()
1557
+ # self endpoint can only be called using API keys paired with the parent account! Returns all active subaccounts.
1558
+ response = await self.privateGetV3AccountNames(params)
1559
+ #
1560
+ # {
1561
+ # "success": True,
1562
+ # "data": [
1563
+ # {
1564
+ # "accountId": "106526",
1565
+ # "name": "testSubAccount"
1566
+ # },
1567
+ # ...
1568
+ # ]
1569
+ # }
1570
+ #
1571
+ data = self.safe_list(response, 'data', [])
1572
+ return self.parse_accounts(data, params)
1573
+
1574
+ def parse_account(self, account):
1575
+ #
1576
+ # {
1577
+ # "accountId": "106526",
1578
+ # "name": "testSubAccount"
1579
+ # },
1580
+ #
1581
+ return {
1582
+ 'id': self.safe_string(account, 'accountId'),
1583
+ 'type': None,
1584
+ 'code': None,
1585
+ 'info': account,
1586
+ }
1587
+
1588
+ async def transfer(self, code: str, amount: float, fromAccount: str, toAccount: str, params={}) -> TransferEntry:
1589
+ """
1590
+ transfer currency internally between wallets on the same account
1591
+ :see: https://docs.ox.fun/?json#post-v3-transfer
1592
+ :param str code: unified currency code
1593
+ :param float amount: amount to transfer
1594
+ :param str fromAccount: account id to transfer from
1595
+ :param str toAccount: account id to transfer to
1596
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1597
+ :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
1598
+ """
1599
+ # transferring funds between sub-accounts is restricted to API keys linked to the parent account.
1600
+ await self.load_markets()
1601
+ currency = self.currency(code)
1602
+ request: dict = {
1603
+ 'asset': currency['id'],
1604
+ 'quantity': self.currency_to_precision(code, amount),
1605
+ 'fromAccount': fromAccount,
1606
+ 'toAccount': toAccount,
1607
+ }
1608
+ response = await self.privatePostV3Transfer(self.extend(request, params))
1609
+ #
1610
+ # {
1611
+ # timestamp: 1715430036267,
1612
+ # datetime: '2024-05-11T12:20:36.267Z',
1613
+ # currency: 'OX',
1614
+ # amount: 10,
1615
+ # fromAccount: '106464',
1616
+ # toAccount: '106570',
1617
+ # info: {
1618
+ # asset: 'OX',
1619
+ # quantity: '10',
1620
+ # fromAccount: '106464',
1621
+ # toAccount: '106570',
1622
+ # transferredAt: '1715430036267'
1623
+ # }
1624
+ # }
1625
+ #
1626
+ data = self.safe_dict(response, 'data', {})
1627
+ return self.parse_transfer(data, currency)
1628
+
1629
+ async def fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params={}):
1630
+ """
1631
+ fetch a history of internal transfers made on an account
1632
+ :see: https://docs.ox.fun/?json#get-v3-transfer
1633
+ :param str code: unified currency code of the currency transferred
1634
+ :param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
1635
+ :param int [limit]: the maximum number of transfer structures to retrieve(default 50, max 200)
1636
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1637
+ :param int [params.until]: the latest time in ms to fetch transfers for(default time now)
1638
+ :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
1639
+ """
1640
+ # API keys linked to the parent account can get all account transfers, while API keys linked to a sub-account can only see transfers where the sub-account is either the "fromAccount" or "toAccount"
1641
+ await self.load_markets()
1642
+ request: dict = {}
1643
+ currency: Currency = None
1644
+ if code is not None:
1645
+ currency = self.currency(code)
1646
+ request['asset'] = currency['id']
1647
+ if since is not None:
1648
+ request['startTime'] = since # startTime and endTime must be within 7 days of each other
1649
+ if limit is not None:
1650
+ request['limit'] = limit
1651
+ until = self.safe_integer(params, 'until')
1652
+ if until is not None:
1653
+ request['endTime'] = until
1654
+ params = self.omit(params, 'until')
1655
+ elif since is not None:
1656
+ request['endTime'] = self.sum(since, 7 * 24 * 60 * 60 * 1000) # for the exchange not to raise an exception if since is younger than 7 days
1657
+ response = await self.privateGetV3Transfer(self.extend(request, params))
1658
+ #
1659
+ # {
1660
+ # "success": True,
1661
+ # "data": [
1662
+ # {
1663
+ # "asset": "USDT",
1664
+ # "quantity": "5",
1665
+ # "fromAccount": "106490",
1666
+ # "toAccount": "106526",
1667
+ # "id": "966706320886267905",
1668
+ # "status": "COMPLETED",
1669
+ # "transferredAt": "1715085756708"
1670
+ # },
1671
+ # ...
1672
+ # ]
1673
+ # }
1674
+ #
1675
+ data = self.safe_list(response, 'data', [])
1676
+ return self.parse_transfers(data, currency, since, limit)
1677
+
1678
+ def parse_transfer(self, transfer, currency: Currency = None):
1679
+ #
1680
+ # fetchTransfers
1681
+ #
1682
+ # {
1683
+ # "asset": "USDT",
1684
+ # "quantity": "5",
1685
+ # "fromAccount": "106490",
1686
+ # "toAccount": "106526",
1687
+ # "id": "966706320886267905",
1688
+ # "status": "COMPLETED",
1689
+ # "transferredAt": "1715085756708"
1690
+ # }
1691
+ #
1692
+ timestamp = self.safe_integer(transfer, 'transferredAt')
1693
+ currencyId = self.safe_string(transfer, 'asset')
1694
+ return {
1695
+ 'id': self.safe_string(transfer, 'id'),
1696
+ 'timestamp': timestamp,
1697
+ 'datetime': self.iso8601(timestamp),
1698
+ 'currency': self.safe_currency_code(currencyId, currency),
1699
+ 'amount': self.safe_number(transfer, 'quantity'),
1700
+ 'fromAccount': self.safe_string(transfer, 'fromAccount'),
1701
+ 'toAccount': self.safe_string(transfer, 'toAccount'),
1702
+ 'status': self.parse_transfer_status(self.safe_string(transfer, 'status')),
1703
+ 'info': transfer,
1704
+ }
1705
+
1706
+ def parse_transfer_status(self, status):
1707
+ statuses: dict = {
1708
+ 'COMPLETED': 'ok',
1709
+ }
1710
+ return self.safe_string(statuses, status, status)
1711
+
1712
+ async def fetch_deposit_address(self, code: str, params={}):
1713
+ """
1714
+ fetch the deposit address for a currency associated with self account
1715
+ :see: https://docs.ox.fun/?json#get-v3-deposit-addresses
1716
+ :param str code: unified currency code
1717
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1718
+ :param str [params.network]: network for fetch deposit address
1719
+ :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
1720
+ """
1721
+ networkCode = self.safe_string(params, 'network')
1722
+ networkId = self.network_code_to_id(networkCode, code)
1723
+ if networkId is None:
1724
+ raise BadRequest(self.id + ' fetchDepositAddress() require network parameter')
1725
+ await self.load_markets()
1726
+ currency = self.currency(code)
1727
+ request: dict = {
1728
+ 'asset': currency['id'],
1729
+ 'network': networkId,
1730
+ }
1731
+ params = self.omit(params, 'network')
1732
+ response = await self.privateGetV3DepositAddresses(self.extend(request, params))
1733
+ #
1734
+ # {"success":true,"data":{"address":"0x998dEc76151FB723963Bd8AFD517687b38D33dE8"}}
1735
+ #
1736
+ data = self.safe_dict(response, 'data', {})
1737
+ return self.parse_deposit_address(data, currency)
1738
+
1739
+ def parse_deposit_address(self, depositAddress, currency: Currency = None):
1740
+ #
1741
+ # {"address":"0x998dEc76151FB723963Bd8AFD517687b38D33dE8"}
1742
+ #
1743
+ address = self.safe_string(depositAddress, 'address')
1744
+ self.check_address(address)
1745
+ return {
1746
+ 'currency': currency['code'],
1747
+ 'address': address,
1748
+ 'tag': None,
1749
+ 'network': None,
1750
+ 'info': depositAddress,
1751
+ }
1752
+
1753
+ async def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
1754
+ """
1755
+ fetch all deposits made to an account
1756
+ :see: https://docs.ox.fun/?json#get-v3-deposit
1757
+ :param str code: unified currency code of the currency transferred
1758
+ :param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
1759
+ :param int [limit]: the maximum number of transfer structures to retrieve(default 50, max 200)
1760
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1761
+ :param int [params.until]: the latest time in ms to fetch transfers for(default time now)
1762
+ :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
1763
+ """
1764
+ await self.load_markets()
1765
+ request: dict = {}
1766
+ currency: Currency = None
1767
+ if code is not None:
1768
+ currency = self.currency(code)
1769
+ request['asset'] = currency['id']
1770
+ if since is not None:
1771
+ request['startTime'] = since # startTime and endTime must be within 7 days of each other
1772
+ if limit is not None:
1773
+ request['limit'] = limit
1774
+ until = self.safe_integer(params, 'until')
1775
+ if until is not None:
1776
+ request['endTime'] = until
1777
+ params = self.omit(params, 'until')
1778
+ response = await self.privateGetV3Deposit(self.extend(request, params))
1779
+ #
1780
+ # {
1781
+ # "success": True,
1782
+ # "data": [
1783
+ # {
1784
+ # "asset":"USDC",
1785
+ # "network":"Ethereum",
1786
+ # "address": "0x998dEc76151FB723963Bd8AFD517687b38D33dE8",
1787
+ # "quantity":"50",
1788
+ # "id":"5914",
1789
+ # "status": "COMPLETED",
1790
+ # "txId":"0xf5e79663830a0c6f94d46638dcfbc134566c12facf1832396f81ecb55d3c75dc",
1791
+ # "creditedAt":"1714821645154"
1792
+ # }
1793
+ # ]
1794
+ # }
1795
+ #
1796
+ data = self.safe_list(response, 'data', [])
1797
+ for i in range(0, len(data)):
1798
+ data[i]['type'] = 'deposit'
1799
+ return self.parse_transactions(data, currency, since, limit)
1800
+
1801
+ async def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
1802
+ """
1803
+ fetch all withdrawals made from an account
1804
+ :see: https://docs.ox.fun/?json#get-v3-withdrawal
1805
+ :param str code: unified currency code of the currency transferred
1806
+ :param int [since]: the earliest time in ms to fetch transfers for(default 24 hours ago)
1807
+ :param int [limit]: the maximum number of transfer structures to retrieve(default 50, max 200)
1808
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1809
+ :param int [params.until]: the latest time in ms to fetch transfers for(default time now)
1810
+ :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
1811
+ """
1812
+ await self.load_markets()
1813
+ request: dict = {}
1814
+ currency: Currency = None
1815
+ if code is not None:
1816
+ currency = self.currency(code)
1817
+ request['asset'] = currency['id']
1818
+ if since is not None:
1819
+ request['startTime'] = since # startTime and endTime must be within 7 days of each other
1820
+ if limit is not None:
1821
+ request['limit'] = limit
1822
+ until = self.safe_integer(params, 'until')
1823
+ if until is not None:
1824
+ request['endTime'] = until
1825
+ params = self.omit(params, 'until')
1826
+ response = await self.privateGetV3Withdrawal(self.extend(request, params))
1827
+ #
1828
+ # {
1829
+ # success: True,
1830
+ # data: [
1831
+ # {
1832
+ # id: '968163212989431811',
1833
+ # asset: 'OX',
1834
+ # network: 'Arbitrum',
1835
+ # address: '0x90fc1fB49a4ED8f485dd02A2a1Cf576897f6Bfc9',
1836
+ # quantity: '11.7444',
1837
+ # fee: '1.744400000',
1838
+ # status: 'COMPLETED',
1839
+ # txId: '0xe96b2d128b737fdbca927edf355cff42202e65b0fb960e64ffb9bd68c121f69f',
1840
+ # requestedAt: '1715530365450',
1841
+ # completedAt: '1715530527000'
1842
+ # }
1843
+ # ]
1844
+ # }
1845
+ #
1846
+ data = self.safe_list(response, 'data', [])
1847
+ for i in range(0, len(data)):
1848
+ data[i]['type'] = 'withdrawal'
1849
+ return self.parse_transactions(data, currency, since, limit)
1850
+
1851
+ def parse_transactions(self, transactions, currency: Currency = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
1852
+ result = []
1853
+ for i in range(0, len(transactions)):
1854
+ transactions[i] = self.extend(transactions[i], params)
1855
+ transaction = self.parse_transaction(transactions[i], currency)
1856
+ result.append(transaction)
1857
+ result = self.sort_by(result, 'timestamp')
1858
+ code = currency['code'] if (currency is not None) else None
1859
+ return self.filter_by_currency_since_limit(result, code, since, limit)
1860
+
1861
+ def parse_transaction(self, transaction, currency: Currency = None) -> Transaction:
1862
+ #
1863
+ # fetchDeposits
1864
+ # {
1865
+ # "asset":"USDC",
1866
+ # "network":"Ethereum",
1867
+ # "address": "0x998dEc76151FB723963Bd8AFD517687b38D33dE8",
1868
+ # "quantity":"50",
1869
+ # "id":"5914",
1870
+ # "status": "COMPLETED",
1871
+ # "txId":"0xf5e79663830a0c6f94d46638dcfbc134566c12facf1832396f81ecb55d3c75dc",
1872
+ # "creditedAt":"1714821645154"
1873
+ # }
1874
+ #
1875
+ # fetchWithdrawals
1876
+ # {
1877
+ # id: '968163212989431811',
1878
+ # asset: 'OX',
1879
+ # network: 'Arbitrum',
1880
+ # address: '0x90fc1fB49a4ED8f485dd02A2a1Cf576897f6Bfc9',
1881
+ # quantity: '11.7444',
1882
+ # fee: '1.744400000',
1883
+ # status: 'COMPLETED',
1884
+ # txId: '0xe96b2d128b737fdbca927edf355cff42202e65b0fb960e64ffb9bd68c121f69f',
1885
+ # requestedAt: '1715530365450',
1886
+ # completedAt: '1715530527000'
1887
+ # }
1888
+ #
1889
+ # withdraw
1890
+ # {
1891
+ # "id": "968364664449302529",
1892
+ # "asset": "OX",
1893
+ # "network": "Arbitrum",
1894
+ # "address": "0x90fc1fB49a4ED8f485dd02A2a1Cf576897f6Bfc9",
1895
+ # "quantity": "10",
1896
+ # "externalFee": False,
1897
+ # "fee": "1.6728",
1898
+ # "status": "PENDING",
1899
+ # "requestedAt": "1715591843616"
1900
+ # }
1901
+ #
1902
+ id = self.safe_string(transaction, 'id')
1903
+ type = self.safe_string(transaction, 'type')
1904
+ transaction = self.omit(transaction, 'type')
1905
+ address: Str = None
1906
+ addressTo: Str = None
1907
+ status: Str = None
1908
+ if type == 'deposit':
1909
+ address = self.safe_string(transaction, 'address')
1910
+ status = self.parse_deposit_status(self.safe_string(transaction, 'status'))
1911
+ elif type == 'withdrawal':
1912
+ addressTo = self.safe_string(transaction, 'address')
1913
+ status = self.parse_withdrawal_status(self.safe_string(transaction, 'status'))
1914
+ txid = self.safe_string(transaction, 'txId')
1915
+ currencyId = self.safe_string(transaction, 'asset')
1916
+ code = self.safe_currency_code(currencyId, currency)
1917
+ network = self.safe_string(transaction, 'network')
1918
+ networkCode = self.network_id_to_code(network)
1919
+ timestamp = self.safe_integer_2(transaction, 'creditedAt', 'requestedAt')
1920
+ amount = self.safe_number(transaction, 'quantity')
1921
+ feeCost = self.safe_number(transaction, 'fee')
1922
+ fee = None
1923
+ if feeCost is not None:
1924
+ fee = {
1925
+ 'cost': feeCost,
1926
+ 'currency': code,
1927
+ }
1928
+ return {
1929
+ 'info': transaction,
1930
+ 'id': id,
1931
+ 'txid': txid,
1932
+ 'timestamp': timestamp,
1933
+ 'datetime': self.iso8601(timestamp),
1934
+ 'network': networkCode,
1935
+ 'address': address,
1936
+ 'addressTo': addressTo,
1937
+ 'addressFrom': None,
1938
+ 'tag': None,
1939
+ 'tagTo': None,
1940
+ 'tagFrom': None,
1941
+ 'type': type,
1942
+ 'amount': amount,
1943
+ 'currency': code,
1944
+ 'status': status,
1945
+ 'updated': None,
1946
+ 'internal': None,
1947
+ 'comment': None,
1948
+ 'fee': fee,
1949
+ }
1950
+
1951
+ def parse_deposit_status(self, status):
1952
+ statuses: dict = {
1953
+ 'COMPLETED': 'ok',
1954
+ }
1955
+ return self.safe_string(statuses, status, status)
1956
+
1957
+ def parse_withdrawal_status(self, status):
1958
+ statuses: dict = {
1959
+ 'COMPLETED': 'ok',
1960
+ 'PROCESSING': 'pending',
1961
+ 'IN SWEEPING': 'pending',
1962
+ 'PENDING': 'pending',
1963
+ 'ON HOLD': 'pending',
1964
+ 'CANCELED': 'canceled',
1965
+ 'FAILED': 'failed',
1966
+ }
1967
+ return self.safe_string(statuses, status, status)
1968
+
1969
+ async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
1970
+ """
1971
+ make a withdrawal
1972
+ :see: https://docs.bitflex.com/spot#withdraw
1973
+ :param str code: unified currency code
1974
+ :param float amount: the amount to withdraw
1975
+ :param str address: the address to withdraw to
1976
+ :param str tag:
1977
+ :param str [params.network]: network for withdraw
1978
+ :param bool [params.externalFee]: if False, then the fee is taken from the quantity, also with the burn fee for asset SOLO
1979
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1980
+ *
1981
+ * EXCHANGE SPECIFIC PARAMETERS
1982
+ :param str [params.tfaType]: GOOGLE, or AUTHY_SECRET, or YUBIKEY, for 2FA
1983
+ :param str [params.code]: 2FA code
1984
+ :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
1985
+ """
1986
+ tag, params = self.handle_withdraw_tag_and_params(tag, params)
1987
+ await self.load_markets()
1988
+ currency = self.currency(code)
1989
+ stringAmount = self.currency_to_precision(code, amount)
1990
+ request: dict = {
1991
+ 'asset': currency['id'],
1992
+ 'address': address,
1993
+ 'quantity': stringAmount,
1994
+ }
1995
+ if tag is not None:
1996
+ request['memo'] = tag
1997
+ networkCode: Str = None
1998
+ networkCode, params = self.handle_network_code_and_params(params)
1999
+ if networkCode is not None:
2000
+ request['network'] = self.network_code_to_id(networkCode)
2001
+ request['externalFee'] = False
2002
+ response = await self.privatePostV3Withdrawal(self.extend(request, params))
2003
+ #
2004
+ # {
2005
+ # "success": True,
2006
+ # "data": {
2007
+ # "id": "968364664449302529",
2008
+ # "asset": "OX",
2009
+ # "network": "Arbitrum",
2010
+ # "address": "0x90fc1fB49a4ED8f485dd02A2a1Cf576897f6Bfc9",
2011
+ # "quantity": "10",
2012
+ # "externalFee": False,
2013
+ # "fee": "1.6728",
2014
+ # "status": "PENDING",
2015
+ # "requestedAt": "1715591843616"
2016
+ # }
2017
+ # }
2018
+ #
2019
+ data = self.safe_dict(response, 'data', {})
2020
+ data['type'] = 'withdrawal'
2021
+ return self.parse_transaction(data, currency)
2022
+
2023
+ async def fetch_positions(self, symbols: Strings = None, params={}):
2024
+ """
2025
+ fetch all open positions
2026
+ :see: https://docs.ox.fun/?json#get-v3-positions
2027
+ :param str[]|None symbols: list of unified market symbols
2028
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2029
+ :param boolean [params.subAcc]:
2030
+ :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
2031
+ """
2032
+ # Calling self endpoint using an API key pair linked to the parent account with the parameter "subAcc"
2033
+ # allows the caller to include positions of additional sub-accounts in the response.
2034
+ # This feature does not work when using API key pairs linked to a sub-account
2035
+ await self.load_markets()
2036
+ symbols = self.market_symbols(symbols)
2037
+ response = await self.privateGetV3Positions(params)
2038
+ #
2039
+ # {
2040
+ # "success": True,
2041
+ # "data": [
2042
+ # {
2043
+ # "accountId": "106490",
2044
+ # "name": "main",
2045
+ # "positions": [
2046
+ # {
2047
+ # "marketCode": "BTC-USD-SWAP-LIN",
2048
+ # "baseAsset": "BTC",
2049
+ # "counterAsset": "USD",
2050
+ # "position": "0.00010",
2051
+ # "entryPrice": "64300.0",
2052
+ # "markPrice": "63278",
2053
+ # "positionPnl": "-10.1900",
2054
+ # "estLiquidationPrice": "0",
2055
+ # "lastUpdatedAt": "1714915841448"
2056
+ # },
2057
+ # ...
2058
+ # ]
2059
+ # },
2060
+ # {
2061
+ # "accountId": "106526",
2062
+ # "name": "testSubAccount",
2063
+ # "positions": [
2064
+ # {
2065
+ # "marketCode": "ETH-USD-SWAP-LIN",
2066
+ # "baseAsset": "ETH",
2067
+ # "counterAsset": "USD",
2068
+ # "position": "0.001",
2069
+ # "entryPrice": "3080.5",
2070
+ # "markPrice": "3062.0",
2071
+ # "positionPnl": "-1.8500",
2072
+ # "estLiquidationPrice": "0",
2073
+ # "lastUpdatedAt": "1715089678013"
2074
+ # },
2075
+ # ...
2076
+ # ]
2077
+ # }
2078
+ # ]
2079
+ # }
2080
+ #
2081
+ data = self.safe_list(response, 'data', [])
2082
+ allPositions = []
2083
+ for i in range(0, len(data)):
2084
+ account = data[i]
2085
+ positions = self.safe_list(account, 'positions', [])
2086
+ allPositions = self.array_concat(allPositions, positions)
2087
+ return self.parse_positions(allPositions, symbols)
2088
+
2089
+ def parse_position(self, position, market: Market = None):
2090
+ #
2091
+ # {
2092
+ # "marketCode": "ETH-USD-SWAP-LIN",
2093
+ # "baseAsset": "ETH",
2094
+ # "counterAsset": "USD",
2095
+ # "position": "0.001",
2096
+ # "entryPrice": "3080.5",
2097
+ # "markPrice": "3062.0",
2098
+ # "positionPnl": "-1.8500",
2099
+ # "estLiquidationPrice": "0",
2100
+ # "lastUpdatedAt": "1715089678013"
2101
+ # }
2102
+ #
2103
+ marketId = self.safe_string(position, 'marketCode')
2104
+ market = self.safe_market(marketId, market)
2105
+ return self.safe_position({
2106
+ 'info': position,
2107
+ 'id': None,
2108
+ 'symbol': market['symbol'],
2109
+ 'notional': None,
2110
+ 'marginMode': 'cross',
2111
+ 'liquidationPrice': self.safe_number(position, 'estLiquidationPrice'),
2112
+ 'entryPrice': self.safe_number(position, 'entryPrice'),
2113
+ 'unrealizedPnl': self.safe_number(position, 'positionPnl'),
2114
+ 'realizedPnl': None,
2115
+ 'percentage': None,
2116
+ 'contracts': self.safe_number(position, 'position'),
2117
+ 'contractSize': None,
2118
+ 'markPrice': self.safe_number(position, 'markPrice'),
2119
+ 'lastPrice': None,
2120
+ 'side': None,
2121
+ 'hedged': None,
2122
+ 'timestamp': None,
2123
+ 'datetime': None,
2124
+ 'lastUpdateTimestamp': self.safe_integer(position, 'lastUpdatedAt'),
2125
+ 'maintenanceMargin': None,
2126
+ 'maintenanceMarginPercentage': None,
2127
+ 'collateral': None,
2128
+ 'initialMargin': None,
2129
+ 'initialMarginPercentage': None,
2130
+ 'leverage': None,
2131
+ 'marginRatio': None,
2132
+ 'stopLossPrice': None,
2133
+ 'takeProfitPrice': None,
2134
+ })
2135
+
2136
+ async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}) -> Order:
2137
+ """
2138
+ create a trade order
2139
+ :see: https://docs.ox.fun/?json#post-v3-orders-place
2140
+ :param str symbol: unified symbol of the market to create an order in
2141
+ :param str type: 'market', 'limit', 'STOP_LIMIT' or 'STOP_MARKET'
2142
+ :param str side: 'buy' or 'sell'
2143
+ :param float amount: how much of currency you want to trade in units of base currency
2144
+ :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2145
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2146
+ :param int [params.clientOrderId]: a unique id for the order
2147
+ :param int [params.timestamp]: in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected.
2148
+ :param int [params.recvWindow]: in milliseconds. If an order reaches the matching engine and the current timestamp exceeds timestamp + recvWindow, then the order will be rejected. If timestamp is provided without recvWindow, then a default recvWindow of 1000ms is used.
2149
+ :param str [params.responseType]: FULL or ACK
2150
+ :param float [params.cost]: the quote quantity that can be used alternative for the amount for market buy orders
2151
+ :param float [params.triggerPrice]: The price at which a trigger order is triggered at
2152
+ :param float [params.limitPrice]: Limit price for the STOP_LIMIT order
2153
+ :param bool [params.postOnly]: if True, the order will only be posted if it will be a maker order
2154
+ :param str [params.timeInForce]: GTC(default), IOC, FOK, PO, MAKER_ONLY or MAKER_ONLY_REPRICE(reprices order to the best maker only price if the specified price were to lead to a taker trade)
2155
+ :param str [params.selfTradePreventionMode]: NONE, EXPIRE_MAKER, EXPIRE_TAKER or EXPIRE_BOTH for more info check here {@link https://docs.ox.fun/?json#self-trade-prevention-modes}
2156
+ :param str [params.displayQuantity]: for an iceberg order, pass both quantity and displayQuantity fields in the order request
2157
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2158
+ """
2159
+ await self.load_markets()
2160
+ request: dict = {
2161
+ 'responseType': self.safe_string(params, 'responseType', 'FULL'),
2162
+ 'timestamp': self.safe_integer(params, 'timestamp', self.milliseconds()),
2163
+ }
2164
+ params = self.omit(params, ['responseType', 'timestamp'])
2165
+ recvWindow = self.safe_integer(params, 'recvWindow')
2166
+ if recvWindow is not None:
2167
+ request['recvWindow'] = recvWindow
2168
+ params = self.omit(params, 'recvWindow')
2169
+ orderRequest = self.create_order_request(symbol, type, side, amount, price, params)
2170
+ request['orders'] = [orderRequest]
2171
+ response = await self.privatePostV3OrdersPlace(request)
2172
+ #
2173
+ # accepted market order responseType FULL
2174
+ # {
2175
+ # "success": True,
2176
+ # "data": [
2177
+ # {
2178
+ # "notice": "OrderMatched",
2179
+ # "accountId": "106490",
2180
+ # "orderId": "1000109901865",
2181
+ # "submitted": True,
2182
+ # "clientOrderId": "0",
2183
+ # "marketCode": "OX-USDT",
2184
+ # "status": "FILLED",
2185
+ # "side": "SELL",
2186
+ # "isTriggered": False,
2187
+ # "quantity": "150.0",
2188
+ # "amount": "0.0",
2189
+ # "remainQuantity": "0.0",
2190
+ # "matchId": "100017047880451399",
2191
+ # "matchPrice": "0.01465",
2192
+ # "matchQuantity": "150.0",
2193
+ # "feeInstrumentId": "USDT",
2194
+ # "fees": "0.0015382500",
2195
+ # "orderType": "MARKET",
2196
+ # "createdAt": "1715592472236",
2197
+ # "lastMatchedAt": "1715592472200",
2198
+ # "displayQuantity": "150.0"
2199
+ # }
2200
+ # ]
2201
+ # }
2202
+ #
2203
+ # accepted limit order responseType FULL
2204
+ # {
2205
+ # "success": True,
2206
+ # "data": [
2207
+ # {
2208
+ # "notice": "OrderOpened",
2209
+ # "accountId": "106490",
2210
+ # "orderId": "1000111482406",
2211
+ # "submitted": True,
2212
+ # "clientOrderId": "0",
2213
+ # "marketCode": "ETH-USD-SWAP-LIN",
2214
+ # "status": "OPEN",
2215
+ # "side": "SELL",
2216
+ # "price": "4000.0",
2217
+ # "isTriggered": False,
2218
+ # "quantity": "0.01",
2219
+ # "amount": "0.0",
2220
+ # "orderType": "LIMIT",
2221
+ # "timeInForce": "GTC",
2222
+ # "createdAt": "1715763507682",
2223
+ # "displayQuantity": "0.01"
2224
+ # }
2225
+ # ]
2226
+ # }
2227
+ #
2228
+ # accepted order responseType ACK
2229
+ # {
2230
+ # "success": True,
2231
+ # "data": [
2232
+ # {
2233
+ # "accountId": "106490",
2234
+ # "orderId": "1000109892193",
2235
+ # "submitted": True,
2236
+ # "marketCode": "OX-USDT",
2237
+ # "side": "BUY",
2238
+ # "price": "0.01961",
2239
+ # "isTriggered": False,
2240
+ # "quantity": "100",
2241
+ # "orderType": "MARKET",
2242
+ # "timeInForce": "IOC",
2243
+ # "createdAt": "1715591529057",
2244
+ # "selfTradePreventionMode": "NONE"
2245
+ # }
2246
+ # ]
2247
+ # }
2248
+ #
2249
+ # rejected order(balance insufficient)
2250
+ # {
2251
+ # "success": True,
2252
+ # "data": [
2253
+ # {
2254
+ # "code": "710001",
2255
+ # "message": "System failure, exception thrown -> null",
2256
+ # "submitted": False,
2257
+ # "marketCode": "OX-USDT",
2258
+ # "side": "BUY",
2259
+ # "price": "0.01961",
2260
+ # "amount": "100",
2261
+ # "orderType": "MARKET",
2262
+ # "timeInForce": "IOC",
2263
+ # "createdAt": "1715591678835",
2264
+ # "source": 11,
2265
+ # "selfTradePreventionMode": "NONE"
2266
+ # }
2267
+ # ]
2268
+ # }
2269
+ #
2270
+ # rejected order(bad request)
2271
+ # {
2272
+ # "success": True,
2273
+ # "data": [
2274
+ # {
2275
+ # "code": "20044",
2276
+ # "message": "Amount is not supported for self order type",
2277
+ # "submitted": False,
2278
+ # "marketCode": "OX-USDT",
2279
+ # "side": "SELL",
2280
+ # "amount": "200",
2281
+ # "orderType": "MARKET",
2282
+ # "createdAt": "1715592079986",
2283
+ # "source": 11
2284
+ # }
2285
+ # ]
2286
+ # }
2287
+ #
2288
+ data = self.safe_list(response, 'data', [])
2289
+ order = self.safe_dict(data, 0, {})
2290
+ return self.parse_order(order)
2291
+
2292
+ async def create_orders(self, orders: List[OrderRequest], params={}) -> List[Order]:
2293
+ """
2294
+ create a list of trade orders
2295
+ :see: https://docs.ox.fun/?json#post-v3-orders-place
2296
+ :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
2297
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2298
+ :param int [params.timestamp]: *for all orders* in milliseconds. If orders reach the matching engine and the current timestamp exceeds timestamp + recvWindow, then all orders will be rejected.
2299
+ :param int [params.recvWindow]: *for all orders* in milliseconds. If orders reach the matching engine and the current timestamp exceeds timestamp + recvWindow, then all orders will be rejected. If timestamp is provided without recvWindow, then a default recvWindow of 1000ms is used.
2300
+ :param str [params.responseType]: *for all orders* FULL or ACK
2301
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2302
+ """
2303
+ await self.load_markets()
2304
+ ordersRequests = []
2305
+ for i in range(0, len(orders)):
2306
+ rawOrder = orders[i]
2307
+ symbol = self.safe_string(rawOrder, 'symbol')
2308
+ type = self.safe_string(rawOrder, 'type')
2309
+ side = self.safe_string(rawOrder, 'side')
2310
+ amount = self.safe_number(rawOrder, 'amount')
2311
+ price = self.safe_number(rawOrder, 'price')
2312
+ orderParams = self.safe_dict(rawOrder, 'params', {})
2313
+ orderRequest = self.create_order_request(symbol, type, side, amount, price, orderParams)
2314
+ ordersRequests.append(orderRequest)
2315
+ request: dict = {
2316
+ 'responseType': 'FULL',
2317
+ 'timestamp': self.milliseconds(),
2318
+ 'orders': ordersRequests,
2319
+ }
2320
+ response = await self.privatePostV3OrdersPlace(self.extend(request, params))
2321
+ data = self.safe_list(response, 'data', [])
2322
+ return self.parse_orders(data)
2323
+
2324
+ def create_order_request(self, symbol: str, type: str, side: str, amount, price=None, params={}):
2325
+ """
2326
+ :param str symbol: unified symbol of the market to create an order in
2327
+ :param str type: 'market', 'limit', 'STOP_LIMIT' or 'STOP_MARKET'
2328
+ :param str side: 'buy' or 'sell'
2329
+ :param float amount: how much of currency you want to trade in units of base currency
2330
+ :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2331
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2332
+ :param int [params.clientOrderId]: a unique id for the order
2333
+ :param float [params.cost]: the quote quantity that can be used alternative for the amount for market buy orders
2334
+ :param float [params.triggerPrice]: The price at which a trigger order is triggered at
2335
+ :param float [params.limitPrice]: Limit price for the STOP_LIMIT order
2336
+ :param bool [params.postOnly]: if True, the order will only be posted if it will be a maker order
2337
+ :param str [params.timeInForce]: GTC(default), IOC, FOK, PO, MAKER_ONLY or MAKER_ONLY_REPRICE(reprices order to the best maker only price if the specified price were to lead to a taker trade)
2338
+ :param str [params.selfTradePreventionMode]: NONE, EXPIRE_MAKER, EXPIRE_TAKER or EXPIRE_BOTH for more info check here {@link https://docs.ox.fun/?json#self-trade-prevention-modes}
2339
+ :param str [params.displayQuantity]: for an iceberg order, pass both quantity and displayQuantity fields in the order request
2340
+ """
2341
+ market = self.market(symbol)
2342
+ request: dict = {
2343
+ 'marketCode': market['id'],
2344
+ 'side': side.upper(),
2345
+ 'source': 1000,
2346
+ }
2347
+ cost = self.safe_string_2(params, 'cost', 'amount')
2348
+ if cost is not None:
2349
+ request['amount'] = cost # todo costToPrecision
2350
+ params = self.omit(params, ['cost', 'amount'])
2351
+ else:
2352
+ request['quantity'] = amount # todo amountToPrecision
2353
+ triggerPrice = self.safe_string_2(params, 'triggerPrice', 'stopPrice')
2354
+ orderType = type.upper()
2355
+ if triggerPrice is not None:
2356
+ if orderType == 'MARKET':
2357
+ orderType = 'STOP_MARKET'
2358
+ elif orderType == 'LIMIT':
2359
+ orderType = 'STOP_LIMIT'
2360
+ request['stopPrice'] = triggerPrice # todo priceToPrecision
2361
+ params = self.omit(params, ['triggerPrice', 'stopPrice'])
2362
+ request['orderType'] = orderType
2363
+ if orderType == 'STOP_LIMIT':
2364
+ request['limitPrice'] = price # todo priceToPrecision
2365
+ elif price is not None:
2366
+ request['price'] = price # todo priceToPrecision
2367
+ postOnly: Bool = None
2368
+ isMarketOrder = (orderType == 'MARKET') or (orderType == 'STOP_MARKET')
2369
+ postOnly, params = self.handle_post_only(isMarketOrder, False, params)
2370
+ timeInForce = self.safe_string_upper(params, 'timeInForce')
2371
+ if postOnly and (timeInForce != 'MAKER_ONLY_REPRICE'):
2372
+ request['timeInForce'] = 'MAKER_ONLY'
2373
+ return self.extend(request, params)
2374
+
2375
+ async def create_market_buy_order_with_cost(self, symbol: str, cost: float, params={}):
2376
+ """
2377
+ create a market buy order by providing the symbol and cost
2378
+ :see: https://open.big.one/docs/spot_orders.html#create-order
2379
+ :param str symbol: unified symbol of the market to create an order in
2380
+ :param float cost: how much you want to trade in units of the quote currency
2381
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2382
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2383
+ """
2384
+ await self.load_markets()
2385
+ market = self.market(symbol)
2386
+ if not market['spot']:
2387
+ raise NotSupported(self.id + ' createMarketBuyOrderWithCost() supports spot orders only')
2388
+ request: dict = {
2389
+ 'cost': cost,
2390
+ }
2391
+ return await self.create_order(symbol, 'market', 'buy', None, None, self.extend(request, params))
2392
+
2393
+ async def fetch_order(self, id: str, symbol: Str = None, params={}) -> Order:
2394
+ """
2395
+ :see: https://docs.ox.fun/?json#get-v3-orders-status
2396
+ fetches information on an order made by the user
2397
+ :param str id: a unique id for the order
2398
+ :param str [symbol]: not used by oxfun fetchOrder
2399
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2400
+ :param int [params.clientOrderId]: the client order id of the order
2401
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2402
+ """
2403
+ await self.load_markets()
2404
+ request: dict = {
2405
+ 'orderId': id,
2406
+ }
2407
+ response = await self.privateGetV3OrdersStatus(self.extend(request, params))
2408
+ #
2409
+ # {
2410
+ # "success": True,
2411
+ # "data": {
2412
+ # "orderId": "1000111762980",
2413
+ # "clientOrderId": "0",
2414
+ # "marketCode": "ETH-USD-SWAP-LIN",
2415
+ # "status": "OPEN",
2416
+ # "side": "BUY",
2417
+ # "price": "2700.0",
2418
+ # "isTriggered": False,
2419
+ # "remainQuantity": "0.01",
2420
+ # "totalQuantity": "0.01",
2421
+ # "amount": "0",
2422
+ # "displayQuantity": "0.01",
2423
+ # "cumulativeMatchedQuantity": "0",
2424
+ # "orderType": "STOP_LIMIT",
2425
+ # "timeInForce": "GTC",
2426
+ # "source": "11",
2427
+ # "createdAt": "1715794191277"
2428
+ # }
2429
+ # }
2430
+ #
2431
+ data = self.safe_dict(response, 'data', {})
2432
+ return self.parse_order(data)
2433
+
2434
+ async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
2435
+ """
2436
+ fetch all unfilled currently open orders
2437
+ :see: https://docs.ox.fun/?json#get-v3-orders-working
2438
+ :param str symbol: unified market symbol
2439
+ :param int [since]: the earliest time in ms to fetch open orders for
2440
+ :param int [limit]: the maximum number of open orders structures to retrieve
2441
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2442
+ :param int [params.orderId]: a unique id for the order
2443
+ :param int [params.clientOrderId]: the client order id of the order
2444
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2445
+ """
2446
+ await self.load_markets()
2447
+ request: dict = {}
2448
+ market: Market = None
2449
+ if symbol is not None:
2450
+ market = self.market(symbol)
2451
+ response = await self.privateGetV3OrdersWorking(self.extend(request, params))
2452
+ data = self.safe_list(response, 'data', [])
2453
+ return self.parse_orders(data, market, since, limit)
2454
+
2455
+ async def cancel_order(self, id: str, symbol: Str = None, params={}):
2456
+ """
2457
+ cancels an open order
2458
+ :see: https://docs.ox.fun/?json#delete-v3-orders-cancel
2459
+ :param str id: order id
2460
+ :param str symbol: unified symbol of the market the order was made in
2461
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2462
+ :param int [params.clientOrderId]: a unique id for the order
2463
+ :param int [params.timestamp]: in milliseconds
2464
+ :param int [params.recvWindow]: in milliseconds
2465
+ :param str [params.responseType]: 'FULL' or 'ACK'
2466
+ :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
2467
+ """
2468
+ if symbol is None:
2469
+ raise ArgumentsRequired(self.id + ' cancelOrder() requires a symbol argument')
2470
+ market = self.market(symbol)
2471
+ marketId = market['id']
2472
+ request: dict = {
2473
+ 'timestamp': self.milliseconds(),
2474
+ 'responseType': 'FULL',
2475
+ }
2476
+ orderRequest = {
2477
+ 'marketCode': marketId,
2478
+ 'orderId': id,
2479
+ }
2480
+ clientOrderId = self.safe_integer(params, 'clientOrderId')
2481
+ if clientOrderId is not None:
2482
+ orderRequest['clientOrderId'] = clientOrderId
2483
+ request['orders'] = [orderRequest]
2484
+ response = await self.privateDeleteV3OrdersCancel(self.extend(request, params))
2485
+ data = self.safe_list(response, 'data', [])
2486
+ order = self.safe_dict(data, 0, {})
2487
+ return self.parse_order(order)
2488
+
2489
+ async def cancel_all_orders(self, symbol: Str = None, params={}):
2490
+ """
2491
+ cancel all open orders
2492
+ :see: https://docs.ox.fun/?json#delete-v3-orders-cancel-all
2493
+ :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
2494
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2495
+ :returns dict: response from exchange
2496
+ """
2497
+ request: dict = {}
2498
+ if symbol is not None:
2499
+ market = self.market(symbol)
2500
+ request['marketCode'] = market['id']
2501
+ #
2502
+ # {
2503
+ # "success": True,
2504
+ # "data": {"notice": "Orders queued for cancelation"}
2505
+ # }
2506
+ #
2507
+ # {
2508
+ # "success": True,
2509
+ # "data": {"notice": "No working orders found"}
2510
+ # }
2511
+ #
2512
+ return await self.privateDeleteV3OrdersCancelAll(self.extend(request, params))
2513
+
2514
+ async def cancel_orders(self, ids: List[str], symbol: Str = None, params={}):
2515
+ """
2516
+ cancel multiple orders
2517
+ :see: https://docs.ox.fun/?json#delete-v3-orders-cancel
2518
+ :param str[] ids: order ids
2519
+ :param str [symbol]: unified market symbol
2520
+ :param dict [params]: extra parameters specific to the exchange API endpoint
2521
+ :param int [params.timestamp]: in milliseconds
2522
+ :param int [params.recvWindow]: in milliseconds
2523
+ :param str [params.responseType]: 'FULL' or 'ACK'
2524
+ :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
2525
+ """
2526
+ if symbol is None:
2527
+ raise ArgumentsRequired(self.id + ' cancelOrders() requires a symbol argument')
2528
+ await self.load_markets()
2529
+ market = self.market(symbol)
2530
+ marketId = market['id']
2531
+ request: dict = {
2532
+ 'timestamp': self.milliseconds(),
2533
+ 'responseType': 'FULL',
2534
+ }
2535
+ orders = []
2536
+ for i in range(0, len(ids)):
2537
+ order = {
2538
+ 'marketCode': marketId,
2539
+ 'orderId': ids[i],
2540
+ }
2541
+ orders.append(order)
2542
+ request['orders'] = orders
2543
+ response = await self.privateDeleteV3OrdersCancel(self.extend(request, params))
2544
+ data = self.safe_list(response, 'data', [])
2545
+ return self.parse_orders(data, market)
2546
+
2547
+ def parse_order(self, order, market: Market = None) -> Order:
2548
+ #
2549
+ # accepted market order responseType FULL
2550
+ # {
2551
+ # "notice": "OrderMatched",
2552
+ # "accountId": "106490",
2553
+ # "orderId": "1000109901865",
2554
+ # "submitted": True,
2555
+ # "clientOrderId": "0",
2556
+ # "marketCode": "OX-USDT",
2557
+ # "status": "FILLED",
2558
+ # "side": "SELL",
2559
+ # "isTriggered": False,
2560
+ # "quantity": "150.0",
2561
+ # "amount": "0.0",
2562
+ # "remainQuantity": "0.0",
2563
+ # "matchId": "100017047880451399",
2564
+ # "matchPrice": "0.01465",
2565
+ # "matchQuantity": "150.0",
2566
+ # "feeInstrumentId": "USDT",
2567
+ # "fees": "0.0015382500",
2568
+ # "orderType": "MARKET",
2569
+ # "createdAt": "1715592472236",
2570
+ # "lastMatchedAt": "1715592472200",
2571
+ # "displayQuantity": "150.0"
2572
+ # }
2573
+ #
2574
+ # accepted limit order responseType FULL
2575
+ # {
2576
+ # "notice": "OrderOpened",
2577
+ # "accountId": "106490",
2578
+ # "orderId": "1000111482406",
2579
+ # "submitted": True,
2580
+ # "clientOrderId": "0",
2581
+ # "marketCode": "ETH-USD-SWAP-LIN",
2582
+ # "status": "OPEN",
2583
+ # "side": "SELL",
2584
+ # "price": "4000.0",
2585
+ # "isTriggered": False,
2586
+ # "quantity": "0.01",
2587
+ # "amount": "0.0",
2588
+ # "orderType": "LIMIT",
2589
+ # "timeInForce": "GTC",
2590
+ # "createdAt": "1715763507682",
2591
+ # "displayQuantity": "0.01"
2592
+ # }
2593
+ #
2594
+ # accepted order responseType ACK
2595
+ # {
2596
+ # "accountId": "106490",
2597
+ # "orderId": "1000109892193",
2598
+ # "submitted": True,
2599
+ # "marketCode": "OX-USDT",
2600
+ # "side": "BUY",
2601
+ # "price": "0.01961",
2602
+ # "isTriggered": False,
2603
+ # "quantity": "100",
2604
+ # "orderType": "MARKET",
2605
+ # "timeInForce": "IOC",
2606
+ # "createdAt": "1715591529057",
2607
+ # "selfTradePreventionMode": "NONE"
2608
+ # }
2609
+ #
2610
+ # rejected order(balance insufficient)
2611
+ # {
2612
+ # "code": "710001",
2613
+ # "message": "System failure, exception thrown -> null",
2614
+ # "submitted": False,
2615
+ # "marketCode": "OX-USDT",
2616
+ # "side": "BUY",
2617
+ # "price": "0.01961",
2618
+ # "amount": "100",
2619
+ # "orderType": "MARKET",
2620
+ # "timeInForce": "IOC",
2621
+ # "createdAt": "1715591678835",
2622
+ # "source": 11,
2623
+ # "selfTradePreventionMode": "NONE"
2624
+ # }
2625
+ #
2626
+ # rejected order(bad request)
2627
+ # {
2628
+ # "code": "20044",
2629
+ # "message": "Amount is not supported for self order type",
2630
+ # "submitted": False,
2631
+ # "marketCode": "OX-USDT",
2632
+ # "side": "SELL",
2633
+ # "amount": "200",
2634
+ # "orderType": "MARKET",
2635
+ # "createdAt": "1715592079986",
2636
+ # "source": 11
2637
+ # }
2638
+ #
2639
+ # fetchOrder
2640
+ # {
2641
+ # "orderId": "1000111762980",
2642
+ # "clientOrderId": "0",
2643
+ # "marketCode": "ETH-USD-SWAP-LIN",
2644
+ # "status": "OPEN",
2645
+ # "side": "BUY",
2646
+ # "price": "2700.0",
2647
+ # "isTriggered": False,
2648
+ # "remainQuantity": "0.01",
2649
+ # "totalQuantity": "0.01",
2650
+ # "amount": "0",
2651
+ # "displayQuantity": "0.01",
2652
+ # "cumulativeMatchedQuantity": "0",
2653
+ # "orderType": "STOP_LIMIT",
2654
+ # "timeInForce": "GTC",
2655
+ # "source": "11",
2656
+ # "createdAt": "1715794191277"
2657
+ # }
2658
+ #
2659
+ marketId = self.safe_string(order, 'marketCode')
2660
+ market = self.safe_market(marketId, market)
2661
+ timestamp = self.safe_integer(order, 'createdAt')
2662
+ fee = None
2663
+ feeCurrency = self.safe_string(order, 'feeInstrumentId')
2664
+ if feeCurrency is not None:
2665
+ fee = {
2666
+ 'currency': self.safe_currency_code(feeCurrency),
2667
+ 'cost': self.safe_number(order, 'fees'),
2668
+ }
2669
+ status = self.safe_string(order, 'status')
2670
+ code = self.safe_integer(order, 'code') # rejected orders have code of the error
2671
+ if code is not None:
2672
+ status = 'rejected'
2673
+ triggerPrice = self.safe_string(order, 'stopPrice')
2674
+ return self.safe_order({
2675
+ 'id': self.safe_string(order, 'orderId'),
2676
+ 'clientOrderId': self.safe_string(order, 'clientOrderId'),
2677
+ 'timestamp': timestamp,
2678
+ 'datetime': self.iso8601(timestamp),
2679
+ 'lastTradeTimestamp': self.safe_integer(order, 'lastMatchedAt'),
2680
+ 'lastUpdateTimestamp': self.safe_integer(order, 'lastModifiedAt'),
2681
+ 'status': self.parse_order_status(status),
2682
+ 'symbol': market['symbol'],
2683
+ 'type': self.parse_order_type(self.safe_string(order, 'orderType')),
2684
+ 'timeInForce': self.parse_order_time_in_force(self.safe_string(order, 'timeInForce')), # only for limit orders
2685
+ 'side': self.safe_string_lower(order, 'side'),
2686
+ 'price': self.safe_string_n(order, ['price', 'matchPrice', 'limitPrice']),
2687
+ 'average': None,
2688
+ 'amount': self.safe_string_2(order, 'totalQuantity', 'quantity'),
2689
+ 'filled': self.safe_string_2(order, 'cumulativeMatchedQuantity', 'matchQuantity'),
2690
+ 'remaining': self.safe_string(order, 'remainQuantity'),
2691
+ 'triggerPrice': triggerPrice,
2692
+ 'stopLossPrice': triggerPrice,
2693
+ 'cost': self.omit_zero(self.safe_string(order, 'amount')),
2694
+ 'trades': None,
2695
+ 'fee': fee,
2696
+ 'info': order,
2697
+ }, market)
2698
+
2699
+ def parse_order_status(self, status):
2700
+ statuses: dict = {
2701
+ 'OPEN': 'open',
2702
+ 'PARTIALLY_FILLED': 'open',
2703
+ 'PARTIAL_FILL': 'open',
2704
+ 'FILLED': 'closed',
2705
+ 'CANCELED': 'canceled',
2706
+ 'CANCELED_BY_USER': 'canceled',
2707
+ 'CANCELED_BY_MAKER_ONLY': 'rejected',
2708
+ 'CANCELED_BY_FOK': 'rejected',
2709
+ 'CANCELED_ALL_BY_IOC': 'rejected',
2710
+ 'CANCELED_PARTIAL_BY_IOC': 'canceled',
2711
+ 'CANCELED_BY_SELF_TRADE_PROTECTION': 'rejected',
2712
+ }
2713
+ return self.safe_string(statuses, status, status)
2714
+
2715
+ def parse_order_type(self, type):
2716
+ types: dict = {
2717
+ 'LIMIT': 'limit',
2718
+ 'STOP_LIMIT': 'limit',
2719
+ 'MARKET': 'market',
2720
+ 'STOP_MARKET': 'market',
2721
+ }
2722
+ return self.safe_string(types, type, type)
2723
+
2724
+ def parse_order_time_in_force(self, type):
2725
+ types: dict = {
2726
+ 'GTC': 'GTC',
2727
+ 'IOC': 'IOC',
2728
+ 'FOK': 'FOK',
2729
+ 'MAKER_ONLY': 'PO',
2730
+ 'MAKER_ONLY_REPRICE': 'PO',
2731
+ }
2732
+ return self.safe_string(types, type, type)
2733
+
2734
+ def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
2735
+ baseUrl = self.urls['api'][api]
2736
+ url = baseUrl + '/' + path
2737
+ queryString = ''
2738
+ if method == 'GET':
2739
+ queryString = self.urlencode(params)
2740
+ if len(queryString) != 0:
2741
+ url += '?' + queryString
2742
+ if api == 'private':
2743
+ self.check_required_credentials()
2744
+ timestamp = self.milliseconds()
2745
+ isoDatetime = self.iso8601(timestamp)
2746
+ datetimeParts = isoDatetime.split('.')
2747
+ datetime = datetimeParts[0]
2748
+ nonce = self.nonce()
2749
+ urlParts = baseUrl.split('//')
2750
+ if (method == 'POST') or (method == 'DELETE'):
2751
+ body = self.json(params)
2752
+ queryString = body
2753
+ msgString = datetime + '\n' + str(nonce) + '\n' + method + '\n' + urlParts[1] + '\n/' + path + '\n' + queryString
2754
+ signature = self.hmac(self.encode(msgString), self.encode(self.secret), hashlib.sha256, 'base64')
2755
+ headers = {
2756
+ 'Content-Type': 'application/json',
2757
+ 'AccessKey': self.apiKey,
2758
+ 'Timestamp': datetime,
2759
+ 'Signature': signature,
2760
+ 'Nonce': nonce,
2761
+ }
2762
+ return {'url': url, 'method': method, 'body': body, 'headers': headers}
2763
+
2764
+ def handle_errors(self, code, reason, url, method, headers, body, response, requestHeaders, requestBody):
2765
+ if response is None:
2766
+ return None
2767
+ if code != 200:
2768
+ responseCode = self.safe_string(response, 'code', None)
2769
+ feedback = self.id + ' ' + body
2770
+ self.throw_broadly_matched_exception(self.exceptions['broad'], body, feedback)
2771
+ self.throw_exactly_matched_exception(self.exceptions['exact'], responseCode, feedback)
2772
+ raise ExchangeError(feedback)
2773
+ return None