Repository navigation
Expand file tree
/
Copy pathoxfun.py
More file actions
2832 lines (2713 loc) · 122 KB
/
Copy pathoxfun.py
File metadata and controls
2832 lines (2713 loc) · 122 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
# https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
from ccxt.base.exchange import Exchange
from ccxt.abstract.oxfun import ImplicitAPI
import hashlib
from ccxt.base.types import Account, Balances, Bool, Currencies, Currency, DepositAddress, Int, LeverageTier, LeverageTiers, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, FundingRate, FundingRates, Trade, Transaction, TransferEntry
from typing import List
from ccxt.base.errors import ExchangeError
from ccxt.base.errors import AuthenticationError
from ccxt.base.errors import AccountNotEnabled
from ccxt.base.errors import ArgumentsRequired
from ccxt.base.errors import BadRequest
from ccxt.base.errors import BadSymbol
from ccxt.base.errors import MarketClosed
from ccxt.base.errors import InsufficientFunds
from ccxt.base.errors import InvalidOrder
from ccxt.base.errors import OrderNotFound
from ccxt.base.errors import NotSupported
from ccxt.base.errors import OperationFailed
from ccxt.base.errors import NetworkError
from ccxt.base.errors import RateLimitExceeded
from ccxt.base.errors import RequestTimeout
from ccxt.base.decimal_to_precision import TICK_SIZE
from ccxt.base.precise import Precise
class oxfun(Exchange, ImplicitAPI):
def describe(self):
return self.deep_extend(super(oxfun, self).describe(), {
'id': 'oxfun',
'name': 'OXFUN',
'countries': ['PA'], # Panama todo check
'version': 'v3',
'rateLimit': 120, # 100 requests per second and 25000 per 5 minutes
'pro': True,
'has': {
'CORS': None,
'spot': True,
'margin': False,
'swap': True,
'future': False,
'option': False,
'addMargin': False,
'cancelAllOrders': True,
'cancelOrder': True,
'cancelOrders': True,
'closeAllPositions': False,
'closePosition': False,
'createDepositAddress': False,
'createMarketBuyOrderWithCost': True,
'createMarketOrderWithCost': False,
'createMarketSellOrderWithCost': False,
'createOrder': True,
'createOrders': True,
'createPostOnlyOrder': True,
'createReduceOnlyOrder': False,
'createStopLimitOrder': True,
'createStopMarketOrder': True,
'createStopOrder': True,
'deposit': False,
'editOrder': False,
'fetchAccounts': True,
'fetchBalance': True,
'fetchBidsAsks': False,
'fetchBorrowInterest': False,
'fetchBorrowRateHistories': False,
'fetchBorrowRateHistory': False,
'fetchCanceledOrders': False,
'fetchClosedOrder': False,
'fetchClosedOrders': False,
'fetchCrossBorrowRate': False,
'fetchCrossBorrowRates': False,
'fetchCurrencies': True,
'fetchDeposit': False,
'fetchDepositAddress': True,
'fetchDepositAddresses': False,
'fetchDepositAddressesByNetwork': False,
'fetchDeposits': True,
'fetchDepositWithdrawFee': False,
'fetchDepositWithdrawFees': False,
'fetchFundingHistory': True,
'fetchFundingRate': 'emulated',
'fetchFundingRateHistory': True,
'fetchFundingRates': True,
'fetchIndexOHLCV': False,
'fetchIsolatedBorrowRate': False,
'fetchIsolatedBorrowRates': False,
'fetchL3OrderBook': False,
'fetchLedger': False,
'fetchLeverage': False,
'fetchLeverageTiers': True,
'fetchMarketLeverageTiers': 'emulated',
'fetchMarkets': True,
'fetchMarkOHLCV': False,
'fetchMyTrades': True,
'fetchOHLCV': True,
'fetchOpenInterestHistory': False,
'fetchOpenOrder': False,
'fetchOpenOrders': True,
'fetchOrder': True,
'fetchOrderBook': True,
'fetchOrderBooks': False,
'fetchOrders': False,
'fetchOrderTrades': False,
'fetchPosition': False,
'fetchPositionHistory': False,
'fetchPositionMode': False,
'fetchPositions': True,
'fetchPositionsForSymbol': False,
'fetchPositionsHistory': False,
'fetchPositionsRisk': False,
'fetchPremiumIndexOHLCV': False,
'fetchStatus': False,
'fetchTicker': True,
'fetchTickers': True,
'fetchTime': False,
'fetchTrades': True,
'fetchTradingFee': False,
'fetchTradingFees': False,
'fetchTradingLimits': False,
'fetchTransactionFee': False,
'fetchTransactionFees': False,
'fetchTransactions': False,
'fetchTransfers': True,
'fetchWithdrawal': False,
'fetchWithdrawals': True,
'fetchWithdrawalWhitelist': False,
'reduceMargin': False,
'repayCrossMargin': False,
'repayIsolatedMargin': False,
'setLeverage': False,
'setMargin': False,
'setMarginMode': False,
'setPositionMode': False,
'signIn': False,
'transfer': True,
'withdraw': True,
'ws': True,
},
'timeframes': {
'1m': '60s',
'5m': '300s',
'15m': '900s',
'30m': '1800s',
'1h': '3600s',
'2h': '7200s',
'4h': '14400s',
'1d': '86400s',
},
'urls': {
'logo': 'https://github.com/ccxt/ccxt/assets/43336371/6a196124-c1ee-4fae-8573-962071b61a85',
'referral': 'https://ox.fun/register?shareAccountId=5ZUD4a7G',
'api': {
'public': 'https://api.ox.fun',
'private': 'https://api.ox.fun',
},
'test': {
'public': 'https://stgapi.ox.fun',
'private': 'https://stgapi.ox.fun',
},
'www': 'https://ox.fun/',
'doc': 'https://docs.ox.fun/',
'fees': 'https://support.ox.fun/en/articles/8819866-trading-fees',
},
'api': {
'public': {
'get': {
'v3/markets': 1,
'v3/assets': 1,
'v3/tickers': 1,
'v3/funding/estimates': 1,
'v3/candles': 1,
'v3/depth': 1,
'v3/markets/operational': 1,
'v3/exchange-trades': 1,
'v3/funding/rates': 1,
'v3/leverage/tiers': 1,
},
},
'private': {
'get': {
'v3/account': 1,
'v3/account/names': 1,
'v3/wallet': 1, # retruns only FUNDING in OX
'v3/transfer': 1,
'v3/balances': 1,
'v3/positions': 1,
'v3/funding': 1,
'v3/deposit-addresses': 1,
'v3/deposit': 1,
'v3/withdrawal-addresses': 1,
'v3/withdrawal': 1,
'v3/withdrawal-fees': 1,
'v3/orders/status': 1,
'v3/orders/working': 1,
'v3/trades': 1,
},
'post': {
'v3/transfer': 1,
'v3/withdrawal': 1,
'v3/orders/place': 1,
},
'delete': {
'v3/orders/cancel': 1,
'v3/orders/cancel-all': 1,
},
},
},
'fees': {
'trading': {
'tierBased': True,
'percentage': True,
'maker': self.parse_number('0.00020'),
'taker': self.parse_number('0.00070'),
'tiers': {
'maker': [
[self.parse_number('0'), self.parse_number('0.00020')],
[self.parse_number('2500000'), self.parse_number('0.00010')],
[self.parse_number('25000000'), self.parse_number('0')],
],
'taker': [
[self.parse_number('0'), self.parse_number('0.00070')],
[self.parse_number('2500000'), self.parse_number('0.00050')],
[self.parse_number('25000000'), self.parse_number('0.00040')],
],
},
},
},
'precisionMode': TICK_SIZE,
# exchange-specific options
'options': {
'sandboxMode': False,
'networks': {
'BTC': 'Bitcoin',
'ERC20': 'Ethereum',
'AVAX': 'Avalanche',
'SOL': 'Solana',
'ARB': 'Arbitrum',
'MATIC': 'Polygon',
'FTM': 'Fantom',
'BNB': 'BNBSmartChain',
'OPTIMISM': 'Optimism',
},
'networksById': {
'Bitcoin': 'BTC',
'Ethereum': 'ERC20',
'Avalanche': 'AVAX',
'Solana': 'SOL',
'Arbitrum': 'ARB',
'Polygon': 'MATIC',
'Fantom': 'FTM',
'Base': 'BASE',
'BNBSmartChain': 'BNB',
'Optimism': 'OPTIMISM',
},
},
'exceptions': {
'exact': {
'-0010': OperationFailed, # {"event":null,"success":false,"message":"Validation failed","code":"0010","data":null} - failed transfer
'-429': RateLimitExceeded, # Rate limit reached
'-05001': AuthenticationError, # Your operation authority is invalid
'-10001': ExchangeError, # General networking failure
'-20000': BadRequest, # Signature is invalid
'-20001': BadRequest, # "success":false,"code":"20001","message":"marketCode is invalid"
'-20002': BadRequest, # Unexpected error, please check if your request data complies with the specification.
'-20003': NotSupported, # Unrecognized operation
'-20005': AuthenticationError, # Already logged in
'-20006': BadRequest, # Quantity must be greater than zero
'-20007': AuthenticationError, # You are accessing server too rapidly
'-20008': BadRequest, # clientOrderId must be greater than zero if provided
'-20009': BadRequest, # JSON data format is invalid
'-20010': ArgumentsRequired, # Either clientOrderId or orderId is required
'-20011': ArgumentsRequired, # marketCode is required
'-20012': ArgumentsRequired, # side is required
'-20013': ArgumentsRequired, # orderType is required
'-20014': BadRequest, # clientOrderId is not long type
'-20015': BadSymbol, # marketCode is invalid
'-20016': BadRequest, # side is invalid
'-20017': BadRequest, # orderType is invalid
'-20018': BadRequest, # timeInForce is invalid
'-20019': BadRequest, # orderId is invalid
'-20020': BadRequest, # stopPrice or limitPrice is invalid
'-20021': BadRequest, # price is invalid
'-20022': ArgumentsRequired, # price is required for LIMIT order
'-20023': ArgumentsRequired, # timestamp is required
'-20024': ExchangeError, # timestamp exceeds the threshold
'-20025': AuthenticationError, # API key is invalid
'-20026': BadRequest, # Token is invalid or expired
'-20027': BadRequest, # The length of the message exceeds the maximum length
'-20028': BadRequest, # price or stopPrice or limitPrice must be greater than zero
'-20029': BadRequest, # stopPrice must be less than limitPrice for Buy Stop Order
'-20030': BadRequest, # limitPrice must be less than stopPrice for Sell Stop Order
'-20031': MarketClosed, # The marketCode is closed for trading temporarily
'-20032': NetworkError, # Failed to submit due to timeout in server side
'-20033': BadRequest, # triggerType is invalid
'-20034': BadRequest, # The size of tag must be less than 32
'-20050': ExchangeError, # selfTradePreventionMode is invalid
'-30001': BadRequest, # {"success":false,"code":"30001","message":"Required parameter 'marketCode' is missing"}
'-35034': AuthenticationError, # {"success":false,"code":"35034","message":"Wallet API is not functioning properly, please try again or contact support."}
'-35046': AuthenticationError, # {"success":false,"code":"35046","message":"Error. Please refresh the page."}
'-40001': ExchangeError, # Alert from the server
'-50001': ExchangeError, # Unknown server error
'-300001': AccountNotEnabled, # Invalid account status xxx, please contact administration if any questions
'-300011': InvalidOrder, # Repo market orders are not allowed during the auction window
'-300012': InvalidOrder, # Repo bids above 0 and offers below 0 are not allowed during the auction window
'-100005': OrderNotFound, # Open order not found
'-100006': InvalidOrder, # Open order is not owned by the user
'-100008': BadRequest, # Quantity cannot be less than the quantity increment xxx
'-100015': NetworkError, # recvWindow xxx has expired
'-710001': ExchangeError, # System failure, exception thrown -> xxx
'-710002': BadRequest, # The price is lower than the minimum
'-710003': BadRequest, # The price is higher than the maximum
'-710004': BadRequest, # Position quantity exceeds the limit
'-710005': InsufficientFunds, # Insufficient margin
'-710006': InsufficientFunds, # Insufficient balance
'-710007': InsufficientFunds, # Insufficient position
'-000101': NetworkError, # Internal server is unavailable temporary, try again later
'-000201': NetworkError, # Trade service is busy, try again later
},
'broad': {
'-20001': OperationFailed, # Operation failed, please contact system administrator
'-200050': RequestTimeout, # The market is not active
},
},
})
def fetch_markets(self, params={}) -> List[Market]:
"""
retrieves data on all markets for bitmex
https://docs.ox.fun/?json#get-v3-markets
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: an array of objects representing market data
"""
responseFromMarkets, responseFromTickers = [self.publicGetV3Markets(params), self.publicGetV3Tickers(params)]
marketsFromMarkets = self.safe_list(responseFromMarkets, 'data', [])
#
# {
# success: True,
# data: [
# {
# marketCode: 'OX-USD-SWAP-LIN',
# name: 'OX/USD Perp',
# referencePair: 'OX/USDT',
# base: 'OX',
# counter: 'USD',
# type: 'FUTURE',
# tickSize: '0.00001',
# minSize: '1',
# listedAt: '1704766320000',
# upperPriceBound: '0.02122',
# lowerPriceBound: '0.01142',
# markPrice: '0.01632',
# indexPrice: '0.01564',
# lastUpdatedAt: '1714762235569'
# },
# {
# marketCode: 'BTC-USD-SWAP-LIN',
# name: 'BTC/USD Perp',
# referencePair: 'BTC/USDT',
# base: 'BTC',
# counter: 'USD',
# type: 'FUTURE',
# tickSize: '1',
# minSize: '0.0001',
# listedAt: '1704686640000',
# upperPriceBound: '67983',
# lowerPriceBound: '55621',
# markPrice: '61802',
# indexPrice: '61813',
# lastUpdatedAt: '1714762234765'
# },
# {
# "marketCode": "MILK-OX",
# "name": "MILK/OX",
# "referencePair": "MILK/OX",
# "base": "MILK",
# "counter": "OX",
# "type": "SPOT",
# "tickSize": "0.0001",
# "minSize": "1",
# "listedAt": "1706608500000",
# "upperPriceBound": "1.0000",
# "lowerPriceBound": "-1.0000",
# "markPrice": "0.0269",
# "indexPrice": "0.0269",
# "lastUpdatedAt": "1714757402185"
# },
# ...
# ]
# }
#
marketsFromTickers = self.safe_list(responseFromTickers, 'data', [])
#
# {
# "success": True,
# "data": [
# {
# "marketCode": "DYM-USD-SWAP-LIN",
# "markPrice": "3.321",
# "open24h": "3.315",
# "high24h": "3.356",
# "low24h": "3.255",
# "volume24h": "0",
# "currencyVolume24h": "0",
# "openInterest": "1768.1",
# "lastTradedPrice": "3.543",
# "lastTradedQuantity": "1.0",
# "lastUpdatedAt": "1714853388102"
# },
# ...
# ]
# }
#
markets = self.array_concat(marketsFromMarkets, marketsFromTickers)
return self.parse_markets(markets)
def parse_markets(self, markets) -> List[Market]:
marketIds = []
result = []
for i in range(0, len(markets)):
market = markets[i]
marketId = self.safe_string(market, 'marketCode')
if not (self.in_array(marketId, marketIds)):
marketIds.append(marketId)
result.append(self.parse_market(market))
return result
def parse_market(self, market) -> Market:
id = self.safe_string(market, 'marketCode', '')
parts = id.split('-')
baseId = self.safe_string(parts, 0)
quoteId = self.safe_string(parts, 1)
base = self.safe_currency_code(baseId)
quote = self.safe_currency_code(quoteId)
symbol = base + '/' + quote
type = self.safe_string_lower(market, 'type', 'spot') # markets from v3/tickers are spot and have no type
settleId: Str = None
settle: Str = None
isFuture = (type == 'future') # the exchange has only perpetual futures
if isFuture:
type = 'swap'
settleId = 'OX'
settle = self.safe_currency_code('OX')
symbol = symbol + ':' + settle
isSpot = type == 'spot'
return self.safe_market_structure({
'id': id,
'numericId': None,
'symbol': symbol,
'base': base,
'quote': quote,
'settle': settle,
'baseId': baseId,
'quoteId': quoteId,
'settleId': settleId,
'type': type,
'spot': isSpot,
'margin': False,
'swap': isFuture,
'future': False,
'option': False,
'active': True,
'contract': isFuture,
'linear': True if isFuture else None,
'inverse': False if isFuture else None,
'taker': self.fees['trading']['taker'],
'maker': self.fees['trading']['maker'],
'contractSize': 1 if isFuture else None,
'expiry': None,
'expiryDatetime': None,
'strike': None,
'optionType': None,
'precision': {
'amount': None, # todo find it out
'price': self.safe_number(market, 'tickSize'),
},
'limits': {
'leverage': {
'min': None,
'max': None,
},
'amount': {
'min': self.safe_number(market, 'minSize'),
'max': None,
},
'price': {
'min': None,
'max': None,
},
'cost': {
'min': None,
'max': None,
},
},
'created': self.safe_integer(market, 'listedAt'),
'index': None,
'info': market,
})
def fetch_currencies(self, params={}) -> Currencies:
"""
fetches all available currencies on an exchange
https://docs.ox.fun/?json#get-v3-assets
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
"""
response = self.publicGetV3Assets(params)
#
# {
# "success": True,
# "data": [
# {
# "asset": "OX",
# "isCollateral": True,
# "loanToValue": "1.000000000",
# "loanToValueFactor": "0.000000000",
# "networkList": [
# {
# "network": "BNBSmartChain",
# "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
# "transactionPrecision": "18",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": False,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# },
# {
# "network": "Polygon",
# "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
# "transactionPrecision": "18",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": False,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# },
# {
# "network": "Arbitrum",
# "tokenId": "0xba0Dda8762C24dA9487f5FA026a9B64b695A07Ea",
# "transactionPrecision": "18",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": True,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# },
# {
# "network": "Ethereum",
# "tokenId": "0xba0Dda8762C24dA9487f5FA026a9B64b695A07Ea",
# "transactionPrecision": "18",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": True,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# },
# {
# "network": "Arbitrum",
# "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
# "transactionPrecision": "18",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": False,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# },
# {
# "network": "Avalanche",
# "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
# "transactionPrecision": "18",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": False,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# },
# {
# "network": "Solana",
# "tokenId": "DV3845GEAVXfwpyVGGgWbqBVCtzHdCXNCGfcdboSEuZz",
# "transactionPrecision": "8",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": True,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# },
# {
# "network": "Ethereum",
# "tokenId": "0x78a0A62Fba6Fb21A83FE8a3433d44C73a4017A6f",
# "transactionPrecision": "18",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": False,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# }
# ]
# },
# {
# "asset": "BTC",
# "isCollateral": True,
# "loanToValue": "0.950000000",
# "loanToValueFactor": "0.000000000",
# "networkList": [
# {
# "network": "Bitcoin",
# "transactionPrecision": "8",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": True,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# }
# ]
# },
# {
# "asset": "USDT.ARB",
# "isCollateral": True,
# "loanToValue": "0.950000000",
# "loanToValueFactor": "0.000000000",
# "networkList": [
# {
# "network": "Arbitrum",
# "tokenId": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
# "transactionPrecision": "18",
# "isWithdrawalFeeChargedToUser": True,
# "canDeposit": True,
# "canWithdraw": True,
# "minDeposit": "0.00010",
# "minWithdrawal": "0.00010"
# }
# ]
# },
# ...
# ]
# }
#
data = self.safe_list(response, 'data', [])
result: dict = {}
for i in range(0, len(data)):
currency = data[i]
fullId = self.safe_string(currency, 'asset', '')
parts = fullId.split('.')
id = parts[0]
code = self.safe_currency_code(id)
networks: dict = {}
chains = self.safe_list(currency, 'networkList', [])
currencyMaxPrecision: Str = None
currencyDepositEnabled: Bool = None
currencyWithdrawEnabled: Bool = None
for j in range(0, len(chains)):
chain = chains[j]
networkId = self.safe_string(chain, 'network')
networkCode = self.network_id_to_code(networkId)
deposit = self.safe_bool(chain, 'canDeposit')
withdraw = self.safe_bool(chain, 'canWithdraw')
active = (deposit and withdraw)
minDeposit = self.safe_string(chain, 'minDeposit')
minWithdrawal = self.safe_string(chain, 'minWithdrawal')
precision = self.parse_precision(self.safe_string(chain, 'transactionPrecision'))
networks[networkCode] = {
'id': networkId,
'network': networkCode,
'margin': None,
'deposit': deposit,
'withdraw': withdraw,
'active': active,
'fee': None,
'precision': self.parse_number(precision),
'limits': {
'deposit': {
'min': minDeposit,
'max': None,
},
'withdraw': {
'min': minWithdrawal,
'max': None,
},
},
'info': chain,
}
if (currencyDepositEnabled is None) or deposit:
currencyDepositEnabled = deposit
if (currencyWithdrawEnabled is None) or withdraw:
currencyWithdrawEnabled = withdraw
if (currencyMaxPrecision is None) or Precise.string_gt(currencyMaxPrecision, precision):
currencyMaxPrecision = precision
if code in result:
# checking for specific ids.ARB
networks = self.extend(result[code]['networks'], networks)
result[code] = {
'id': id,
'code': code,
'name': None,
'type': None,
'active': None,
'deposit': currencyDepositEnabled,
'withdraw': currencyWithdrawEnabled,
'fee': None,
'precision': self.parse_number(currencyMaxPrecision),
'limits': {
'amount': {
'min': None,
'max': None,
},
'withdraw': {
'min': None,
'max': None,
},
},
'networks': networks,
'info': currency,
}
return result
def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
"""
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
https://docs.ox.fun/?json#get-v3-tickers
:param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
"""
self.load_markets()
symbols = self.market_symbols(symbols)
response = self.publicGetV3Tickers(params)
#
# {
# "success": True,
# "data": [
# {
# "marketCode": "NII-USDT",
# "markPrice": "0",
# "open24h": "0",
# "high24h": "0",
# "low24h": "0",
# "volume24h": "0",
# "currencyVolume24h": "0",
# "openInterest": "0",
# "lastTradedPrice": "0",
# "lastTradedQuantity": "0",
# "lastUpdatedAt": "1714853388621"
# },
# {
# "marketCode": "GEC-USDT",
# "markPrice": "0",
# "open24h": "0",
# "high24h": "0",
# "low24h": "0",
# "volume24h": "0",
# "currencyVolume24h": "0",
# "openInterest": "0",
# "lastTradedPrice": "0",
# "lastTradedQuantity": "0",
# "lastUpdatedAt": "1714853388621"
# },
# {
# "marketCode": "DYM-USD-SWAP-LIN",
# "markPrice": "3.321",
# "open24h": "3.315",
# "high24h": "3.356",
# "low24h": "3.255",
# "volume24h": "0",
# "currencyVolume24h": "0",
# "openInterest": "1768.1",
# "lastTradedPrice": "3.543",
# "lastTradedQuantity": "1.0",
# "lastUpdatedAt": "1714853388102"
# },
# ...
# ]
# }
#
tickers = self.safe_list(response, 'data', [])
return self.parse_tickers(tickers, symbols)
def fetch_ticker(self, symbol: str, params={}) -> Ticker:
"""
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
https://docs.ox.fun/?json#get-v3-tickers
:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
"""
self.load_markets()
market = self.market(symbol)
request: dict = {
'marketCode': market['id'],
}
response = self.publicGetV3Tickers(self.extend(request, params))
#
# {
# "success": True,
# "data": [
# {
# "marketCode": "BTC-USD-SWAP-LIN",
# "markPrice": "64276",
# "open24h": "63674",
# "high24h": "64607",
# "low24h": "62933",
# "volume24h": "306317655.80000",
# "currencyVolume24h": "48.06810",
# "openInterest": "72.39250",
# "lastTradedPrice": "64300.0",
# "lastTradedQuantity": "1.0",
# "lastUpdatedAt": "1714925196034"
# }
# ]
# }
#
data = self.safe_list(response, 'data', [])
ticker = self.safe_dict(data, 0, {})
return self.parse_ticker(ticker, market)
def parse_ticker(self, ticker, market: Market = None) -> Ticker:
#
# {
# "marketCode": "BTC-USD-SWAP-LIN",
# "markPrice": "64276",
# "open24h": "63674",
# "high24h": "64607",
# "low24h": "62933",
# "volume24h": "306317655.80000",
# "currencyVolume24h": "48.06810",
# "openInterest": "72.39250",
# "lastTradedPrice": "64300.0",
# "lastTradedQuantity": "1.0",
# "lastUpdatedAt": "1714925196034"
# }
#
timestamp = self.safe_integer(ticker, 'lastUpdatedAt')
marketId = self.safe_string(ticker, 'marketCode')
market = self.safe_market(marketId, market)
symbol = market['symbol']
last = self.safe_string(ticker, 'lastTradedPrice')
return self.safe_ticker({
'symbol': symbol,
'timestamp': timestamp,
'datetime': self.iso8601(timestamp),
'high': self.safe_string(ticker, 'high24h'),
'low': self.safe_string(ticker, 'low24h'),
'bid': None,
'bidVolume': None,
'ask': None,
'askVolume': None,
'vwap': None,
'open': self.safe_string(ticker, 'open24h'),
'close': last,
'last': last,
'previousClose': None,
'change': None,
'percentage': None,
'average': None,
'baseVolume': self.safe_string(ticker, 'currencyVolume24h'),
'quoteVolume': None, # the exchange returns cost in OX
'markPrice': self.safe_string(ticker, 'markPrice'),
'info': ticker,
}, market)
def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
"""
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
https://docs.ox.fun/?json#get-v3-candles
:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch(default 24 hours ago)
:param int [limit]: the maximum amount of candles to fetch(default 200, max 500)
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: timestamp in ms of the latest candle to fetch(default now)
:returns int[][]: A list of candles ordered, open, high, low, close, volume
"""
self.load_markets()
market = self.market(symbol)
timeframe = self.safe_string(self.timeframes, timeframe, timeframe)
request: dict = {
'marketCode': market['id'],
'timeframe': timeframe,
}
if since is not None:
request['startTime'] = since # startTime and endTime must be within 7 days of each other
if limit is not None:
request['limit'] = limit
until = self.safe_integer(params, 'until')
if until is not None:
request['endTime'] = until
params = self.omit(params, 'until')
elif since is not None:
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
response = self.publicGetV3Candles(self.extend(request, params))
#
# {
# "success": True,
# "timeframe": "3600s",
# "data": [
# {
# "open": "0.03240000",
# "high": "0.03240000",
# "low": "0.03240000",
# "close": "0.03240000",
# "volume": "0",
# "currencyVolume": "0",
# "openedAt": "1714906800000"
# },
# {
# "open": "0.03240000",
# "high": "0.03240000",
# "low": "0.03240000",
# "close": "0.03240000",
# "volume": "0",
# "currencyVolume": "0",
# "openedAt": "1714903200000"
# },
# ...
# ]
# }
#
result = self.safe_list(response, 'data', [])
return self.parse_ohlcvs(result, market, timeframe, since, limit)
def parse_ohlcv(self, ohlcv, market: Market = None) -> list:
#
# {
# "open": "0.03240000",
# "high": "0.03240000",
# "low": "0.03240000",
# "close": "0.03240000",
# "volume": "0",
# "currencyVolume": "0",
# "openedAt": "1714906800000"
# }
#
return [
self.safe_integer(ohlcv, 'openedAt'),
self.safe_number(ohlcv, 'open'),
self.safe_number(ohlcv, 'high'),
self.safe_number(ohlcv, 'low'),
self.safe_number(ohlcv, 'close'),
self.safe_number(ohlcv, 'currencyVolume'),
]
def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
"""
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
https://docs.ox.fun/?json#get-v3-depth
:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return(default 5, max 100)
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
"""
self.load_markets()
market = self.market(symbol)
request: dict = {
'marketCode': market['id'],
}
if limit is not None:
request['level'] = limit
response = self.publicGetV3Depth(self.extend(request, params))
#
# {
# "success": True,
# "level": "5",
# "data": {
# "marketCode": "BTC-USD-SWAP-LIN",
# "lastUpdatedAt": "1714933499266",
# "asks": [
# [64073.0, 8.4622],
# [64092.0, 8.1912],
# [64111.0, 8.0669],
# [64130.0, 11.7195],
# [64151.0, 10.1798]
# ],
# "bids": [
# [64022.0, 10.1292],
# [64003.0, 8.1619],
# [64000.0, 1.0],
# [63984.0, 12.7724],
# [63963.0, 11.0073]
# ]
# }
# }
#
data = self.safe_dict(response, 'data', {})
timestamp = self.safe_integer(data, 'lastUpdatedAt')