ccxt 4.3.67__py2.py3-none-any.whl → 4.3.69__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. ccxt/__init__.py +1 -1
  2. ccxt/async_support/__init__.py +1 -1
  3. ccxt/async_support/base/exchange.py +1 -1
  4. ccxt/async_support/binance.py +2 -2
  5. ccxt/async_support/bingx.py +446 -215
  6. ccxt/async_support/bitget.py +5 -4
  7. ccxt/async_support/bitmart.py +2 -2
  8. ccxt/async_support/bitrue.py +2 -2
  9. ccxt/async_support/btcbox.py +1 -1
  10. ccxt/async_support/bybit.py +2 -2
  11. ccxt/async_support/coinbaseinternational.py +72 -1
  12. ccxt/async_support/coinex.py +2 -2
  13. ccxt/async_support/coinlist.py +2 -2
  14. ccxt/async_support/deribit.py +2 -2
  15. ccxt/async_support/digifinex.py +2 -2
  16. ccxt/async_support/hyperliquid.py +0 -2
  17. ccxt/async_support/kucoin.py +11 -5
  18. ccxt/async_support/latoken.py +2 -2
  19. ccxt/async_support/mexc.py +2 -2
  20. ccxt/async_support/okx.py +2 -2
  21. ccxt/async_support/oxfun.py +1 -1
  22. ccxt/async_support/phemex.py +2 -2
  23. ccxt/async_support/poloniex.py +33 -33
  24. ccxt/async_support/poloniexfutures.py +26 -26
  25. ccxt/async_support/woo.py +2 -2
  26. ccxt/base/exchange.py +333 -120
  27. ccxt/base/types.py +21 -3
  28. ccxt/binance.py +2 -2
  29. ccxt/bingx.py +446 -215
  30. ccxt/bitget.py +5 -4
  31. ccxt/bitmart.py +2 -2
  32. ccxt/bitrue.py +2 -2
  33. ccxt/btcbox.py +1 -1
  34. ccxt/bybit.py +2 -2
  35. ccxt/coinbaseinternational.py +72 -1
  36. ccxt/coinex.py +2 -2
  37. ccxt/coinlist.py +2 -2
  38. ccxt/deribit.py +2 -2
  39. ccxt/digifinex.py +2 -2
  40. ccxt/hyperliquid.py +0 -2
  41. ccxt/kucoin.py +11 -5
  42. ccxt/latoken.py +2 -2
  43. ccxt/mexc.py +2 -2
  44. ccxt/okx.py +2 -2
  45. ccxt/oxfun.py +1 -1
  46. ccxt/phemex.py +2 -2
  47. ccxt/poloniex.py +33 -33
  48. ccxt/poloniexfutures.py +26 -26
  49. ccxt/pro/__init__.py +1 -1
  50. ccxt/pro/krakenfutures.py +7 -6
  51. ccxt/pro/poloniex.py +13 -13
  52. ccxt/pro/poloniexfutures.py +5 -5
  53. ccxt/woo.py +2 -2
  54. {ccxt-4.3.67.dist-info → ccxt-4.3.69.dist-info}/METADATA +6 -6
  55. {ccxt-4.3.67.dist-info → ccxt-4.3.69.dist-info}/RECORD +58 -58
  56. {ccxt-4.3.67.dist-info → ccxt-4.3.69.dist-info}/LICENSE.txt +0 -0
  57. {ccxt-4.3.67.dist-info → ccxt-4.3.69.dist-info}/WHEEL +0 -0
  58. {ccxt-4.3.67.dist-info → ccxt-4.3.69.dist-info}/top_level.txt +0 -0
@@ -8,7 +8,7 @@ from ccxt.abstract.bingx import ImplicitAPI
8
8
  import asyncio
9
9
  import hashlib
10
10
  import numbers
11
- from ccxt.base.types import Balances, Currencies, Currency, Int, Leverage, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, Transaction, TransferEntry, TransferEntries
11
+ from ccxt.base.types import Balances, Currencies, Currency, Int, Leverage, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, Transaction, TransferEntry
12
12
  from typing import List
13
13
  from ccxt.base.errors import ExchangeError
14
14
  from ccxt.base.errors import AuthenticationError
@@ -63,6 +63,7 @@ class bingx(Exchange, ImplicitAPI):
63
63
  'createTrailingPercentOrder': True,
64
64
  'createTriggerOrder': True,
65
65
  'fetchBalance': True,
66
+ 'fetchCanceledOrders': True,
66
67
  'fetchClosedOrders': True,
67
68
  'fetchCurrencies': True,
68
69
  'fetchDepositAddress': True,
@@ -1110,7 +1111,27 @@ class bingx(Exchange, ImplicitAPI):
1110
1111
  # "s": "BTC-USDT"
1111
1112
  # }
1112
1113
  #
