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/async_support/htx.py CHANGED
@@ -3193,14 +3193,16 @@ class htx(Exchange, ImplicitAPI):
3193
3193
  # "margin_mode": "cross",
3194
3194
  # "margin_account": "USDT",
3195
3195
  # "margin_asset": "USDT",
3196
- # "margin_balance": 200.000000000000000000,
3197
- # "margin_static": 200.000000000000000000,
3198
- # "margin_position": 0,
3199
- # "margin_frozen": 0,
3200
- # "profit_real": 0E-18,
3201
- # "profit_unreal": 0,
3202
- # "withdraw_available": 2E+2,
3203
- # "risk_rate": null,
3196
+ # "margin_balance": 49.874186030200000000,
3197
+ # "money_in": 50,
3198
+ # "money_out": 0,
3199
+ # "margin_static": 49.872786030200000000,
3200
+ # "margin_position": 6.180000000000000000,
3201
+ # "margin_frozen": 6.000000000000000000,
3202
+ # "profit_unreal": 0.001400000000000000,
3203
+ # "withdraw_available": 37.6927860302,
3204
+ # "risk_rate": 271.984050521072796934,
3205
+ # "new_risk_rate": 0.001858676950514399,
3204
3206
  # "contract_detail": [
3205
3207
  # {
3206
3208
  # "symbol": "MANA",
@@ -3293,8 +3295,8 @@ class htx(Exchange, ImplicitAPI):
3293
3295
  result[symbol] = self.safe_balance(accountsByCode)
3294
3296
  else:
3295
3297
  account = self.account()
3296
- account['free'] = self.safe_string(first, 'margin_balance', 'margin_available')
3297
- account['used'] = self.safe_string(first, 'margin_frozen')
3298
+ account['free'] = self.safe_string(first, 'withdraw_available')
3299
+ account['total'] = self.safe_string(first, 'margin_balance')
3298
3300
  currencyId = self.safe_string_2(first, 'margin_asset', 'symbol')
3299
3301
  code = self.safe_currency_code(currencyId)
3300
3302
  result[code] = account
@@ -18,6 +18,7 @@ from ccxt.base.errors import InsufficientFunds
18
18
  from ccxt.base.errors import InvalidAddress
19
19
  from ccxt.base.errors import InvalidOrder
20
20
  from ccxt.base.errors import DuplicateOrderId
21
+ from ccxt.base.errors import NotSupported
21
22
  from ccxt.base.errors import RateLimitExceeded
22
23
  from ccxt.base.errors import InvalidNonce
23
24
  from ccxt.base.errors import AuthenticationError
@@ -46,6 +47,9 @@ class lbank(Exchange, ImplicitAPI):
46
47
  'addMargin': False,
47
48
  'cancelAllOrders': True,
48
49
  'cancelOrder': True,
50
+ 'createMarketBuyOrderWithCost': True,
51
+ 'createMarketOrderWithCost': False,
52
+ 'createMarketSellOrderWithCost': False,
49
53
  'createOrder': True,
50
54
  'createReduceOnlyOrder': False,
51
55
  'createStopLimitOrder': False,
@@ -116,10 +120,10 @@ class lbank(Exchange, ImplicitAPI):
116
120
  'contract': 'https://lbkperp.lbank.com',
117
121
  },
118
122
  'api2': 'https://api.lbkex.com',
119
- 'www': 'https://www.lbank.info',
120
- 'doc': 'https://www.lbank.info/en-US/docs/index.html',
121
- 'fees': 'https://lbankinfo.zendesk.com/hc/en-gb/articles/360012072873-Trading-Fees',
122
- 'referral': 'https://www.lbank.info/invitevip?icode=7QCY',
123
+ 'www': 'https://www.lbank.com',
124
+ 'doc': 'https://www.lbank.com/en-US/docs/index.html',
125
+ 'fees': 'https://support.lbank.site/hc/en-gb/articles/900000535703-Trading-Fees-From-14-00-on-April-7-2020-UTC-8-',
126
+ 'referral': 'https://www.lbank.com/login/?icode=7QCY',
123
127
  },
