ccxt 4.1.81__py2.py3-none-any.whl → 4.1.83__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.
ccxt/htx.py CHANGED
@@ -3192,14 +3192,16 @@ class htx(Exchange, ImplicitAPI):
3192
3192
  # "margin_mode": "cross",
3193
3193
  # "margin_account": "USDT",
3194
3194
  # "margin_asset": "USDT",
3195
- # "margin_balance": 200.000000000000000000,
3196
- # "margin_static": 200.000000000000000000,
3197
- # "margin_position": 0,
3198
- # "margin_frozen": 0,
3199
- # "profit_real": 0E-18,
3200
- # "profit_unreal": 0,
3201
- # "withdraw_available": 2E+2,
3202
- # "risk_rate": null,
3195
+ # "margin_balance": 49.874186030200000000,
3196
+ # "money_in": 50,
3197
+ # "money_out": 0,
3198
+ # "margin_static": 49.872786030200000000,
3199
+ # "margin_position": 6.180000000000000000,
3200
+ # "margin_frozen": 6.000000000000000000,
3201
+ # "profit_unreal": 0.001400000000000000,
3202
+ # "withdraw_available": 37.6927860302,
3203
+ # "risk_rate": 271.984050521072796934,
3204
+ # "new_risk_rate": 0.001858676950514399,
3203
3205
  # "contract_detail": [
3204
3206
  # {
3205
3207
  # "symbol": "MANA",
@@ -3292,8 +3294,8 @@ class htx(Exchange, ImplicitAPI):
3292
3294
  result[symbol] = self.safe_balance(accountsByCode)
3293
3295
  else:
3294
3296
  account = self.account()
3295
- account['free'] = self.safe_string(first, 'margin_balance', 'margin_available')
3296
- account['used'] = self.safe_string(first, 'margin_frozen')
3297
+ account['free'] = self.safe_string(first, 'withdraw_available')
3298
+ account['total'] = self.safe_string(first, 'margin_balance')
3297
3299
  currencyId = self.safe_string_2(first, 'margin_asset', 'symbol')
3298
3300
  code = self.safe_currency_code(currencyId)
3299
3301
  result[code] = account
ccxt/lbank.py CHANGED
@@ -17,6 +17,7 @@ from ccxt.base.errors import InsufficientFunds
17
17
  from ccxt.base.errors import InvalidAddress
18
18
  from ccxt.base.errors import InvalidOrder
19
19
  from ccxt.base.errors import DuplicateOrderId
20
+ from ccxt.base.errors import NotSupported
20
21
  from ccxt.base.errors import RateLimitExceeded
21
22
  from ccxt.base.errors import InvalidNonce
22
23
  from ccxt.base.errors import AuthenticationError
@@ -45,6 +46,9 @@ class lbank(Exchange, ImplicitAPI):
45
46
  'addMargin': False,
46
47
  'cancelAllOrders': True,
47
48
  'cancelOrder': True,
49
+ 'createMarketBuyOrderWithCost': True,
50
+ 'createMarketOrderWithCost': False,
51
+ 'createMarketSellOrderWithCost': False,
48
52
  'createOrder': True,
49
53
  'createReduceOnlyOrder': False,
50
54
  'createStopLimitOrder': False,
@@ -115,10 +119,10 @@ class lbank(Exchange, ImplicitAPI):
115
119
  'contract': 'https://lbkperp.lbank.com',
116
120
  },
117
121
  'api2': 'https://api.lbkex.com',
118
- 'www': 'https://www.lbank.info',
119
- 'doc': 'https://www.lbank.info/en-US/docs/index.html',
120
- 'fees': 'https://lbankinfo.zendesk.com/hc/en-gb/articles/360012072873-Trading-Fees',
121
- 'referral': 'https://www.lbank.info/invitevip?icode=7QCY',
122
+ 'www': 'https://www.lbank.com',
123
+ 'doc': 'https://www.lbank.com/en-US/docs/index.html',
124
+ 'fees': 'https://support.lbank.site/hc/en-gb/articles/900000535703-Trading-Fees-From-14-00-on-April-7-2020-UTC-8-',
125
+ 'referral': 'https://www.lbank.com/login/?icode=7QCY',
122
126
  },