1113
- time = self.safe_integer_n(trade, ['time', 'filledTm', 'T'])
1114
+ # inverse swap fetchMyTrades
1115
+ #
1116
+ # {
1117
+ # "orderId": "1817441228670648320",
1118
+ # "symbol": "SOL-USD",
1119
+ # "type": "MARKET",
1120
+ # "side": "BUY",
1121
+ # "positionSide": "LONG",
1122
+ # "tradeId": "97244554",
1123
+ # "volume": "2",
1124
+ # "tradePrice": "182.652",
1125
+ # "amount": "20.00000000",
1126
+ # "realizedPnl": "0.00000000",
1127
+ # "commission": "-0.00005475",
1128
+ # "currency": "SOL",
1129
+ # "buyer": True,
1130
+ # "maker": False,
1131
+ # "tradeTime": 1722146730000
1132
+ # }
1133
+ #
1134
+ time = self.safe_integer_n(trade, ['time', 'filledTm', 'T', 'tradeTime'])
1114
1135
  datetimeId = self.safe_string(trade, 'filledTm')
1115
1136
  if datetimeId is not None:
1116
1137
  time = self.parse8601(datetimeId)
@@ -1121,8 +1142,8 @@ class bingx(Exchange, ImplicitAPI):
1121
1142
  currencyId = self.safe_string_n(trade, ['currency', 'N', 'commissionAsset'])
1122
1143
  currencyCode = self.safe_currency_code(currencyId)
1123
1144
  m = self.safe_bool(trade, 'm')
1124
- marketId = self.safe_string(trade, 's')
1125
- isBuyerMaker = self.safe_bool_2(trade, 'buyerMaker', 'isBuyerMaker')
1145
+ marketId = self.safe_string_2(trade, 's', 'symbol')
1146
+ isBuyerMaker = self.safe_bool_n(trade, ['buyerMaker', 'isBuyerMaker', 'maker'])
1126
1147
  takeOrMaker = None
1127
1148
  if (isBuyerMaker is not None) or (m is not None):
1128
1149
  takeOrMaker = 'maker' if (isBuyerMaker or m) else 'taker'
@@ -1153,7 +1174,7 @@ class bingx(Exchange, ImplicitAPI):
1153
1174
  'type': self.safe_string_lower(trade, 'o'),
1154
1175
  'side': self.parse_order_side(side),
1155
1176
  'takerOrMaker': takeOrMaker,
1156
- 'price': self.safe_string_2(trade, 'price', 'p'),
1177
+ 'price': self.safe_string_n(trade, ['price', 'p', 'tradePrice']),
1157
1178
  'amount': amount,
1158
1179
  'cost': cost,
1159
1180
  'fee': {
@@ -2842,8 +2863,7 @@ class bingx(Exchange, ImplicitAPI):
2842
2863
  # "clientOrderID": ""
2843
2864
  # }
2844
2865
  #
2845
- # inverse swap cancelAllOrders, cancelOrder
2846
- # inverse swap cancelAllOrders, cancelOrder, fetchOpenOrders
2866
+ # inverse swap cancelAllOrders, cancelOrder, fetchOrder, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders
2847
2867
  #
2848
2868
  # {
2849
2869
  # "symbol": "SOL-USD",
@@ -2901,7 +2921,7 @@ class bingx(Exchange, ImplicitAPI):
2901
2921
  side = self.safe_string_lower_2(order, 'side', 'S')
2902
2922
  timestamp = self.safe_integer_n(order, ['time', 'transactTime', 'E'])
2903
2923
  lastTradeTimestamp = self.safe_integer_2(order, 'updateTime', 'T')
2904
- statusId = self.safe_string_2(order, 'status', 'X')
2924
+ statusId = self.safe_string_upper_2(order, 'status', 'X')
2905
2925
  feeCurrencyCode = self.safe_string_2(order, 'feeAsset', 'N')
2906
2926
  feeCost = self.safe_string_n(order, ['fee', 'commission', 'n'])
2907
2927
  if (feeCurrencyCode is None):
@@ -3400,11 +3420,12 @@ class bingx(Exchange, ImplicitAPI):
3400
3420
  async def fetch_order(self, id: str, symbol: Str = None, params={}):
3401
3421
  """
3402
3422
  fetches information on an order made by the user
3403
- :see: https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Orders
3404
- :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20Order
3423
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20details
3424
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20details
3425
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Order
3405
3426
  :param str symbol: unified symbol of the market the order was made in
3406
3427
  :param dict [params]: extra parameters specific to the exchange API endpoint
3407
- :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3428
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
3408
3429
  """
3409
3430
  if symbol is None:
3410
3431
  raise ArgumentsRequired(self.id + ' fetchOrder() requires a symbol argument')
@@ -3414,66 +3435,120 @@ class bingx(Exchange, ImplicitAPI):
3414
3435
  'symbol': market['id'],
3415
3436
  'orderId': id,
3416
3437
  }
3438
+ type = None
3439
+ subType = None
3417
3440
  response = None
3418
- marketType, query = self.handle_market_type_and_params('fetchOrder', market, params)
3419
- if marketType == 'spot':
3420
- response = await self.spotV1PrivateGetTradeQuery(self.extend(request, query))
3441
+ type, params = self.handle_market_type_and_params('fetchOrder', market, params)
3442
+ subType, params = self.handle_sub_type_and_params('fetchOrder', market, params)
3443
+ if type == 'spot':
3444
+ response = await self.spotV1PrivateGetTradeQuery(self.extend(request, params))
3445
+ #
3446
+ # {
3447
+ # "code": 0,
3448
+ # "msg": "",
3449
+ # "data": {
3450
+ # "symbol": "XRP-USDT",
3451
+ # "orderId": 1514087361158316032,
3452
+ # "price": "0.5",
3453
+ # "origQty": "10",
3454
+ # "executedQty": "0",
3455
+ # "cummulativeQuoteQty": "0",
3456
+ # "status": "CANCELED",
3457
+ # "type": "LIMIT",
3458
+ # "side": "BUY",
3459
+ # "time": 1649821532000,
3460
+ # "updateTime": 1649821543000,
3461
+ # "origQuoteOrderQty": "0",
3462
+ # "fee": "0",
3463
+ # "feeAsset": "XRP"
3464
+ # }
3465
+ # }
3466
+ #
3421
3467
  else:
3422
- response = await self.swapV2PrivateGetTradeOrder(self.extend(request, query))
3423
- #
3424
- # spot
3425
- #
3426
- # {
3427
- # "code": 0,
3428
- # "msg": "",
3429
- # "data": {
3430
- # "symbol": "XRP-USDT",
3431
- # "orderId": 1514087361158316032,
3432
- # "price": "0.5",
3433
- # "origQty": "10",
3434
- # "executedQty": "0",
3435
- # "cummulativeQuoteQty": "0",
3436
- # "status": "CANCELED",
3437
- # "type": "LIMIT",
3438
- # "side": "BUY",
3439
- # "time": 1649821532000,
3440
- # "updateTime": 1649821543000,
3441
- # "origQuoteOrderQty": "0",
3442
- # "fee": "0",
3443
- # "feeAsset": "XRP"
3444
- # }
3445
- # }
3446
- #
3447
- # swap
3448
- #
3449
- # {
3450
- # "code": 0,
3451
- # "msg": "",
3452
- # "data": {
3453
- # "order": {
3454
- # "symbol": "BTC-USDT",
3455
- # "orderId": 1597597642269917184,
3456
- # "side": "SELL",
3457
- # "positionSide": "LONG",
3458
- # "type": "TAKE_PROFIT_MARKET",
3459
- # "origQty": "1.0000",
3460
- # "price": "0.0",
3461
- # "executedQty": "0.0000",
3462
- # "avgPrice": "0.0",
3463
- # "cumQuote": "",
3464
- # "stopPrice": "16494.0",
3465
- # "profit": "",
3466
- # "commission": "",
3467
- # "status": "FILLED",
3468
- # "time": 1669731935000,
3469
- # "updateTime": 1669752524000
3470
- # }
3471
- # }
3472
- # }
3473
- #
3474
- data = self.safe_value(response, 'data')
3475
- first = self.safe_dict(data, 'order', data)
3476
- return self.parse_order(first, market)
3468
+ if subType == 'inverse':
3469
+ response = await self.cswapV1PrivateGetTradeOrderDetail(self.extend(request, params))
3470
+ #
3471
+ # {
3472
+ # "code": 0,
3473
+ # "msg": "",
3474
+ # "data": {
3475
+ # "order": {
3476
+ # "symbol": "SOL-USD",
3477
+ # "orderId": "1816342420721254400",
3478
+ # "side": "BUY",
3479
+ # "positionSide": "Long",
3480
+ # "type": "LIMIT",
3481
+ # "quantity": 1,
3482
+ # "origQty": "",
3483
+ # "price": "150",
3484
+ # "executedQty": "0",
3485
+ # "avgPrice": "0.000",
3486
+ # "cumQuote": "",
3487
+ # "stopPrice": "",
3488
+ # "profit": "0.0000",
3489
+ # "commission": "0.0000",
3490
+ # "status": "Pending",
3491
+ # "time": 1721884753767,
3492
+ # "updateTime": 1721884753786,
3493
+ # "clientOrderId": "",
3494
+ # "leverage": "",
3495
+ # "takeProfit": {
3496
+ # "type": "TAKE_PROFIT",
3497
+ # "quantity": 0,
3498
+ # "stopPrice": 0,
3499
+ # "price": 0,
3500
+ # "workingType": "MARK_PRICE",
3501
+ # "stopGuaranteed": ""
3502
+ # },
3503
+ # "stopLoss": {
3504
+ # "type": "STOP",
3505
+ # "quantity": 0,
3506
+ # "stopPrice": 0,
3507
+ # "price": 0,
3508
+ # "workingType": "MARK_PRICE",
3509
+ # "stopGuaranteed": ""
3510
+ # },
3511
+ # "advanceAttr": 0,
3512
+ # "positionID": 0,
3513
+ # "takeProfitEntrustPrice": 0,
3514
+ # "stopLossEntrustPrice": 0,
3515
+ # "orderType": "",
3516
+ # "workingType": "MARK_PRICE"
3517
+ # }
3518
+ # }
3519
+ # }
3520
+ #
3521
+ else:
3522
+ response = await self.swapV2PrivateGetTradeOrder(self.extend(request, params))
3523
+ #
3524
+ # {
3525
+ # "code": 0,
3526
+ # "msg": "",
3527
+ # "data": {
3528
+ # "order": {
3529
+ # "symbol": "BTC-USDT",
3530
+ # "orderId": 1597597642269917184,
3531
+ # "side": "SELL",
3532
+ # "positionSide": "LONG",
3533
+ # "type": "TAKE_PROFIT_MARKET",
3534
+ # "origQty": "1.0000",
3535
+ # "price": "0.0",
3536
+ # "executedQty": "0.0000",
3537
+ # "avgPrice": "0.0",
3538
+ # "cumQuote": "",
3539
+ # "stopPrice": "16494.0",
3540
+ # "profit": "",
3541
+ # "commission": "",
3542
+ # "status": "FILLED",
3543
+ # "time": 1669731935000,
3544
+ # "updateTime": 1669752524000
3545
+ # }
3546
+ # }
3547
+ # }
3548
+ #
3549
+ data = self.safe_dict(response, 'data', {})
3550
+ order = self.safe_dict(data, 'order', data)
3551
+ return self.parse_order(order, market)
3477
3552
 
3478
3553
  async def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
3479
3554
  """
@@ -3709,8 +3784,47 @@ class bingx(Exchange, ImplicitAPI):
3709
3784
  async def fetch_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
3710
3785
  """
3711
3786
  fetches information on multiple closed orders made by the user
3712
- :see: https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Order%20History
3713
- :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
3787
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
3788
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
3789
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
3790
+ :see: https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
3791
+ :param str symbol: unified market symbol of the closed orders
3792
+ :param int [since]: timestamp in ms of the earliest order
3793
+ :param int [limit]: the max number of closed orders to return
3794
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3795
+ :param int [params.until]: the latest time in ms to fetch orders for
3796
+ :param boolean [params.standard]: whether to fetch standard contract orders
3797
+ :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3798
+ """
3799
+ await self.load_markets()
3800
+ orders = await self.fetch_canceled_and_closed_orders(symbol, since, limit, params)
3801
+ return self.filter_by(orders, 'status', 'closed')
3802
+
3803
+ async def fetch_canceled_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
3804
+ """
3805
+ fetches information on multiple canceled orders made by the user
3806
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
3807
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
3808
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
3809
+ :see: https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
3810
+ :param str symbol: unified market symbol of the canceled orders
3811
+ :param int [since]: timestamp in ms of the earliest order
3812
+ :param int [limit]: the max number of canceled orders to return
3813
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3814
+ :param int [params.until]: the latest time in ms to fetch orders for
3815
+ :param boolean [params.standard]: whether to fetch standard contract orders
3816
+ :returns dict: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
3817
+ """
3818
+ await self.load_markets()
3819
+ orders = await self.fetch_canceled_and_closed_orders(symbol, since, limit, params)
3820
+ return self.filter_by(orders, 'status', 'canceled')
3821
+
3822
+ async def fetch_canceled_and_closed_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
3823
+ """
3824
+ fetches information on multiple closed orders made by the user
3825
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20history
3826
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Order%20history
3827
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#User's%20History%20Orders
3714
3828
  :see: https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
3715
3829
  :param str [symbol]: unified market symbol of the market orders were made in
3716
3830
  :param int [since]: the earliest time in ms to fetch orders for
@@ -3727,72 +3841,128 @@ class bingx(Exchange, ImplicitAPI):
3727
3841
  request: dict = {
3728
3842
  'symbol': market['id'],
3729
3843
  }
3730
- response = None
3844
+ type = None
3845
+ subType = None
3731
3846
  standard = None
3847
+ response = None
3848
+ type, params = self.handle_market_type_and_params('fetchClosedOrders', market, params)
3849
+ subType, params = self.handle_sub_type_and_params('fetchClosedOrders', market, params)
3732
3850
  standard, params = self.handle_option_and_params(params, 'fetchClosedOrders', 'standard', False)
3733
- marketType, query = self.handle_market_type_and_params('fetchClosedOrders', market, params)
3734
3851
  if standard:
3735
- response = await self.contractV1PrivateGetAllOrders(self.extend(request, query))
3736
- elif marketType == 'spot':
3737
- response = await self.spotV1PrivateGetTradeHistoryOrders(self.extend(request, query))
3852
+ response = await self.contractV1PrivateGetAllOrders(self.extend(request, params))
3853
+ elif type == 'spot':
3854
+ response = await self.spotV1PrivateGetTradeHistoryOrders(self.extend(request, params))
3855
+ #
3856
+ # {
3857
+ # "code": 0,
3858
+ # "msg": "",
3859
+ # "data": {
3860
+ # "orders": [
3861
+ # {
3862
+ # "symbol": "XRP-USDT",
3863
+ # "orderId": 1514073325788200960,
3864
+ # "price": "0.5",
3865
+ # "origQty": "20",
3866
+ # "executedQty": "0",
3867
+ # "cummulativeQuoteQty": "0",
3868
+ # "status": "PENDING",
3869
+ # "type": "LIMIT",
3870
+ # "side": "BUY",
3871
+ # "time": 1649818185647,
3872
+ # "updateTime": 1649818185647,
3873
+ # "origQuoteOrderQty": "0"
3874
+ # }
3875
+ # ]
3876
+ # }
3877
+ # }
3878
+ #
3738
3879
  else:
3739
- response = await self.swapV2PrivateGetTradeAllOrders(self.extend(request, query))
3740
- #
3741
- # spot
3742
- #
3743
- # {
3744
- # "code": 0,
3745
- # "msg": "",
3746
- # "data": {
3747
- # "orders": [
3748
- # {
3749
- # "symbol": "XRP-USDT",
3750
- # "orderId": 1514073325788200960,
3751
- # "price": "0.5",
3752
- # "origQty": "20",
3753
- # "executedQty": "0",
3754
- # "cummulativeQuoteQty": "0",
3755
- # "status": "PENDING",
3756
- # "type": "LIMIT",
3757
- # "side": "BUY",
3758
- # "time": 1649818185647,
3759
- # "updateTime": 1649818185647,
3760
- # "origQuoteOrderQty": "0"
3761
- # }
3762
- # ]
3763
- # }
3764
- # }
3765
- #
3766
- # swap
3767
- #
3768
- # {
3769
- # "code": 0,
3770
- # "msg": "",
3771
- # "data": {
3772
- # "orders": [
3773
- # {
3774
- # "symbol": "LINK-USDT",
3775
- # "orderId": 1585839271162413056,
3776
- # "side": "BUY",
3777
- # "positionSide": "LONG",
3778
- # "type": "TRIGGER_MARKET",
3779
- # "origQty": "5.0",
3780
- # "price": "9",
3781
- # "executedQty": "0.0",
3782
- # "avgPrice": "0",
3783
- # "cumQuote": "0",
3784
- # "stopPrice": "5",
3785
- # "profit": "0.0000",
3786
- # "commission": "0.000000",
3787
- # "status": "CANCELLED",
3788
- # "time": 1667631605000,
3789
- # "updateTime": 1667631605000
3790
- # },
3791
- # ]
3792
- # }
3793
- # }
3794
- #
3795
- data = self.safe_value(response, 'data', [])
3880
+ if subType == 'inverse':
3881
+ response = await self.cswapV1PrivateGetTradeOrderHistory(self.extend(request, params))
3882
+ #
3883
+ # {
3884
+ # "code": 0,
3885
+ # "msg": "",
3886
+ # "data": {
3887
+ # "orders": [
3888
+ # {
3889
+ # "symbol": "SOL-USD",
3890
+ # "orderId": "1816002957423951872",
3891
+ # "side": "BUY",
3892
+ # "positionSide": "LONG",
3893
+ # "type": "LIMIT",
3894
+ # "quantity": 1,
3895
+ # "origQty": "10.00000000",
3896
+ # "price": "150.000",
3897
+ # "executedQty": "0.00000000",
3898
+ # "avgPrice": "0.000",
3899
+ # "cumQuote": "",
3900
+ # "stopPrice": "0.000",
3901
+ # "profit": "0.0000",
3902
+ # "commission": "0.000000",
3903
+ # "status": "Filled",
3904
+ # "time": 1721803819000,
3905
+ # "updateTime": 1721803856000,
3906
+ # "clientOrderId": "",
3907
+ # "leverage": "",
3908
+ # "takeProfit": {
3909
+ # "type": "",
3910
+ # "quantity": 0,
3911
+ # "stopPrice": 0,
3912
+ # "price": 0,
3913
+ # "workingType": "",
3914
+ # "stopGuaranteed": ""
3915
+ # },
3916
+ # "stopLoss": {
3917
+ # "type": "",
3918
+ # "quantity": 0,
3919
+ # "stopPrice": 0,
3920
+ # "price": 0,
3921
+ # "workingType": "",
3922
+ # "stopGuaranteed": ""
3923
+ # },
3924
+ # "advanceAttr": 0,
3925
+ # "positionID": 0,
3926
+ # "takeProfitEntrustPrice": 0,
3927
+ # "stopLossEntrustPrice": 0,
3928
+ # "orderType": "",
3929
+ # "workingType": "MARK_PRICE"
3930
+ # },
3931
+ # ]
3932
+ # }
3933
+ # }
3934
+ #
3935
+ else:
3936
+ response = await self.swapV2PrivateGetTradeAllOrders(self.extend(request, params))
3937
+ #
3938
+ # {
3939
+ # "code": 0,
3940
+ # "msg": "",
3941
+ # "data": {
3942
+ # "orders": [
3943
+ # {
3944
+ # "symbol": "LINK-USDT",
3945
+ # "orderId": 1585839271162413056,
3946
+ # "side": "BUY",
3947
+ # "positionSide": "LONG",
3948
+ # "type": "TRIGGER_MARKET",
3949
+ # "origQty": "5.0",
3950
+ # "price": "9",
3951
+ # "executedQty": "0.0",
3952
+ # "avgPrice": "0",
3953
+ # "cumQuote": "0",
3954
+ # "stopPrice": "5",
3955
+ # "profit": "0.0000",
3956
+ # "commission": "0.000000",
3957
+ # "status": "CANCELLED",
3958
+ # "time": 1667631605000,
3959
+ # "updateTime": 1667631605000
3960
+ # },
3961
+ # ]
3962
+ # }
3963
+ # }
3964
+ #
3965
+ data = self.safe_dict(response, 'data', {})
3796
3966
  orders = self.safe_list(data, 'orders', [])
3797
3967
  return self.parse_orders(orders, market, since, limit)
3798
3968
 
@@ -3835,7 +4005,7 @@ class bingx(Exchange, ImplicitAPI):
3835
4005
  'status': None,
3836
4006
  }
3837
4007
 
3838
- async def fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> TransferEntries:
4008
+ async def fetch_transfers(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[TransferEntry]:
3839
4009
  """
3840
4010
  fetch a history of internal transfers made on an account
3841
4011
  :see: https://bingx-api.github.io/docs/#/spot/account-api.html#Query%20User%20Universal%20Transfer%20History%20(USER_DATA)
@@ -4195,7 +4365,8 @@ class bingx(Exchange, ImplicitAPI):
4195
4365
  async def set_margin_mode(self, marginMode: str, symbol: Str = None, params={}):
4196
4366
  """
4197
4367
  set margin mode to 'cross' or 'isolated'
4198
- :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Switch%20Margin%20Mode
4368
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Change%20Margin%20Type
4369
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Set%20Margin%20Type
4199
4370
  :param str marginMode: 'cross' or 'isolated'
4200
4371
  :param str symbol: unified market symbol
4201
4372
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -4216,7 +4387,12 @@ class bingx(Exchange, ImplicitAPI):
4216
4387
  'symbol': market['id'],
4217
4388
  'marginType': marginMode,
4218
4389
  }
4219
- return await self.swapV2PrivatePostTradeMarginType(self.extend(request, params))
4390
+ subType = None
4391
+ subType, params = self.handle_sub_type_and_params('setMarginMode', market, params)
4392
+ if subType == 'inverse':
4393
+ return await self.cswapV1PrivatePostTradeMarginType(self.extend(request, params))
4394
+ else:
4395
+ return await self.swapV2PrivatePostTradeMarginType(self.extend(request, params))
4220
4396
 
4221
4397
  async def add_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
4222
4398
  request: dict = {
@@ -4441,93 +4617,129 @@ class bingx(Exchange, ImplicitAPI):
4441
4617
  async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
4442
4618
  """
4443
4619
  fetch all trades made by the user
4444
- :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20History
4445
- :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20historical%20transaction%20orders
4620
+ :see: https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20transaction%20details
4621
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20historical%20transaction%20orders
4622
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Order%20Trade%20Detail
4446
4623
  :param str [symbol]: unified market symbol
4447
4624
  :param int [since]: the earliest time in ms to fetch trades for
4448
4625
  :param int [limit]: the maximum number of trades structures to retrieve
4449
4626
  :param dict [params]: extra parameters specific to the exchange API endpoint
4450
4627
  :param int [params.until]: timestamp in ms for the ending date filter, default is None
4451
4628
  :param str params['trandingUnit']: COIN(directly represent assets such and ETH) or CONT(represents the number of contract sheets)
4629
+ :param str params['orderId']: the order id required for inverse swap
4452
4630
  :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
4453
4631
  """
4454
4632
  if symbol is None:
4455
4633
  raise ArgumentsRequired(self.id + ' fetchMyTrades() requires a symbol argument')
4456
4634
  await self.load_markets()
4457
4635
  market = self.market(symbol)
4458
- now = self.milliseconds()
4459
- response = None
4460
- request: dict = {
4461
- 'symbol': market['id'],
4462
- }
4463
- if since is not None:
4464
- startTimeReq = 'startTime' if market['spot'] else 'startTs'
4465
- request[startTimeReq] = since
4466
- elif market['swap']:
4467
- request['startTs'] = now - 7776000000 # 90 days
4468
- until = self.safe_integer(params, 'until')
4469
- params = self.omit(params, 'until')
4470
- if until is not None:
4471
- endTimeReq = 'endTime' if market['spot'] else 'endTs'
4472
- request[endTimeReq] = until
4473
- elif market['swap']:
4474
- request['endTs'] = now
4636
+ request: dict = {}
4475
4637
  fills = None
4476
- if market['spot']:
4477
- response = await self.spotV1PrivateGetTradeMyTrades(self.extend(request, params))
4478
- data = self.safe_dict(response, 'data', {})
4479
- fills = self.safe_list(data, 'fills', [])
4638
+ response = None
4639
+ subType = None
4640
+ subType, params = self.handle_sub_type_and_params('fetchMyTrades', market, params)
4641
+ if subType == 'inverse':
4642
+ orderId = self.safe_string(params, 'orderId')
4643
+ if orderId is None:
4644
+ raise ArgumentsRequired(self.id + ' fetchMyTrades() requires an orderId argument for inverse swap trades')
4645
+ response = await self.cswapV1PrivateGetTradeAllFillOrders(self.extend(request, params))
4646
+ fills = self.safe_list(response, 'data', [])
4480
4647
  #
4481
4648
  # {
4482
4649
  # "code": 0,
4483
4650
  # "msg": "",
4484
- # "debugMsg": "",
4485
- # "data": {
4486
- # "fills": [
4487
- # {
4488
- # "symbol": "LTC-USDT",
4489
- # "id": 36237072,
4490
- # "orderId": 1674069326895775744,
4491
- # "price": "85.891",
4492
- # "qty": "0.0582",
4493
- # "quoteQty": "4.9988562000000005",
4494
- # "commission": -0.00005820000000000001,
4495
- # "commissionAsset": "LTC",
4496
- # "time": 1687964205000,
4497
- # "isBuyer": True,
4498
- # "isMaker": False
4499
- # }
4500
- # ]
4501
- # }
4651
+ # "timestamp": 1722147756019,
4652
+ # "data": [
4653
+ # {
4654
+ # "orderId": "1817441228670648320",
4655
+ # "symbol": "SOL-USD",
4656
+ # "type": "MARKET",
4657
+ # "side": "BUY",
4658
+ # "positionSide": "LONG",
4659
+ # "tradeId": "97244554",
4660
+ # "volume": "2",
4661
+ # "tradePrice": "182.652",
4662
+ # "amount": "20.00000000",
4663
+ # "realizedPnl": "0.00000000",
4664
+ # "commission": "-0.00005475",
4665
+ # "currency": "SOL",
4666
+ # "buyer": True,
4667
+ # "maker": False,
4668
+ # "tradeTime": 1722146730000
4669
+ # }
4670
+ # ]
4502
4671
  # }
4503
4672
  #
4504
4673
  else:
4505
- tradingUnit = self.safe_string_upper(params, 'tradingUnit', 'CONT')
4506
- params = self.omit(params, 'tradingUnit')
4507
- request['tradingUnit'] = tradingUnit
4508
- response = await self.swapV2PrivateGetTradeAllFillOrders(self.extend(request, params))
4509
- data = self.safe_dict(response, 'data', {})
4510
- fills = self.safe_list(data, 'fill_orders', [])
4511
- #
4512
- # {
4513
- # "code": "0",
4514
- # "msg": '',
4515
- # "data": {fill_orders: [
4516
- # {
4517
- # "volume": "0.1",
4518
- # "price": "106.75",
4519
- # "amount": "10.6750",
4520
- # "commission": "-0.0053",
4521
- # "currency": "USDT",
4522
- # "orderId": "1676213270274379776",
4523
- # "liquidatedPrice": "0.00",
4524
- # "liquidatedMarginRatio": "0.00",
4525
- # "filledTime": "2023-07-04T20:56:01.000+0800"
4526
- # }
4527
- # ]
4528
- # }
4529
- # }
4530
- #
4674
+ request['symbol'] = market['id']
4675
+ now = self.milliseconds()
4676
+ if since is not None:
4677
+ startTimeReq = 'startTime' if market['spot'] else 'startTs'
4678
+ request[startTimeReq] = since
4679
+ elif market['swap']:
4680
+ request['startTs'] = now - 7776000000 # 90 days
4681
+ until = self.safe_integer(params, 'until')
4682
+ params = self.omit(params, 'until')
4683
+ if until is not None:
4684
+ endTimeReq = 'endTime' if market['spot'] else 'endTs'
4685
+ request[endTimeReq] = until
4686
+ elif market['swap']:
4687
+ request['endTs'] = now
4688
+ if market['spot']:
4689
+ response = await self.spotV1PrivateGetTradeMyTrades(self.extend(request, params))
4690
+ data = self.safe_dict(response, 'data', {})
4691
+ fills = self.safe_list(data, 'fills', [])
4692
+ #
4693
+ # {
4694
+ # "code": 0,
4695
+ # "msg": "",
4696
+ # "debugMsg": "",
4697
+ # "data": {
4698
+ # "fills": [
4699
+ # {
4700
+ # "symbol": "LTC-USDT",
4701
+ # "id": 36237072,
4702
+ # "orderId": 1674069326895775744,
4703
+ # "price": "85.891",
4704
+ # "qty": "0.0582",
4705
+ # "quoteQty": "4.9988562000000005",
4706
+ # "commission": -0.00005820000000000001,
4707
+ # "commissionAsset": "LTC",
4708
+ # "time": 1687964205000,
4709
+ # "isBuyer": True,
4710
+ # "isMaker": False
4711
+ # }
4712
+ # ]
4713
+ # }
4714
+ # }
4715
+ #
4716
+ else:
4717
+ tradingUnit = self.safe_string_upper(params, 'tradingUnit', 'CONT')
4718
+ params = self.omit(params, 'tradingUnit')
4719
+ request['tradingUnit'] = tradingUnit
4720
+ response = await self.swapV2PrivateGetTradeAllFillOrders(self.extend(request, params))
4721
+ data = self.safe_dict(response, 'data', {})
4722
+ fills = self.safe_list(data, 'fill_orders', [])
4723
+ #
4724
+ # {
4725
+ # "code": "0",
4726
+ # "msg": '',
4727
+ # "data": {fill_orders: [
4728
+ # {
4729
+ # "volume": "0.1",
4730
+ # "price": "106.75",
4731
+ # "amount": "10.6750",
4732
+ # "commission": "-0.0053",
4733
+ # "currency": "USDT",
4734
+ # "orderId": "1676213270274379776",
4735
+ # "liquidatedPrice": "0.00",
4736
+ # "liquidatedMarginRatio": "0.00",
4737
+ # "filledTime": "2023-07-04T20:56:01.000+0800"
4738
+ # }
4739
+ # ]
4740
+ # }
4741
+ # }
4742
+ #
4531
4743
  return self.parse_trades(fills, market, since, limit, params)
4532
4744
 
4533
4745
  def parse_deposit_withdraw_fee(self, fee, currency: Currency = None):
@@ -5108,7 +5320,8 @@ class bingx(Exchange, ImplicitAPI):
5108
5320
  async def fetch_margin_mode(self, symbol: str, params={}) -> MarginMode:
5109
5321
  """
5110
5322
  fetches the margin mode of the trading pair
5111
- :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Mode
5323
+ :see: https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Query%20Margin%20Type
5324
+ :see: https://bingx-api.github.io/docs/#/en-us/cswap/trade-api.html#Query%20Margin%20Type
5112
5325
  :param str symbol: unified symbol of the market to fetch the margin mode for
5113
5326
  :param dict [params]: extra parameters specific to the exchange API endpoint
5114
5327
  :returns dict: a `margin mode structure <https://docs.ccxt.com/#/?id=margin-mode-structure>`
@@ -5118,25 +5331,43 @@ class bingx(Exchange, ImplicitAPI):
5118
5331
  request: dict = {
5119
5332
  'symbol': market['id'],
5120
5333
  }
5121
- response = await self.swapV2PrivateGetTradeMarginType(self.extend(request, params))
5122
- #
5123
- # {
5124
- # "code": 0,
5125
- # "msg": "",
5126
- # "data": {
5127
- # "marginType": "CROSSED"
5128
- # }
5129
- # }
5130
- #
5334
+ subType = None
5335
+ response = None
5336
+ subType, params = self.handle_sub_type_and_params('fetchMarginMode', market, params)
5337
+ if subType == 'inverse':
5338
+ response = await self.cswapV1PrivateGetTradeMarginType(self.extend(request, params))
5339
+ #
5340
+ # {
5341
+ # "code": 0,
5342
+ # "msg": "",
5343
+ # "timestamp": 1721966069132,
5344
+ # "data": {
5345
+ # "symbol": "SOL-USD",
5346
+ # "marginType": "CROSSED"
5347
+ # }
5348
+ # }
5349
+ #
5350
+ else:
5351
+ response = await self.swapV2PrivateGetTradeMarginType(self.extend(request, params))
5352
+ #
5353
+ # {
5354
+ # "code": 0,
5355
+ # "msg": "",
5356
+ # "data": {
5357
+ # "marginType": "CROSSED"
5358
+ # }
5359
+ # }
5360
+ #
5131
5361
  data = self.safe_dict(response, 'data', {})
5132
5362
  return self.parse_margin_mode(data, market)
5133
5363
 
5134
5364
  def parse_margin_mode(self, marginMode: dict, market=None) -> MarginMode:
5365
+ marketId = self.safe_string(marginMode, 'symbol')
5135
5366
  marginType = self.safe_string_lower(marginMode, 'marginType')
5136
5367
  marginType = 'cross' if (marginType == 'crossed') else marginType
5137
5368
  return {
5138
5369
  'info': marginMode,
5139
- 'symbol': market['symbol'],
5370
+ 'symbol': self.safe_symbol(marketId, market, '-', 'swap'),
5140
5371
  'marginMode': marginType,
5141
5372
  }
5142
5373