124
128
  'api': {
125
129
  'spot': {
@@ -305,7 +309,7 @@ class lbank(Exchange, ImplicitAPI):
305
309
  async def fetch_time(self, params={}):
306
310
  """
307
311
  fetches the current integer timestamp in milliseconds from the exchange server
308
- :see: https://www.lbank.info/en-US/docs/index.html#get-timestamp
312
+ :see: https://www.lbank.com/en-US/docs/index.html#get-timestamp
309
313
  :see: https://www.lbank.com/en-US/docs/contract.html#get-the-current-time
310
314
  :param dict [params]: extra parameters specific to the exchange API endpoint
311
315
  :returns int: the current integer timestamp in milliseconds from the exchange server
@@ -592,7 +596,7 @@ class lbank(Exchange, ImplicitAPI):
592
596
  async def fetch_ticker(self, symbol: str, params={}) -> Ticker:
593
597
  """
594
598
  fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
595
- :see: https://www.lbank.info/en-US/docs/index.html#query-current-market-data-new
599
+ :see: https://www.lbank.com/en-US/docs/index.html#query-current-market-data-new
596
600
  :param str symbol: unified symbol of the market to fetch the ticker for
597
601
  :param dict [params]: extra parameters specific to the exchange API endpoint
598
602
  :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
@@ -634,7 +638,7 @@ class lbank(Exchange, ImplicitAPI):
634
638
  async def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
635
639
  """
636
640
  fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
637
- :see: https://www.lbank.info/en-US/docs/index.html#query-current-market-data-new
641
+ :see: https://www.lbank.com/en-US/docs/index.html#query-current-market-data-new
638
642
  :see: https://www.lbank.com/en-US/docs/contract.html#query-contract-market-list
639
643
  :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
640
644
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -708,7 +712,7 @@ class lbank(Exchange, ImplicitAPI):
708
712
  async def fetch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
709
713
  """
710
714
  fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
711
- :see: https://www.lbank.info/en-US/docs/index.html#query-market-depth
715
+ :see: https://www.lbank.com/en-US/docs/index.html#query-market-depth
712
716
  :see: https://www.lbank.com/en-US/docs/contract.html#get-handicap
713
717
  :param str symbol: unified symbol of the market to fetch the order book for
714
718
  :param int [limit]: the maximum amount of order book entries to return
@@ -881,8 +885,8 @@ class lbank(Exchange, ImplicitAPI):
881
885
  async def fetch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
882
886
  """
883
887
  get the list of most recent trades for a particular symbol
884
- :see: https://www.lbank.info/en-US/docs/index.html#query-historical-transactions
885
- :see: https://www.lbank.info/en-US/docs/index.html#recent-transactions-list
888
+ :see: https://www.lbank.com/en-US/docs/index.html#query-historical-transactions
889
+ :see: https://www.lbank.com/en-US/docs/index.html#recent-transactions-list
886
890
  :param str symbol: unified symbol of the market to fetch trades for
887
891
  :param int [since]: timestamp in ms of the earliest trade to fetch
888
892
  :param int [limit]: the maximum amount of trades to fetch
@@ -948,7 +952,7 @@ class lbank(Exchange, ImplicitAPI):
948
952
  async def fetch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
949
953
  """
950
954
  fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
951
- :see: https://www.lbank.info/en-US/docs/index.html#query-k-bar-data
955
+ :see: https://www.lbank.com/en-US/docs/index.html#query-k-bar-data
952
956
  :param str symbol: unified symbol of the market to fetch OHLCV data for
953
957
  :param str timeframe: the length of time each candle represents
954
958
  :param int [since]: timestamp in ms of the earliest candle to fetch
@@ -1123,9 +1127,9 @@ class lbank(Exchange, ImplicitAPI):
1123
1127
  async def fetch_balance(self, params={}) -> Balances:
1124
1128
  """
1125
1129
  query for balance and get the amount of funds available for trading or funds locked in orders
1126
- :see: https://www.lbank.info/en-US/docs/index.html#asset-information
1127
- :see: https://www.lbank.info/en-US/docs/index.html#account-information
1128
- :see: https://www.lbank.info/en-US/docs/index.html#get-all-coins-information
1130
+ :see: https://www.lbank.com/en-US/docs/index.html#asset-information
1131
+ :see: https://www.lbank.com/en-US/docs/index.html#account-information
1132
+ :see: https://www.lbank.com/en-US/docs/index.html#get-all-coins-information
1129
1133
  :param dict [params]: extra parameters specific to the exchange API endpoint
1130
1134
  :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
1131
1135
  """
@@ -1187,7 +1191,7 @@ class lbank(Exchange, ImplicitAPI):
1187
1191
  async def fetch_trading_fee(self, symbol: str, params={}):
1188
1192
  """
1189
1193
  fetch the trading fees for a market
1190
- :see: https://www.lbank.info/en-US/docs/index.html#transaction-fee-rate-query
1194
+ :see: https://www.lbank.com/en-US/docs/index.html#transaction-fee-rate-query
1191
1195
  :param str symbol: unified market symbol
1192
1196
  :param dict [params]: extra parameters specific to the exchange API endpoint
1193
1197
  :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
@@ -1199,7 +1203,7 @@ class lbank(Exchange, ImplicitAPI):
1199
1203
  async def fetch_trading_fees(self, params={}):
1200
1204
  """
1201
1205
  fetch the trading fees for multiple markets
1202
- :see: https://www.lbank.info/en-US/docs/index.html#transaction-fee-rate-query
1206
+ :see: https://www.lbank.com/en-US/docs/index.html#transaction-fee-rate-query
1203
1207
  :param dict [params]: extra parameters specific to the exchange API endpoint
1204
1208
  :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
1205
1209
  """
@@ -1214,11 +1218,28 @@ class lbank(Exchange, ImplicitAPI):
1214
1218
  result[symbol] = fee
1215
1219
  return result
1216
1220
 
1221
+ async def create_market_buy_order_with_cost(self, symbol: str, cost, params={}):
1222
+ """
1223
+ create a market buy order by providing the symbol and cost
1224
+ :see: https://www.lbank.com/en-US/docs/index.html#place-order
1225
+ :see: https://www.lbank.com/en-US/docs/index.html#place-an-order
1226
+ :param str symbol: unified symbol of the market to create an order in
1227
+ :param float cost: how much you want to trade in units of the quote currency
1228
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1229
+ :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
1230
+ """
1231
+ await self.load_markets()
1232
+ market = self.market(symbol)
1233
+ if not market['spot']:
1234
+ raise NotSupported(self.id + ' createMarketBuyOrderWithCost() supports spot orders only')
1235
+ params['createMarketBuyOrderRequiresPrice'] = False
1236
+ return await self.create_order(symbol, 'market', 'buy', cost, None, params)
1237
+
1217
1238
  async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount, price=None, params={}):
1218
1239
  """
1219
1240
  create a trade order
1220
- :see: https://www.lbank.info/en-US/docs/index.html#place-order
1221
- :see: https://www.lbank.info/en-US/docs/index.html#place-an-order
1241
+ :see: https://www.lbank.com/en-US/docs/index.html#place-order
1242
+ :see: https://www.lbank.com/en-US/docs/index.html#place-an-order
1222
1243
  :param str symbol: unified symbol of the market to create an order in
1223
1244
  :param str type: 'market' or 'limit'
1224
1245
  :param str side: 'buy' or 'sell'
@@ -1257,17 +1278,25 @@ class lbank(Exchange, ImplicitAPI):
1257
1278
  request['amount'] = self.amount_to_precision(symbol, amount)
1258
1279
  elif side == 'buy':
1259
1280
  request['type'] = side + '_' + 'market'
1260
- if self.options['createMarketBuyOrderRequiresPrice']:
1281
+ quoteAmount = None
1282
+ createMarketBuyOrderRequiresPrice = True
1283
+ createMarketBuyOrderRequiresPrice, params = self.handle_option_and_params(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', True)
1284
+ cost = self.safe_number(params, 'cost')
1285
+ params = self.omit(params, 'cost')
1286
+ if cost is not None:
1287
+ quoteAmount = self.cost_to_precision(symbol, cost)
1288
+ elif createMarketBuyOrderRequiresPrice:
1261
1289
  if price is None:
1262
- 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)")
1290
+ 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')
1263
1291
  else:
1264
1292
  amountString = self.number_to_string(amount)
1265
1293
  priceString = self.number_to_string(price)
1266
- quoteAmount = Precise.string_mul(amountString, priceString)
1267
- cost = self.parse_number(quoteAmount)
1268
- request['price'] = self.price_to_precision(symbol, cost)
1294
+ costRequest = Precise.string_mul(amountString, priceString)
1295
+ quoteAmount = self.cost_to_precision(symbol, costRequest)
1269
1296
  else:
1270
- request['price'] = amount
1297
+ quoteAmount = self.cost_to_precision(symbol, amount)
1298
+ # market buys require filling the price param instead of the amount param, for market buys the price is treated cost by lbank
1299
+ request['price'] = quoteAmount
1271
1300
  if clientOrderId is not None:
1272
1301
  request['custom_id'] = clientOrderId
1273
1302
  method = None
@@ -1428,8 +1457,8 @@ class lbank(Exchange, ImplicitAPI):
1428
1457
  async def fetch_order(self, id: str, symbol: Str = None, params={}):
1429
1458
  """
1430
1459
  fetches information on an order made by the user
1431
- :see: https://www.lbank.info/en-US/docs/index.html#query-order
1432
- :see: https://www.lbank.info/en-US/docs/index.html#query-order-new
1460
+ :see: https://www.lbank.com/en-US/docs/index.html#query-order
1461
+ :see: https://www.lbank.com/en-US/docs/index.html#query-order-new
1433
1462
  :param str symbol: unified symbol of the market the order was made in
1434
1463
  :param dict [params]: extra parameters specific to the exchange API endpoint
1435
1464
  :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
@@ -1524,7 +1553,7 @@ class lbank(Exchange, ImplicitAPI):
1524
1553
  async def fetch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
1525
1554
  """
1526
1555
  fetch all trades made by the user
1527
- :see: https://www.lbank.info/en-US/docs/index.html#past-transaction-details
1556
+ :see: https://www.lbank.com/en-US/docs/index.html#past-transaction-details
1528
1557
  :param str symbol: unified market symbol
1529
1558
  :param int [since]: the earliest time in ms to fetch trades for
1530
1559
  :param int [limit]: the maximum number of trade structures to retrieve
@@ -1578,7 +1607,7 @@ class lbank(Exchange, ImplicitAPI):
1578
1607
  async def fetch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1579
1608
  """
1580
1609
  fetches information on multiple orders made by the user
1581
- :see: https://www.lbank.info/en-US/docs/index.html#query-all-orders
1610
+ :see: https://www.lbank.com/en-US/docs/index.html#query-all-orders
1582
1611
  :param str symbol: unified market symbol of the market orders were made in
1583
1612
  :param int [since]: the earliest time in ms to fetch orders for
1584
1613
  :param int [limit]: the maximum number of order structures to retrieve
@@ -1634,7 +1663,7 @@ class lbank(Exchange, ImplicitAPI):
1634
1663
  async def fetch_open_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
1635
1664
  """
1636
1665
  fetch all unfilled currently open orders
1637
- :see: https://www.lbank.info/en-US/docs/index.html#current-pending-order
1666
+ :see: https://www.lbank.com/en-US/docs/index.html#current-pending-order
1638
1667
  :param str symbol: unified market symbol
1639
1668
  :param int [since]: the earliest time in ms to fetch open orders for
1640
1669
  :param int [limit]: the maximum number of open order structures to retrieve
@@ -1687,7 +1716,7 @@ class lbank(Exchange, ImplicitAPI):
1687
1716
  async def cancel_order(self, id: str, symbol: Str = None, params={}):
1688
1717
  """
1689
1718
  cancels an open order
1690
- :see: https://www.lbank.info/en-US/docs/index.html#cancel-order-new
1719
+ :see: https://www.lbank.com/en-US/docs/index.html#cancel-order-new
1691
1720
  :param str id: order id
1692
1721
  :param str symbol: unified symbol of the market the order was made in
1693
1722
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -1725,7 +1754,7 @@ class lbank(Exchange, ImplicitAPI):
1725
1754
  async def cancel_all_orders(self, symbol: Str = None, params={}):
1726
1755
  """
1727
1756
  cancel all open orders in a market
1728
- :see: https://www.lbank.info/en-US/docs/index.html#cancel-all-pending-orders-for-a-single-trading-pair
1757
+ :see: https://www.lbank.com/en-US/docs/index.html#cancel-all-pending-orders-for-a-single-trading-pair
1729
1758
  :param str symbol: unified market symbol of the market to cancel orders in
1730
1759
  :param dict [params]: extra parameters specific to the exchange API endpoint
1731
1760
  :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
@@ -1769,8 +1798,8 @@ class lbank(Exchange, ImplicitAPI):
1769
1798
  async def fetch_deposit_address(self, code: str, params={}):
1770
1799
  """
1771
1800
  fetch the deposit address for a currency associated with self account
1772
- :see: https://www.lbank.info/en-US/docs/index.html#get-deposit-address
1773
- :see: https://www.lbank.info/en-US/docs/index.html#the-user-obtains-the-deposit-address
1801
+ :see: https://www.lbank.com/en-US/docs/index.html#get-deposit-address
1802
+ :see: https://www.lbank.com/en-US/docs/index.html#the-user-obtains-the-deposit-address
1774
1803
  :param str code: unified currency code
1775
1804
  :param dict [params]: extra parameters specific to the exchange API endpoint
1776
1805
  :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
@@ -1863,7 +1892,7 @@ class lbank(Exchange, ImplicitAPI):
1863
1892
  async def withdraw(self, code: str, amount, address, tag=None, params={}):
1864
1893
  """
1865
1894
  make a withdrawal
1866
- :see: https://www.lbank.info/en-US/docs/index.html#withdrawal
1895
+ :see: https://www.lbank.com/en-US/docs/index.html#withdrawal
1867
1896
  :param str code: unified currency code
1868
1897
  :param float amount: the amount to withdraw
1869
1898
  :param str address: the address to withdraw to
@@ -2020,7 +2049,7 @@ class lbank(Exchange, ImplicitAPI):
2020
2049
  async def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
2021
2050
  """
2022
2051
  fetch all deposits made to an account
2023
- :see: https://www.lbank.info/en-US/docs/index.html#get-recharge-history
2052
+ :see: https://www.lbank.com/en-US/docs/index.html#get-recharge-history
2024
2053
  :param str code: unified currency code
2025
2054
  :param int [since]: the earliest time in ms to fetch deposits for
2026
2055
  :param int [limit]: the maximum number of deposits structures to retrieve
@@ -2069,7 +2098,7 @@ class lbank(Exchange, ImplicitAPI):
2069
2098
  async def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
2070
2099
  """
2071
2100
  fetch all withdrawals made from an account
2072
- :see: https://www.lbank.info/en-US/docs/index.html#get-withdrawal-history
2101
+ :see: https://www.lbank.com/en-US/docs/index.html#get-withdrawal-history
2073
2102
  :param str code: unified currency code
2074
2103
  :param int [since]: the earliest time in ms to fetch withdrawals for
2075
2104
  :param int [limit]: the maximum number of withdrawals structures to retrieve
@@ -2255,8 +2284,8 @@ class lbank(Exchange, ImplicitAPI):
2255
2284
  async def fetch_deposit_withdraw_fees(self, codes: Strings = None, params={}):
2256
2285
  """
2257
2286
  when using private endpoint, only returns information for currencies with non-zero balance, use public method by specifying self.options['fetchDepositWithdrawFees']['method'] = 'fetchPublicDepositWithdrawFees'
2258
- :see: https://www.lbank.info/en-US/docs/index.html#get-all-coins-information
2259
- :see: https://www.lbank.info/en-US/docs/index.html#withdrawal-configurations
2287
+ :see: https://www.lbank.com/en-US/docs/index.html#get-all-coins-information
2288
+ :see: https://www.lbank.com/en-US/docs/index.html#withdrawal-configurations
2260
2289
  :param str[]|None codes: array of unified currency codes
2261
2290
  :param dict [params]: extra parameters specific to the exchange API endpoint
2262
2291
  :returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
ccxt/async_support/okx.py CHANGED
@@ -57,6 +57,8 @@ class okx(Exchange, ImplicitAPI):
57
57
  'cancelAllOrders': False,
58
58
  'cancelOrder': True,
59
59
  'cancelOrders': True,
60
+ 'closeAllPositions': False,
61
+ 'closePosition': True,
60
62
  'createDepositAddress': False,
61
63
  'createMarketBuyOrderWithCost': True,
62
64
  'createMarketSellOrderWithCost': True,
@@ -2954,7 +2956,11 @@ class okx(Exchange, ImplicitAPI):
2954
2956
  'instId': market['id'],
2955
2957
  'clOrdId': clientOrderIds[i],
2956
2958
  })
2957
- response = await getattr(self, method)(request) # * dont self.extend with params, otherwise ARRAY will be turned into OBJECT
2959
+ response = None
2960
+ if method == 'privatePostTradeCancelAlgos':
2961
+ response = await self.privatePostTradeCancelAlgos(request) # * dont self.extend with params, otherwise ARRAY will be turned into OBJECT
2962
+ else:
2963
+ response = await self.privatePostTradeCancelBatchOrders(request) # * dont self.extend with params, otherwise ARRAY will be turned into OBJECT
2958
2964
  #
2959
2965
  # {
2960
2966
  # "code": "0",
@@ -3235,7 +3241,11 @@ class okx(Exchange, ImplicitAPI):
3235
3241
  else:
3236
3242
  request['ordId'] = id
3237
3243
  query = self.omit(params, ['method', 'clOrdId', 'clientOrderId', 'stop'])
3238
- response = await getattr(self, method)(self.extend(request, query))
3244
+ response = None
3245
+ if method == 'privateGetTradeOrderAlgo':
3246
+ response = await self.privateGetTradeOrderAlgo(self.extend(request, query))
3247
+ else:
3248
+ response = await self.privateGetTradeOrder(self.extend(request, query))
3239
3249
  #
3240
3250
  # Spot and Swap
3241
3251
  #
@@ -3386,7 +3396,11 @@ class okx(Exchange, ImplicitAPI):
3386
3396
  if ordType is None:
3387
3397
  raise ArgumentsRequired(self.id + ' fetchOpenOrders() requires an "ordType" string parameter, "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"')
3388
3398
  query = self.omit(params, ['method', 'stop'])
3389
- response = await getattr(self, method)(self.extend(request, query))
3399
+ response = None
3400
+ if method == 'privateGetTradeOrdersAlgoPending':
3401
+ response = await self.privateGetTradeOrdersAlgoPending(self.extend(request, query))
3402
+ else:
3403
+ response = await self.privateGetTradeOrdersPending(self.extend(request, query))
3390
3404
  #
3391
3405
  # {
3392
3406
  # "code": "0",
@@ -3547,7 +3561,11 @@ class okx(Exchange, ImplicitAPI):
3547
3561
  request['end'] = until
3548
3562
  query = self.omit(query, ['until', 'till'])
3549
3563
  send = self.omit(query, ['method', 'stop', 'ordType'])
3550
- response = await getattr(self, method)(self.extend(request, send))
3564
+ response = None
3565
+ if method == 'privateGetTradeOrdersAlgoHistory':
3566
+ response = await self.privateGetTradeOrdersAlgoHistory(self.extend(request, send))
3567
+ else:
3568
+ response = await self.privateGetTradeOrdersHistory(self.extend(request, send))
3551
3569
  #
3552
3570
  # {
3553
3571
  # "code": "0",
@@ -3713,7 +3731,11 @@ class okx(Exchange, ImplicitAPI):
3713
3731
  query = self.omit(query, ['until', 'till'])
3714
3732
  request['state'] = 'filled'
3715
3733
  send = self.omit(query, ['method', 'stop'])
3716
- response = await getattr(self, method)(self.extend(request, send))
3734
+ response = None
3735
+ if method == 'privateGetTradeOrdersAlgoHistory':
3736
+ response = await self.privateGetTradeOrdersAlgoHistory(self.extend(request, send))
3737
+ else:
3738
+ response = await self.privateGetTradeOrdersHistory(self.extend(request, send))
3717
3739
  #
3718
3740
  # {
3719
3741
  # "code": "0",
@@ -3950,7 +3972,13 @@ class okx(Exchange, ImplicitAPI):
3950
3972
  currency = self.currency(code)
3951
3973
  request['ccy'] = currency['id']
3952
3974
  request, params = self.handle_until_option('end', request, params)
3953
- response = await getattr(self, method)(self.extend(request, query))
3975
+ response = None
3976
+ if method == 'privateGetAccountBillsArchive':
3977
+ response = await self.privateGetAccountBillsArchive(self.extend(request, query))
3978
+ elif method == 'privateGetAssetBills':
3979
+ response = await self.privateGetAssetBills(self.extend(request, query))
3980
+ else:
3981
+ response = await self.privateGetAccountBills(self.extend(request, query))
3954
3982
  #
3955
3983
  # privateGetAccountBills, privateGetAccountBillsArchive
3956
3984
  #
@@ -4803,7 +4831,11 @@ class okx(Exchange, ImplicitAPI):
4803
4831
  request['instId'] = ','.join(marketIds)
4804
4832
  fetchPositionsOptions = self.safe_value(self.options, 'fetchPositions', {})
4805
4833
  method = self.safe_string(fetchPositionsOptions, 'method', 'privateGetAccountPositions')
4806
- response = await getattr(self, method)(self.extend(request, params))
4834
+ response = None
4835
+ if method == 'privateGetAccountPositionsHistory':
4836
+ response = await self.privateGetAccountPositionsHistory(self.extend(request, params))
4837
+ else:
4838
+ response = await self.privateGetAccountPositions(self.extend(request, params))
4807
4839
  #
4808
4840
  # {
4809
4841
  # "code": "0",
@@ -6662,6 +6694,66 @@ class okx(Exchange, ImplicitAPI):
6662
6694
  'info': greeks,
6663
6695
  }
6664
6696
 
6697
+ async def close_position(self, symbol: str, side: OrderSide = None, params={}) -> Order:
6698
+ """
6699
+ closes open positions for a market
6700
+ :see: https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-close-positions
6701
+ :param str symbol: Unified CCXT market symbol
6702
+ :param str [side]: 'buy' or 'sell', leave in net mode
6703
+ :param dict [params]: extra parameters specific to the okx api endpoint
6704
+ :param str [params.clientOrderId]: a unique identifier for the order
6705
+ :param str [params.marginMode]: 'cross' or 'isolated', default is 'cross
6706
+ :param str [params.code]: *required in the case of closing cross MARGIN position for Single-currency margin* margin currency
6707
+ *
6708
+ * EXCHANGE SPECIFIC PARAMETERS
6709
+ :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
6710
+ :param str [params.tag]: order tag a combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters
6711
+ :returns [dict]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
6712
+ """
6713
+ await self.load_markets()
6714
+ market = self.market(symbol)
6715
+ clientOrderId = self.safe_string(params, 'clientOrderId')
6716
+ code = self.safe_string(params, 'code')
6717
+ marginMode = None
6718
+ marginMode, params = self.handle_margin_mode_and_params('closePosition', params, 'cross')
6719
+ request = {
6720
+ 'instId': market['id'],
6721
+ 'mgnMode': marginMode,
6722
+ }
6723
+ if side is not None:
6724
+ if (side == 'buy'):
6725
+ request['posSide'] = 'long'
6726
+ elif side == 'sell':
6727
+ request['posSide'] = 'short'
6728
+ else:
6729
+ request['posSide'] = side
6730
+ if clientOrderId is not None:
6731
+ request['clOrdId'] = clientOrderId
6732
+ if code is not None:
6733
+ currency = self.currency(code)
6734
+ request['ccy'] = currency['id']
6735
+ response = await self.privatePostTradeClosePosition(self.extend(request, params))
6736
+ #
6737
+ # {
6738
+ # "code": "1",
6739
+ # "data": [
6740
+ # {
6741
+ # "clOrdId":"e847386590ce4dBCe903bbc394dc88bf",
6742
+ # "ordId":"",
6743
+ # "sCode":"51000",
6744
+ # "sMsg":"Parameter posSide error ",
6745
+ # "tag":"e847386590ce4dBC"
6746
+ # }
6747
+ # ],
6748
+ # "inTime": "1701877077101064",
6749
+ # "msg": "All operations failed",
6750
+ # "outTime": "1701877077102579"
6751
+ # }
6752
+ #
6753
+ data = self.safe_value(response, 'data')
6754
+ order = self.safe_value(data, 0)
6755
+ return self.parse_order(order, market)
6756
+
6665
6757
  def handle_errors(self, httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody):
6666
6758
  if not response:
6667
6759
  return None # fallback to default error handler
ccxt/base/exchange.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
 
@@ -3847,7 +3847,7 @@ class Exchange(object):
3847
3847
  def fetch_funding_history(self, symbol: str = None, since: Int = None, limit: Int = None, params={}):
3848
3848
  raise NotSupported(self.id + ' fetchFundingHistory() is not supported yet')
3849
3849
 
3850
- def close_position(self, symbol: str, side: OrderSide = None, marginMode: str = None, params={}):
3850
+ def close_position(self, symbol: str, side: OrderSide = None, params={}):
3851
3851
  raise NotSupported(self.id + ' closePositions() is not supported yet')
3852
3852
 
3853
3853
  def close_all_positions(self, params={}):
ccxt/bingx.py CHANGED
@@ -3171,7 +3171,7 @@ class bingx(Exchange, ImplicitAPI):
3171
3171
  :see: https://bitgetlimited.github.io/apidoc/en/mix/#close-all-position
3172
3172
  :param dict [params]: extra parameters specific to the okx api endpoint
3173
3173
  :param str [params.recvWindow]: request valid time window value
3174
- :returns [dict]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
3174
+ :returns dict[]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
3175
3175
  """
3176
3176
  self.load_markets()
3177
3177
  defaultRecvWindow = self.safe_integer(self.options, 'recvWindow')
ccxt/bitget.py CHANGED
@@ -6554,7 +6554,7 @@ class bitget(Exchange, ImplicitAPI):
6554
6554
  :param dict [params]: extra parameters specific to the okx api endpoint
6555
6555
  :param str [params.subType]: 'linear' or 'inverse'
6556
6556
  :param str [params.settle]: *required and only valid when params.subType == "linear"* 'USDT' or 'USDC'
6557
- :returns [dict]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
6557
+ :returns dict[]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
6558
6558
  """
6559
6559
  self.load_markets()
6560
6560
  subType = None
ccxt/bybit.py CHANGED
@@ -2896,7 +2896,7 @@ class bybit(Exchange, ImplicitAPI):
2896
2896
  :see: https://bybit-exchange.github.io/docs/v5/account/wallet-balance
2897
2897
  :param dict [params]: extra parameters specific to the exchange API endpoint
2898
2898
  :param str [params.type]: wallet type, ['spot', 'swap', 'fund']
2899
- :returns dict: a `balance structure <https://docs.ccxt.com/en/latest/manual.html?#balance-structure>`
2899
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
2900
2900
  """
2901
2901
  self.load_markets()
2902
2902
  request = {}
ccxt/cex.py CHANGED
@@ -45,6 +45,9 @@ class cex(Exchange, ImplicitAPI):
45
45
  'cancelOrder': True,
46
46
  'cancelOrders': False,
47
47
  'createDepositAddress': False,
48
+ 'createMarketBuyOrderWithCost': True,
49
+ 'createMarketOrderWithCost': False,
50
+ 'createMarketSellOrderWithCost': False,
48
51
  'createOrder': True,
49
52
  'createStopLimitOrder': False,
50
53
  'createStopMarketOrder': False,
@@ -728,27 +731,39 @@ class cex(Exchange, ImplicitAPI):
728
731
  :param float amount: how much of currency you want to trade in units of base currency
729
732
  :param float [price]: the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
730
733
  :param dict [params]: extra parameters specific to the exchange API endpoint
734
+ :param float [params.cost]: the quote quantity that can be used alternative for the amount for market buy orders
731
735
  :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
732
736
  """
733
- # for market buy it requires the amount of quote currency to spend
734
- if (type == 'market') and (side == 'buy'):
735
- if self.options['createMarketBuyOrderRequiresPrice']:
736
- if price is None:
737
- 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 a 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)")
738
- else:
739
- amountString = self.number_to_string(amount)
740
- priceString = self.number_to_string(price)
741
- baseAmount = Precise.string_mul(amountString, priceString)
742
- amount = self.parse_number(baseAmount)
743
737
  self.load_markets()
744
738
  market = self.market(symbol)
745
739
  request = {
746
740
  'pair': market['id'],
747
741
  'type': side,
748
- 'amount': amount,
749
742
  }
743
+ # for market buy it requires the amount of quote currency to spend
744
+ if (type == 'market') and (side == 'buy'):
745
+ quoteAmount = None
746
+ createMarketBuyOrderRequiresPrice = True
747
+ createMarketBuyOrderRequiresPrice, params = self.handle_option_and_params(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', True)
748
+ cost = self.safe_string(params, 'cost')
749
+ params = self.omit(params, 'cost')
750
+ if cost is not None:
751
+ quoteAmount = self.cost_to_precision(symbol, cost)
752
+ elif createMarketBuyOrderRequiresPrice:
753
+ if price is None:
754
+ 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')
755
+ else:
756
+ amountString = self.number_to_string(amount)
757
+ priceString = self.number_to_string(price)
758
+ costRequest = Precise.string_mul(amountString, priceString)
759
+ quoteAmount = self.cost_to_precision(symbol, costRequest)
760
+ else:
761
+ quoteAmount = self.cost_to_precision(symbol, amount)
762
+ request['amount'] = quoteAmount
763
+ else:
764
+ request['amount'] = self.amount_to_precision(symbol, amount)
750
765
  if type == 'limit':
751
- request['price'] = price
766
+ request['price'] = self.number_to_string(price)
752
767
  else:
753
768
  request['order_type'] = type
754
769
  response = self.privatePostPlaceOrderPair(self.extend(request, params))