123
127
  'api': {
124
128
  'spot': {
@@ -304,7 +308,7 @@ class lbank(Exchange, ImplicitAPI):
304
308
  def fetch_time(self, params={}):
305
309
  """
306
310
  fetches the current integer timestamp in milliseconds from the exchange server
307
- :see: https://www.lbank.info/en-US/docs/index.html#get-timestamp
311
+ :see: https://www.lbank.com/en-US/docs/index.html#get-timestamp
308
312
  :see: https://www.lbank.com/en-US/docs/contract.html#get-the-current-time
309
313
  :param dict [params]: extra parameters specific to the exchange API endpoint
310
314
  :returns int: the current integer timestamp in milliseconds from the exchange server
@@ -591,7 +595,7 @@ class lbank(Exchange, ImplicitAPI):
591
595
  def fetch_ticker(self, symbol: str, params={}) -> Ticker:
592
596
  """
593
597
  fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
594
- :see: https://www.lbank.info/en-US/docs/index.html#query-current-market-data-new
598
+ :see: https://www.lbank.com/en-US/docs/index.html#query-current-market-data-new
595
599
  :param str symbol: unified symbol of the market to fetch the ticker for
596
600
  :param dict [params]: extra parameters specific to the exchange API endpoint
597
601
  :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
@@ -633,7 +637,7 @@ class lbank(Exchange, ImplicitAPI):
633
637
  def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
634
638
  """
635
639
  fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
636
- :see: https://www.lbank.info/en-US/docs/index.html#query-current-market-data-new
640
+ :see: https://www.lbank.com/en-US/docs/index.html#query-current-market-data-new
637
641
  :see: https://www.lbank.com/en-US/docs/contract.html#query-contract-market-list
638
642
  :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
639
643
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -707,7 +711,7 @@ class lbank(Exchange, ImplicitAPI):
707
711
  def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
708
712
  """
709
713
  fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
710
- :see: https://www.lbank.info/en-US/docs/index.html#query-market-depth
714
+ :see: https://www.lbank.com/en-US/docs/index.html#query-market-depth
711
715
  :see: https://www.lbank.com/en-US/docs/contract.html#get-handicap
712
716
  :param str symbol: unified symbol of the market to fetch the order book for
713
717
  :param int [limit]: the maximum amount of order book entries to return
@@ -880,8 +884,8 @@ class lbank(Exchange, ImplicitAPI):
880
884
  def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
881
885
  """
882
886
  get the list of most recent trades for a particular symbol
883
- :see: https://www.lbank.info/en-US/docs/index.html#query-historical-transactions
884
- :see: https://www.lbank.info/en-US/docs/index.html#recent-transactions-list
887
+ :see: https://www.lbank.com/en-US/docs/index.html#query-historical-transactions
888
+ :see: https://www.lbank.com/en-US/docs/index.html#recent-transactions-list
885
889
  :param str symbol: unified symbol of the market to fetch trades for
886
890
  :param int [since]: timestamp in ms of the earliest trade to fetch
887
891
  :param int [limit]: the maximum amount of trades to fetch
@@ -947,7 +951,7 @@ class lbank(Exchange, ImplicitAPI):
947
951
  def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
948
952
  """
949
953
  fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
950
- :see: https://www.lbank.info/en-US/docs/index.html#query-k-bar-data
954
+ :see: https://www.lbank.com/en-US/docs/index.html#query-k-bar-data
951
955
  :param str symbol: unified symbol of the market to fetch OHLCV data for
952
956
  :param str timeframe: the length of time each candle represents
953
957
  :param int [since]: timestamp in ms of the earliest candle to fetch
@@ -1122,9 +1126,9 @@ class lbank(Exchange, ImplicitAPI):
1122
1126
  def fetch_balance(self, params={}) -> Balances:
1123
1127
  """
1124
1128
  query for balance and get the amount of funds available for trading or funds locked in orders
1125
- :see: https://www.lbank.info/en-US/docs/index.html#asset-information
1126
- :see: https://www.lbank.info/en-US/docs/index.html#account-information
1127
- :see: https://www.lbank.info/en-US/docs/index.html#get-all-coins-information
1129
+ :see: https://www.lbank.com/en-US/docs/index.html#asset-information
1130
+ :see: https://www.lbank.com/en-US/docs/index.html#account-information
1131
+ :see: https://www.lbank.com/en-US/docs/index.html#get-all-coins-information
1128
1132
  :param dict [params]: extra parameters specific to the exchange API endpoint
1129
1133
  :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
1130
1134
  """
@@ -1186,7 +1190,7 @@ class lbank(Exchange, ImplicitAPI):
1186
1190
  def fetch_trading_fee(self, symbol: str, params={}):
1187
1191
  """
1188
1192
  fetch the trading fees for a market
1189
- :see: https://www.lbank.info/en-US/docs/index.html#transaction-fee-rate-query
1193
+ :see: https://www.lbank.com/en-US/docs/index.html#transaction-fee-rate-query
1190
1194
  :param str symbol: unified market symbol
1191
1195
  :param dict [params]: extra parameters specific to the exchange API endpoint
1192
1196
  :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
@@ -1198,7 +1202,7 @@ class lbank(Exchange, ImplicitAPI):
1198
1202
  def fetch_trading_fees(self, params={}):
1199
1203
  """
1200
1204
  fetch the trading fees for multiple markets
1201
- :see: https://www.lbank.info/en-US/docs/index.html#transaction-fee-rate-query
1205
+ :see: https://www.lbank.com/en-US/docs/index.html#transaction-fee-rate-query
1202
1206
  :param dict [params]: extra parameters specific to the exchange API endpoint
1203
1207
  :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
1204
1208
  """
@@ -1213,11 +1217,28 @@ class lbank(Exchange, ImplicitAPI):
1213
1217
  result[symbol] = fee
1214
1218
  return result
1215
1219
 
1220
+ def create_market_buy_order_with_cost(self, symbol: str, cost, params={}):
1221
+ """
1222
+ create a market buy order by providing the symbol and cost
1223
+ :see: https://www.lbank.com/en-US/docs/index.html#place-order
1224
+ :see: https://www.lbank.com/en-US/docs/index.html#place-an-order
1225
+ :param str symbol: unified symbol of the market to create an order in
1226
+ :param float cost: how much you want to trade in units of the quote currency
1227
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1228
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1229
+ """
1230
+ self.load_markets()
1231
+ market = self.market(symbol)
1232
+ if not market['spot']:
1233
+ raise NotSupported(self.id + ' createMarketBuyOrderWithCost() supports spot orders only')
1234
+ params['createMarketBuyOrderRequiresPrice'] = False
1235
+ return self.create_order(symbol, 'market', 'buy', cost, None, params)
1236
+
1216
1237
  def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount, price=None, params={}):
1217
1238
  """
1218
1239
  create a trade order
1219
- :see: https://www.lbank.info/en-US/docs/index.html#place-order
1220
- :see: https://www.lbank.info/en-US/docs/index.html#place-an-order
1240
+ :see: https://www.lbank.com/en-US/docs/index.html#place-order
1241
+ :see: https://www.lbank.com/en-US/docs/index.html#place-an-order
1221
1242
  :param str symbol: unified symbol of the market to create an order in
1222
1243
  :param str type: 'market' or 'limit'
1223
1244
  :param str side: 'buy' or 'sell'
@@ -1256,17 +1277,25 @@ class lbank(Exchange, ImplicitAPI):
1256
1277
  request['amount'] = self.amount_to_precision(symbol, amount)
1257
1278
  elif side == 'buy':
1258
1279
  request['type'] = side + '_' + 'market'
1259
- if self.options['createMarketBuyOrderRequiresPrice']:
1280
+ quoteAmount = None
1281
+ createMarketBuyOrderRequiresPrice = True
1282
+ createMarketBuyOrderRequiresPrice, params = self.handle_option_and_params(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', True)
1283
+ cost = self.safe_number(params, 'cost')
1284
+ params = self.omit(params, 'cost')
1285
+ if cost is not None:
1286
+ quoteAmount = self.cost_to_precision(symbol, cost)
1287
+ elif createMarketBuyOrderRequiresPrice:
1260
1288
  if price is None:
1261
- raise InvalidOrder(self.id + " createOrder() requires the price argument with market buy orders to calculate total order cost(amount to spend), where cost = amount * price. Supply the price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = False to supply the cost in the amount argument(the exchange-specific behaviour)")
1289
+ raise InvalidOrder(self.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argument')
1262
1290
  else:
1263
1291
  amountString = self.number_to_string(amount)
1264
1292
  priceString = self.number_to_string(price)
1265
- quoteAmount = Precise.string_mul(amountString, priceString)
1266
- cost = self.parse_number(quoteAmount)
1267
- request['price'] = self.price_to_precision(symbol, cost)
1293
+ costRequest = Precise.string_mul(amountString, priceString)
1294
+ quoteAmount = self.cost_to_precision(symbol, costRequest)
1268
1295
  else:
1269
- request['price'] = amount
1296
+ quoteAmount = self.cost_to_precision(symbol, amount)
1297
+ # market buys require filling the price param instead of the amount param, for market buys the price is treated cost by lbank
1298
+ request['price'] = quoteAmount
1270
1299
  if clientOrderId is not None:
1271
1300
  request['custom_id'] = clientOrderId
1272
1301
  method = None
@@ -1427,8 +1456,8 @@ class lbank(Exchange, ImplicitAPI):
1427
1456
  def fetch_order(self, id: str, symbol: Str = None, params={}):
1428
1457
  """
1429
1458
  fetches information on an order made by the user
1430
- :see: https://www.lbank.info/en-US/docs/index.html#query-order
1431
- :see: https://www.lbank.info/en-US/docs/index.html#query-order-new
1459
+ :see: https://www.lbank.com/en-US/docs/index.html#query-order
1460
+ :see: https://www.lbank.com/en-US/docs/index.html#query-order-new
1432
1461
  :param str symbol: unified symbol of the market the order was made in
1433
1462
  :param dict [params]: extra parameters specific to the exchange API endpoint
1434
1463
  :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
@@ -1523,7 +1552,7 @@ class lbank(Exchange, ImplicitAPI):
1523
1552
  def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1524
1553
  """
1525
1554
  fetch all trades made by the user
1526
- :see: https://www.lbank.info/en-US/docs/index.html#past-transaction-details
1555
+ :see: https://www.lbank.com/en-US/docs/index.html#past-transaction-details
1527
1556
  :param str symbol: unified market symbol
1528
1557
  :param int [since]: the earliest time in ms to fetch trades for
1529
1558
  :param int [limit]: the maximum number of trade structures to retrieve
@@ -1577,7 +1606,7 @@ class lbank(Exchange, ImplicitAPI):
1577
1606
  def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1578
1607
  """
1579
1608
  fetches information on multiple orders made by the user
1580
- :see: https://www.lbank.info/en-US/docs/index.html#query-all-orders
1609
+ :see: https://www.lbank.com/en-US/docs/index.html#query-all-orders
1581
1610
  :param str symbol: unified market symbol of the market orders were made in
1582
1611
  :param int [since]: the earliest time in ms to fetch orders for
1583
1612
  :param int [limit]: the maximum number of order structures to retrieve
@@ -1633,7 +1662,7 @@ class lbank(Exchange, ImplicitAPI):
1633
1662
  def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1634
1663
  """
1635
1664
  fetch all unfilled currently open orders
1636
- :see: https://www.lbank.info/en-US/docs/index.html#current-pending-order
1665
+ :see: https://www.lbank.com/en-US/docs/index.html#current-pending-order
1637
1666
  :param str symbol: unified market symbol
1638
1667
  :param int [since]: the earliest time in ms to fetch open orders for
1639
1668
  :param int [limit]: the maximum number of open order structures to retrieve
@@ -1686,7 +1715,7 @@ class lbank(Exchange, ImplicitAPI):
1686
1715
  def cancel_order(self, id: str, symbol: Str = None, params={}):
1687
1716
  """
1688
1717
  cancels an open order
1689
- :see: https://www.lbank.info/en-US/docs/index.html#cancel-order-new
1718
+ :see: https://www.lbank.com/en-US/docs/index.html#cancel-order-new
1690
1719
  :param str id: order id
1691
1720
  :param str symbol: unified symbol of the market the order was made in
1692
1721
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -1724,7 +1753,7 @@ class lbank(Exchange, ImplicitAPI):
1724
1753
  def cancel_all_orders(self, symbol: Str = None, params={}):
1725
1754
  """
1726
1755
  cancel all open orders in a market
1727
- :see: https://www.lbank.info/en-US/docs/index.html#cancel-all-pending-orders-for-a-single-trading-pair
1756
+ :see: https://www.lbank.com/en-US/docs/index.html#cancel-all-pending-orders-for-a-single-trading-pair
1728
1757
  :param str symbol: unified market symbol of the market to cancel orders in
1729
1758
  :param dict [params]: extra parameters specific to the exchange API endpoint
1730
1759
  :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
@@ -1768,8 +1797,8 @@ class lbank(Exchange, ImplicitAPI):
1768
1797
  def fetch_deposit_address(self, code: str, params={}):
1769
1798
  """
1770
1799
  fetch the deposit address for a currency associated with self account
1771
- :see: https://www.lbank.info/en-US/docs/index.html#get-deposit-address
1772
- :see: https://www.lbank.info/en-US/docs/index.html#the-user-obtains-the-deposit-address
1800
+ :see: https://www.lbank.com/en-US/docs/index.html#get-deposit-address
1801
+ :see: https://www.lbank.com/en-US/docs/index.html#the-user-obtains-the-deposit-address
1773
1802
  :param str code: unified currency code
1774
1803
  :param dict [params]: extra parameters specific to the exchange API endpoint
1775
1804
  :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
@@ -1862,7 +1891,7 @@ class lbank(Exchange, ImplicitAPI):
1862
1891
  def withdraw(self, code: str, amount, address, tag=None, params={}):
1863
1892
  """
1864
1893
  make a withdrawal
1865
- :see: https://www.lbank.info/en-US/docs/index.html#withdrawal
1894
+ :see: https://www.lbank.com/en-US/docs/index.html#withdrawal
1866
1895
  :param str code: unified currency code
1867
1896
  :param float amount: the amount to withdraw
1868
1897
  :param str address: the address to withdraw to
@@ -2019,7 +2048,7 @@ class lbank(Exchange, ImplicitAPI):
2019
2048
  def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
2020
2049
  """
2021
2050
  fetch all deposits made to an account
2022
- :see: https://www.lbank.info/en-US/docs/index.html#get-recharge-history
2051
+ :see: https://www.lbank.com/en-US/docs/index.html#get-recharge-history
2023
2052
  :param str code: unified currency code
2024
2053
  :param int [since]: the earliest time in ms to fetch deposits for
2025
2054
  :param int [limit]: the maximum number of deposits structures to retrieve
@@ -2068,7 +2097,7 @@ class lbank(Exchange, ImplicitAPI):
2068
2097
  def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
2069
2098
  """
2070
2099
  fetch all withdrawals made from an account
2071
- :see: https://www.lbank.info/en-US/docs/index.html#get-withdrawal-history
2100
+ :see: https://www.lbank.com/en-US/docs/index.html#get-withdrawal-history
2072
2101
  :param str code: unified currency code
2073
2102
  :param int [since]: the earliest time in ms to fetch withdrawals for
2074
2103
  :param int [limit]: the maximum number of withdrawals structures to retrieve
@@ -2254,8 +2283,8 @@ class lbank(Exchange, ImplicitAPI):
2254
2283
  def fetch_deposit_withdraw_fees(self, codes: Strings = None, params={}):
2255
2284
  """
2256
2285
  when using private endpoint, only returns information for currencies with non-zero balance, use public method by specifying self.options['fetchDepositWithdrawFees']['method'] = 'fetchPublicDepositWithdrawFees'
2257
- :see: https://www.lbank.info/en-US/docs/index.html#get-all-coins-information
2258
- :see: https://www.lbank.info/en-US/docs/index.html#withdrawal-configurations
2286
+ :see: https://www.lbank.com/en-US/docs/index.html#get-all-coins-information
2287
+ :see: https://www.lbank.com/en-US/docs/index.html#withdrawal-configurations
2259
2288
  :param str[]|None codes: array of unified currency codes
2260
2289
  :param dict [params]: extra parameters specific to the exchange API endpoint
2261
2290
  :returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
ccxt/okx.py CHANGED
@@ -56,6 +56,8 @@ class okx(Exchange, ImplicitAPI):
56
56
  'cancelAllOrders': False,
57
57
  'cancelOrder': True,
58
58
  'cancelOrders': True,
59
+ 'closeAllPositions': False,
60
+ 'closePosition': True,
59
61
  'createDepositAddress': False,
60
62
  'createMarketBuyOrderWithCost': True,
61
63
  'createMarketSellOrderWithCost': True,
@@ -2953,7 +2955,11 @@ class okx(Exchange, ImplicitAPI):
2953
2955
  'instId': market['id'],
2954
2956
  'clOrdId': clientOrderIds[i],
2955
2957
  })
2956
- response = getattr(self, method)(request) # * dont self.extend with params, otherwise ARRAY will be turned into OBJECT
2958
+ response = None
2959
+ if method == 'privatePostTradeCancelAlgos':
2960
+ response = self.privatePostTradeCancelAlgos(request) # * dont self.extend with params, otherwise ARRAY will be turned into OBJECT
2961
+ else:
2962
+ response = self.privatePostTradeCancelBatchOrders(request) # * dont self.extend with params, otherwise ARRAY will be turned into OBJECT
2957
2963
  #
2958
2964
  # {
2959
2965
  # "code": "0",
@@ -3234,7 +3240,11 @@ class okx(Exchange, ImplicitAPI):
3234
3240
  else:
3235
3241
  request['ordId'] = id
3236
3242
  query = self.omit(params, ['method', 'clOrdId', 'clientOrderId', 'stop'])
3237
- response = getattr(self, method)(self.extend(request, query))
3243
+ response = None
3244
+ if method == 'privateGetTradeOrderAlgo':
3245
+ response = self.privateGetTradeOrderAlgo(self.extend(request, query))
3246
+ else:
3247
+ response = self.privateGetTradeOrder(self.extend(request, query))
3238
3248
  #
3239
3249
  # Spot and Swap
3240
3250
  #
@@ -3385,7 +3395,11 @@ class okx(Exchange, ImplicitAPI):
3385
3395
  if ordType is None:
3386
3396
  raise ArgumentsRequired(self.id + ' fetchOpenOrders() requires an "ordType" string parameter, "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"')
3387
3397
  query = self.omit(params, ['method', 'stop'])
3388
- response = getattr(self, method)(self.extend(request, query))
3398
+ response = None
3399
+ if method == 'privateGetTradeOrdersAlgoPending':
3400
+ response = self.privateGetTradeOrdersAlgoPending(self.extend(request, query))
3401
+ else:
3402
+ response = self.privateGetTradeOrdersPending(self.extend(request, query))
3389
3403
  #
3390
3404
  # {
3391
3405
  # "code": "0",
@@ -3546,7 +3560,11 @@ class okx(Exchange, ImplicitAPI):
3546
3560
  request['end'] = until
3547
3561
  query = self.omit(query, ['until', 'till'])
3548
3562
  send = self.omit(query, ['method', 'stop', 'ordType'])
3549
- response = getattr(self, method)(self.extend(request, send))
3563
+ response = None
3564
+ if method == 'privateGetTradeOrdersAlgoHistory':
3565
+ response = self.privateGetTradeOrdersAlgoHistory(self.extend(request, send))
3566
+ else:
3567
+ response = self.privateGetTradeOrdersHistory(self.extend(request, send))
3550
3568
  #
3551
3569
  # {
3552
3570
  # "code": "0",
@@ -3712,7 +3730,11 @@ class okx(Exchange, ImplicitAPI):
3712
3730
  query = self.omit(query, ['until', 'till'])
3713
3731
  request['state'] = 'filled'
3714
3732
  send = self.omit(query, ['method', 'stop'])
3715
- response = getattr(self, method)(self.extend(request, send))
3733
+ response = None
3734
+ if method == 'privateGetTradeOrdersAlgoHistory':
3735
+ response = self.privateGetTradeOrdersAlgoHistory(self.extend(request, send))
3736
+ else:
3737
+ response = self.privateGetTradeOrdersHistory(self.extend(request, send))
3716
3738
  #
3717
3739
  # {
3718
3740
  # "code": "0",
@@ -3949,7 +3971,13 @@ class okx(Exchange, ImplicitAPI):
3949
3971
  currency = self.currency(code)
3950
3972
  request['ccy'] = currency['id']
3951
3973
  request, params = self.handle_until_option('end', request, params)
3952
- response = getattr(self, method)(self.extend(request, query))
3974
+ response = None
3975
+ if method == 'privateGetAccountBillsArchive':
3976
+ response = self.privateGetAccountBillsArchive(self.extend(request, query))
3977
+ elif method == 'privateGetAssetBills':
3978
+ response = self.privateGetAssetBills(self.extend(request, query))
3979
+ else:
3980
+ response = self.privateGetAccountBills(self.extend(request, query))
3953
3981
  #
3954
3982
  # privateGetAccountBills, privateGetAccountBillsArchive
3955
3983
  #
@@ -4802,7 +4830,11 @@ class okx(Exchange, ImplicitAPI):
4802
4830
  request['instId'] = ','.join(marketIds)
4803
4831
  fetchPositionsOptions = self.safe_value(self.options, 'fetchPositions', {})
4804
4832
  method = self.safe_string(fetchPositionsOptions, 'method', 'privateGetAccountPositions')
4805
- response = getattr(self, method)(self.extend(request, params))
4833
+ response = None
4834
+ if method == 'privateGetAccountPositionsHistory':
4835
+ response = self.privateGetAccountPositionsHistory(self.extend(request, params))
4836
+ else:
4837
+ response = self.privateGetAccountPositions(self.extend(request, params))
4806
4838
  #
4807
4839
  # {
4808
4840
  # "code": "0",
@@ -6661,6 +6693,66 @@ class okx(Exchange, ImplicitAPI):
6661
6693
  'info': greeks,
6662
6694
  }
6663
6695
 
6696
+ def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
6697
+ """
6698
+ closes open positions for a market
6699
+ :see: https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-close-positions
6700
+ :param str symbol: Unified CCXT market symbol
6701
+ :param str [side]: 'buy' or 'sell', leave in net mode
6702
+ :param dict [params]: extra parameters specific to the okx api endpoint
6703
+ :param str [params.clientOrderId]: a unique identifier for the order
6704
+ :param str [params.marginMode]: 'cross' or 'isolated', default is 'cross
6705
+ :param str [params.code]: *required in the case of closing cross MARGIN position for Single-currency margin* margin currency
6706
+ *
6707
+ * EXCHANGE SPECIFIC PARAMETERS
6708
+ :param boolean [params.autoCxl]: whether any pending orders for closing out needs to be automatically canceled when close position via a market order. False or True, the default is False
6709
+ :param str [params.tag]: order tag a combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters
6710
+ :returns [dict]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
6711
+ """
6712
+ self.load_markets()
6713
+ market = self.market(symbol)
6714
+ clientOrderId = self.safe_string(params, 'clientOrderId')
6715
+ code = self.safe_string(params, 'code')
6716
+ marginMode = None
6717
+ marginMode, params = self.handle_margin_mode_and_params('closePosition', params, 'cross')
6718
+ request = {
6719
+ 'instId': market['id'],
6720
+ 'mgnMode': marginMode,
6721
+ }
6722
+ if side is not None:
6723
+ if (side == 'buy'):
6724
+ request['posSide'] = 'long'
6725
+ elif side == 'sell':
6726
+ request['posSide'] = 'short'
6727
+ else:
6728
+ request['posSide'] = side
6729
+ if clientOrderId is not None:
6730
+ request['clOrdId'] = clientOrderId
6731
+ if code is not None:
6732
+ currency = self.currency(code)
6733
+ request['ccy'] = currency['id']
6734
+ response = self.privatePostTradeClosePosition(self.extend(request, params))
6735
+ #
6736
+ # {
6737
+ # "code": "1",
6738
+ # "data": [
6739
+ # {
6740
+ # "clOrdId":"e847386590ce4dBCe903bbc394dc88bf",
6741
+ # "ordId":"",
6742
+ # "sCode":"51000",
6743
+ # "sMsg":"Parameter posSide error ",
6744
+ # "tag":"e847386590ce4dBC"
6745
+ # }
6746
+ # ],
6747
+ # "inTime": "1701877077101064",
6748
+ # "msg": "All operations failed",
6749
+ # "outTime": "1701877077102579"
6750
+ # }
6751
+ #
6752
+ data = self.safe_value(response, 'data')
6753
+ order = self.safe_value(data, 0)
6754
+ return self.parse_order(order, market)
6755
+
6664
6756
  def handle_errors(self, httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody):
6665
6757
  if not response:
6666
6758
  return None # fallback to default error handler
ccxt/pro/__init__.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # ----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.1.81'
7
+ __version__ = '4.1.83'
8
8
 
9
9
  # ----------------------------------------------------------------------------
10
10
 
ccxt/pro/binance.py CHANGED
@@ -456,7 +456,7 @@ class binance(ccxt.async_support.binance):
456
456
  :param int [since]: timestamp in ms of the earliest trade to fetch
457
457
  :param int [limit]: the maximum amount of trades to fetch
458
458
  :param dict [params]: extra parameters specific to the exchange API endpoint
459
- :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
459
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
460
460
  """
461
461
  await self.load_markets()
462
462
  symbols = self.market_symbols(symbols, None, False, True, True)
ccxt/pro/bingx.py CHANGED
@@ -488,7 +488,7 @@ class bingx(ccxt.async_support.bingx):
488
488
  :see: https://bingx-api.github.io/docs/#/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
489
489
  query for balance and get the amount of funds available for trading or funds locked in orders
490
490
  :param dict [params]: extra parameters specific to the exchange API endpoint
491
- :returns dict: a `balance structure <https://docs.ccxt.com/en/latest/manual.html?#balance-structure>`
491
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
492
492
  """
493
493
  await self.load_markets()
494
494
  await self.authenticate()
ccxt/pro/bitget.py CHANGED
@@ -617,7 +617,7 @@ class bitget(ccxt.async_support.bitget):
617
617
  :param int [since]: timestamp in ms of the earliest trade to fetch
618
618
  :param int [limit]: the maximum amount of trades to fetch
619
619
  :param dict [params]: extra parameters specific to the exchange API endpoint
620
- :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
620
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
621
621
  """
622
622
  symbolsLength = len(symbols)
623
623
  if symbolsLength == 0:
ccxt/pro/bybit.py CHANGED
@@ -657,7 +657,7 @@ class bybit(ccxt.async_support.bybit):
657
657
  :param int [since]: timestamp in ms of the earliest trade to fetch
658
658
  :param int [limit]: the maximum amount of trades to fetch
659
659
  :param dict [params]: extra parameters specific to the exchange API endpoint
660
- :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
660
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
661
661
  """
662
662
  await self.load_markets()
663
663
  symbols = self.market_symbols(symbols)
ccxt/pro/cex.py CHANGED
@@ -392,7 +392,7 @@ class cex(ccxt.async_support.cex):
392
392
  :see: https://docs.cex.io/#ws-api-get-balance
393
393
  query for balance and get the amount of funds available for trading or funds locked in orders
394
394
  :param dict [params]: extra parameters specific to the cex api endpoint
395
- :returns dict: a `balance structure <https://docs.ccxt.com/en/latest/manual.html?#balance-structure>`
395
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
396
396
  """
397
397
  await self.load_markets()
398
398
  await self.authenticate()
ccxt/pro/coinbasepro.py CHANGED
@@ -165,7 +165,7 @@ class coinbasepro(ccxt.async_support.coinbasepro):
165
165
  :param int [since]: timestamp in ms of the earliest trade to fetch
166
166
  :param int [limit]: the maximum amount of trades to fetch
167
167
  :param dict [params]: extra parameters specific to the exchange API endpoint
168
- :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
168
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
169
169
  """
170
170
  symbolsLength = len(symbols)
171
171
  if symbolsLength == 0:
ccxt/pro/cryptocom.py CHANGED
@@ -171,7 +171,7 @@ class cryptocom(ccxt.async_support.cryptocom):
171
171
  :param int [since]: timestamp in ms of the earliest trade to fetch
172
172
  :param int [limit]: the maximum amount of trades to fetch
173
173
  :param dict [params]: extra parameters specific to the exchange API endpoint
174
- :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
174
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
175
175
  """
176
176
  await self.load_markets()
177
177
  symbols = self.market_symbols(symbols)
ccxt/pro/gate.py CHANGED
@@ -388,7 +388,7 @@ class gate(ccxt.async_support.gate):
388
388
  :param int [since]: timestamp in ms of the earliest trade to fetch
389
389
  :param int [limit]: the maximum amount of trades to fetch
390
390
  :param dict [params]: extra parameters specific to the exchange API endpoint
391
- :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
391
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
392
392
  """
393
393
  await self.load_markets()
394
394
  symbols = self.market_symbols(symbols)
ccxt/pro/kucoin.py CHANGED
@@ -337,7 +337,7 @@ class kucoin(ccxt.async_support.kucoin):
337
337
  :param int [since]: timestamp in ms of the earliest trade to fetch
338
338
  :param int [limit]: the maximum amount of trades to fetch
339
339
  :param dict [params]: extra parameters specific to the exchange API endpoint
340
- :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
340
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
341
341
  """
342
342
  symbolsLength = len(symbols)
343
343
  if symbolsLength == 0:
ccxt/pro/kucoinfutures.py CHANGED
@@ -377,7 +377,7 @@ class kucoinfutures(ccxt.async_support.kucoinfutures):
377
377
  :param int [since]: timestamp in ms of the earliest trade to fetch
378
378
  :param int [limit]: the maximum amount of trades to fetch
379
379
  :param dict [params]: extra parameters specific to the exchange API endpoint
380
- :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
380
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
381
381
  """
382
382
  symbolsLength = len(symbols)
383
383
  if symbolsLength == 0:
ccxt/pro/okx.py CHANGED
@@ -181,7 +181,7 @@ class okx(ccxt.async_support.okx):
181
181
  :param int [since]: timestamp in ms of the earliest trade to fetch
182
182
  :param int [limit]: the maximum amount of trades to fetch
183
183
  :param dict [params]: extra parameters specific to the exchange API endpoint
184
- :returns dict[]: a list of `trade structures <https://docs.ccxt.com/en/latest/manual.html?#public-trades>`
184
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
185
185
  """
186
186
  symbolsLength = len(symbols)
187
187
  if symbolsLength == 0: