ccxt 4.3.74__py2.py3-none-any.whl → 4.3.76__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.
@@ -200,6 +200,7 @@ class gemini(Exchange, ImplicitAPI):
200
200
  'v1/account/create': 1,
201
201
  'v1/account/list': 1,
202
202
  'v1/heartbeat': 1,
203
+ 'v1/roles': 1,
203
204
  },
204
205
  },
205
206
  },
ccxt/async_support/htx.py CHANGED
@@ -5751,6 +5751,7 @@ class htx(Exchange, ImplicitAPI):
5751
5751
 
5752
5752
  async def fetch_deposit_addresses_by_network(self, code: str, params={}):
5753
5753
  """
5754
+ :see: https://www.htx.com/en-us/opend/newApiPages/?id=7ec50029-7773-11ed-9966-0242ac110003
5754
5755
  fetch a dictionary of addresses for a currency, indexed by network
5755
5756
  :param str code: unified currency code of the currency for the deposit address
5756
5757
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -5781,6 +5782,7 @@ class htx(Exchange, ImplicitAPI):
5781
5782
 
5782
5783
  async def fetch_deposit_address(self, code: str, params={}):
5783
5784
  """
5785
+ :see: https://www.htx.com/en-us/opend/newApiPages/?id=7ec50029-7773-11ed-9966-0242ac110003
5784
5786
  fetch the deposit address for a currency associated with self account
5785
5787
  :param str code: unified currency code
5786
5788
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -5827,6 +5829,7 @@ class htx(Exchange, ImplicitAPI):
5827
5829
 
5828
5830
  async def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
5829
5831
  """
5832
+ :see: https://www.htx.com/en-us/opend/newApiPages/?id=7ec4f050-7773-11ed-9966-0242ac110003
5830
5833
  fetch all deposits made to an account
5831
5834
  :param str code: unified currency code
5832
5835
  :param int [since]: the earliest time in ms to fetch deposits for
@@ -6046,6 +6049,7 @@ class htx(Exchange, ImplicitAPI):
6046
6049
 
6047
6050
  async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
6048
6051
  """
6052
+ :see: https://www.htx.com/en-us/opend/newApiPages/?id=7ec4cc41-7773-11ed-9966-0242ac110003
6049
6053
  make a withdrawal
6050
6054
  :param str code: unified currency code
6051
6055
  :param float amount: the amount to withdraw
@@ -4908,7 +4908,7 @@ class mexc(Exchange, ImplicitAPI):
4908
4908
  networks = self.safe_dict(self.options, 'networks', {})
4909
4909
  network = self.safe_string_2(params, 'network', 'netWork') # self line allows the user to specify either ERC20 or ETH
4910
4910
  network = self.safe_string(networks, network, network) # handle ETH > ERC-20 alias
4911
- network = self.network_code_to_id(network)
4911
+ network = self.network_id_to_code(network)
4912
4912
  self.check_address(address)
4913
4913
  await self.load_markets()
4914
4914
  currency = self.currency(code)
@@ -794,8 +794,23 @@ class whitebit(Exchange, ImplicitAPI):
794
794
  # "change": "2.12" # in percent
795
795
  # }
796
796
  #
797
+ # WS market_update
798
+ #
799
+ # {
800
+ # "open": "52853.04",
801
+ # "close": "55913.88",
802
+ # "high": "56272",
803
+ # "low": "49549.67",
804
+ # "volume": "57331.067185",
805
+ # "deal": "3063860382.42985338",
806
+ # "last": "55913.88",
807
+ # "period": 86400
808
+ # }
797
809
  market = self.safe_market(None, market)
798
- last = self.safe_string(ticker, 'last_price')
810
+ # last price is provided as "last" or "last_price"
811
+ last = self.safe_string_2(ticker, 'last', 'last_price')
812
+ # if "close" is provided, use it, otherwise use <last>
813
+ close = self.safe_string(ticker, 'close', last)
799
814
  return self.safe_ticker({
800
815
  'symbol': market['symbol'],
801
816
  'timestamp': None,
@@ -808,7 +823,7 @@ class whitebit(Exchange, ImplicitAPI):
808
823
  'askVolume': None,
809
824
  'vwap': None,
810
825
  'open': self.safe_string(ticker, 'open'),
811
- 'close': last,
826
+ 'close': close,
812
827
  'last': last,
813
828
  'previousClose': None,
814
829
  'change': None,
ccxt/base/exchange.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.3.74'
7
+ __version__ = '4.3.76'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
@@ -360,6 +360,7 @@ class Exchange(object):
360
360
  self.trades = dict() if self.trades is None else self.trades
361
361
  self.transactions = dict() if self.transactions is None else self.transactions
362
362
  self.ohlcvs = dict() if self.ohlcvs is None else self.ohlcvs
363
+ self.liquidations = dict() if self.liquidations is None else self.liquidations
363
364
  self.currencies = dict() if self.currencies is None else self.currencies
364
365
  self.options = self.get_default_options() if self.options is None else self.options # Python does not allow to define properties in run-time with setattr
365
366
  self.decimal_to_precision = decimal_to_precision
ccxt/binance.py CHANGED
@@ -9122,7 +9122,7 @@ class binance(Exchange, ImplicitAPI):
9122
9122
  liquidationPrice = self.parse_number(liquidationPriceString)
9123
9123
  collateralString = None
9124
9124
  marginMode = self.safe_string(position, 'marginType')
9125
- if marginMode is None and isolatedMarginString:
9125
+ if marginMode is None and isolatedMarginString is not None:
9126
9126
  marginMode = 'cross' if Precise.string_eq(isolatedMarginString, '0') else 'isolated'
9127
9127
  side = None
9128
9128
  if Precise.string_gt(notionalString, '0'):
ccxt/bitmart.py CHANGED
@@ -129,7 +129,8 @@ class bitmart(Exchange, ImplicitAPI):
129
129
  'urls': {
130
130
  'logo': 'https://user-images.githubusercontent.com/1294454/129991357-8f47464b-d0f4-41d6-8a82-34122f0d1398.jpg',
131
131
  'api': {
132
- 'rest': 'https://api-cloud.{hostname}', # bitmart.info for Hong Kong users
132
+ 'spot': 'https://api-cloud.{hostname}',
133
+ 'swap': 'https://api-cloud-v2.{hostname}', # bitmart.info for Hong Kong users
133
134
  },
134
135
  'www': 'https://www.bitmart.com/',
135
136
  'doc': 'https://developer-pro.bitmart.com/',
@@ -220,6 +221,8 @@ class bitmart(Exchange, ImplicitAPI):
220
221
  'contract/private/current-plan-order': 1.2,
221
222
  'contract/private/trades': 10,
222
223
  'contract/private/position-risk': 10,
224
+ 'contract/private/affilate/rebate-list': 10,
225
+ 'contract/private/affilate/trade-list': 10,
223
226
  },
224
227
  'post': {
225
228
  # sub-account endpoints
@@ -513,8 +516,8 @@ class bitmart(Exchange, ImplicitAPI):
513
516
  '40045': InvalidOrder, # 400, The order open type is invalid
514
517
  '40046': PermissionDenied, # 403, The account is not opened futures
515
518
  '40047': PermissionDenied, # 403, Services is not available in you countries and areas
516
- '40048': BadRequest, # 403, ClientOrderId only allows a combination of numbers and letters
517
- '40049': BadRequest, # 403, The maximum length of clientOrderId cannot exceed 32
519
+ '40048': InvalidOrder, # 403, ClientOrderId only allows a combination of numbers and letters
520
+ '40049': InvalidOrder, # 403, The maximum length of clientOrderId cannot exceed 32
518
521
  '40050': InvalidOrder, # 403, Client OrderId duplicated with existing orders
519
522
  },
520
523
  'broad': {},
@@ -877,36 +880,43 @@ class bitmart(Exchange, ImplicitAPI):
877
880
  def fetch_contract_markets(self, params={}):
878
881
  response = self.publicGetContractPublicDetails(params)
879
882
  #
880
- # {
881
- # "code": 1000,
882
- # "message": "Ok",
883
- # "trace": "9b92a999-9463-4c96-91a4-93ad1cad0d72",
884
- # "data": {
885
- # "symbols": [{
886
- # "symbol": "BTCUSDT",
887
- # "product_type": 1,
888
- # "open_timestamp": 1594080000,
889
- # "expire_timestamp": 0,
890
- # "settle_timestamp": 0,
891
- # "base_currency": "BTC",
892
- # "quote_currency": "USDT",
893
- # "last_price": "23920",
894
- # "volume_24h": "18969368",
895
- # "turnover_24h": "458933659.7858",
896
- # "index_price": "23945.25191635",
897
- # "index_name": "BTCUSDT",
898
- # "contract_size": "0.001",
899
- # "min_leverage": "1",
900
- # "max_leverage": "100",
901
- # "price_precision": "0.1",
902
- # "vol_precision": "1",
903
- # "max_volume": "500000",
904
- # "min_volume": "1"
905
- # },
906
- # ...
907
- # ]
908
- # }
883
+ # {
884
+ # "code": 1000,
885
+ # "message": "Ok",
886
+ # "trace": "9b92a999-9463-4c96-91a4-93ad1cad0d72",
887
+ # "data": {
888
+ # "symbols": [
889
+ # {
890
+ # "symbol": "BTCUSDT",
891
+ # "product_type": 1,
892
+ # "open_timestamp": 1594080000,
893
+ # "expire_timestamp": 0,
894
+ # "settle_timestamp": 0,
895
+ # "base_currency": "BTC",
896
+ # "quote_currency": "USDT",
897
+ # "last_price": "23920",
898
+ # "volume_24h": "18969368",
899
+ # "turnover_24h": "458933659.7858",
900
+ # "index_price": "23945.25191635",
901
+ # "index_name": "BTCUSDT",
902
+ # "contract_size": "0.001",
903
+ # "min_leverage": "1",
904
+ # "max_leverage": "100",
905
+ # "price_precision": "0.1",
906
+ # "vol_precision": "1",
907
+ # "max_volume": "500000",
908
+ # "min_volume": "1",
909
+ # "funding_rate": "0.0001",
910
+ # "expected_funding_rate": "0.00011",
911
+ # "open_interest": "4134180870",
912
+ # "open_interest_value": "94100888927.0433258",
913
+ # "high_24h": "23900",
914
+ # "low_24h": "23100",
915
+ # "change_24h": "0.004"
916
+ # },
917
+ # ]
909
918
  # }
919
+ # }
910
920
  #
911
921
  data = self.safe_value(response, 'data', {})
912
922
  symbols = self.safe_value(data, 'symbols', [])
@@ -981,6 +991,7 @@ class bitmart(Exchange, ImplicitAPI):
981
991
 
982
992
  def fetch_markets(self, params={}) -> List[Market]:
983
993
  """
994
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-contract-details
984
995
  retrieves data on all markets for bitmart
985
996
  :param dict [params]: extra parameters specific to the exchange API endpoint
986
997
  :returns dict[]: an array of objects representing market data
@@ -1179,25 +1190,41 @@ class bitmart(Exchange, ImplicitAPI):
1179
1190
  #
1180
1191
  # swap
1181
1192
  #
1182
- # {
1183
- # "contract_symbol":"DOGEUSDT",
1184
- # "last_price":"0.130340",
1185
- # "index_price":"0.13048245",
1186
- # "last_funding_rate":"0.00002287",
1187
- # "price_change_percent_24h":"-2.074",
1188
- # "volume_24h":"113705028.59482228",
1189
- # "url":"https://futures.bitmart.com/en?symbol=DOGEUSDT",
1190
- # "high_price":"0.134520",
1191
- # "low_price":"0.128570",
1192
- # "legal_coin_price":"0.1302699"
1193
- # }
1193
+ # {
1194
+ # "symbol": "BTCUSDT",
1195
+ # "product_type": 1,
1196
+ # "open_timestamp": 1594080000,
1197
+ # "expire_timestamp": 0,
1198
+ # "settle_timestamp": 0,
1199
+ # "base_currency": "BTC",
1200
+ # "quote_currency": "USDT",
1201
+ # "last_price": "23920",
1202
+ # "volume_24h": "18969368",
1203
+ # "turnover_24h": "458933659.7858",
1204
+ # "index_price": "23945.25191635",
1205
+ # "index_name": "BTCUSDT",
1206
+ # "contract_size": "0.001",
1207
+ # "min_leverage": "1",
1208
+ # "max_leverage": "100",
1209
+ # "price_precision": "0.1",
1210
+ # "vol_precision": "1",
1211
+ # "max_volume": "500000",
1212
+ # "min_volume": "1",
1213
+ # "funding_rate": "0.0001",
1214
+ # "expected_funding_rate": "0.00011",
1215
+ # "open_interest": "4134180870",
1216
+ # "open_interest_value": "94100888927.0433258",
1217
+ # "high_24h": "23900",
1218
+ # "low_24h": "23100",
1219
+ # "change_24h": "0.004"
1220
+ # }
1194
1221
  #
1195
1222
  result = self.safe_list(ticker, 'result', [])
1196
1223
  average = self.safe_string_2(ticker, 'avg_price', 'index_price')
1197
1224
  marketId = self.safe_string_2(ticker, 'symbol', 'contract_symbol')
1198
1225
  timestamp = self.safe_integer_2(ticker, 'timestamp', 'ts')
1199
1226
  last = self.safe_string_2(ticker, 'last_price', 'last')
1200
- percentage = self.safe_string(ticker, 'price_change_percent_24h')
1227
+ percentage = self.safe_string_2(ticker, 'price_change_percent_24h', 'change_24h')
1201
1228
  change = self.safe_string(ticker, 'fluctuation')
1202
1229
  high = self.safe_string_2(ticker, 'high_24h', 'high_price')
1203
1230
  low = self.safe_string_2(ticker, 'low_24h', 'low_price')
@@ -1206,8 +1233,8 @@ class bitmart(Exchange, ImplicitAPI):
1206
1233
  ask = self.safe_string_2(ticker, 'best_ask', 'ask_px')
1207
1234
  askVolume = self.safe_string_2(ticker, 'best_ask_size', 'ask_sz')
1208
1235
  open = self.safe_string(ticker, 'open_24h')
1209
- baseVolume = self.safe_string_2(ticker, 'base_volume_24h', 'v_24h')
1210
- quoteVolume = self.safe_string_lower_2(ticker, 'quote_volume_24h', 'qv_24h')
1236
+ baseVolume = self.safe_string_n(ticker, ['base_volume_24h', 'v_24h', 'volume_24h'])
1237
+ quoteVolume = self.safe_string_lower_n(ticker, ['quote_volume_24h', 'qv_24h', 'turnover_24h'])
1211
1238
  listMarketId = self.safe_string(result, 0)
1212
1239
  if listMarketId is not None:
1213
1240
  marketId = listMarketId
@@ -1266,6 +1293,7 @@ class bitmart(Exchange, ImplicitAPI):
1266
1293
  """
1267
1294
  fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1268
1295
  :see: https://developer-pro.bitmart.com/en/spot/#get-ticker-of-a-trading-pair-v3
1296
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-contract-details
1269
1297
  :param str symbol: unified symbol of the market to fetch the ticker for
1270
1298
  :param dict [params]: extra parameters specific to the exchange API endpoint
1271
1299
  :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
@@ -1275,8 +1303,8 @@ class bitmart(Exchange, ImplicitAPI):
1275
1303
  request: dict = {}
1276
1304
  response = None
1277
1305
  if market['swap']:
1278
- request['contract_symbol'] = market['id']
1279
- response = self.publicGetContractV1Tickers(self.extend(request, params))
1306
+ request['symbol'] = market['id']
1307
+ response = self.publicGetContractPublicDetails(self.extend(request, params))
1280
1308
  #
1281
1309
  # {
1282
1310
  # "message":"OK",
@@ -1328,22 +1356,21 @@ class bitmart(Exchange, ImplicitAPI):
1328
1356
  else:
1329
1357
  raise NotSupported(self.id + ' fetchTicker() does not support ' + market['type'] + ' markets, only spot and swap markets are accepted')
1330
1358
  # fails in naming for contract tickers 'contract_symbol'
1331
- tickersById = None
1332
1359
  tickers = []
1333
1360
  ticker: dict = {}
1334
1361
  if market['spot']:
1335
1362
  ticker = self.safe_dict(response, 'data', {})
1336
1363
  else:
1337
1364
  data = self.safe_dict(response, 'data', {})
1338
- tickers = self.safe_list(data, 'tickers', [])
1339
- tickersById = self.index_by(tickers, 'contract_symbol')
1340
- ticker = self.safe_dict(tickersById, market['id'])
1365
+ tickers = self.safe_list(data, 'symbols', [])
1366
+ ticker = self.safe_value(tickers, 0, {})
1341
1367
  return self.parse_ticker(ticker, market)
1342
1368
 
1343
1369
  def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
1344
1370
  """
1345
1371
  fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1346
1372
  :see: https://developer-pro.bitmart.com/en/spot/#get-ticker-of-all-pairs-v3
1373
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-contract-details
1347
1374
  :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1348
1375
  :param dict [params]: extra parameters specific to the exchange API endpoint
1349
1376
  :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
@@ -1384,29 +1411,45 @@ class bitmart(Exchange, ImplicitAPI):
1384
1411
  # }
1385
1412
  #
1386
1413
  elif type == 'swap':
1387
- response = self.publicGetContractV1Tickers(params)
1414
+ response = self.publicGetContractPublicDetails(params)
1388
1415
  #
1389
- # {
1390
- # "message": "OK",
1391
- # "code": 1000,
1392
- # "trace": "c1dec681c24ea5d.105.171712565",
1393
- # "data": {
1394
- # "tickers": [
1395
- # {
1396
- # "contract_symbol": "SNTUSDT",
1397
- # "last_price": "0.0366600",
1398
- # "index_price": "0.03587373",
1399
- # "last_funding_rate": "0.00005000",
1400
- # "price_change_percent_24h": "-2.629",
1401
- # "volume_24h": "10102540.19909109848",
1402
- # "url": "https://futures.bitmart.com/en?symbol=SNTUSDT",
1403
- # "high_price": "0.0405600",
1404
- # "low_price": "0.0355000",
1405
- # "legal_coin_price": "0.03666697"
1406
- # },
1407
- # ]
1408
- # }
1409
- # }
1416
+ # {
1417
+ # "code": 1000,
1418
+ # "message": "Ok",
1419
+ # "trace": "9b92a999-9463-4c96-91a4-93ad1cad0d72",
1420
+ # "data": {
1421
+ # "symbols": [
1422
+ # {
1423
+ # "symbol": "BTCUSDT",
1424
+ # "product_type": 1,
1425
+ # "open_timestamp": 1594080000,
1426
+ # "expire_timestamp": 0,
1427
+ # "settle_timestamp": 0,
1428
+ # "base_currency": "BTC",
1429
+ # "quote_currency": "USDT",
1430
+ # "last_price": "23920",
1431
+ # "volume_24h": "18969368",
1432
+ # "turnover_24h": "458933659.7858",
1433
+ # "index_price": "23945.25191635",
1434
+ # "index_name": "BTCUSDT",
1435
+ # "contract_size": "0.001",
1436
+ # "min_leverage": "1",
1437
+ # "max_leverage": "100",
1438
+ # "price_precision": "0.1",
1439
+ # "vol_precision": "1",
1440
+ # "max_volume": "500000",
1441
+ # "min_volume": "1",
1442
+ # "funding_rate": "0.0001",
1443
+ # "expected_funding_rate": "0.00011",
1444
+ # "open_interest": "4134180870",
1445
+ # "open_interest_value": "94100888927.0433258",
1446
+ # "high_24h": "23900",
1447
+ # "low_24h": "23100",
1448
+ # "change_24h": "0.004"
1449
+ # },
1450
+ # ]
1451
+ # }
1452
+ # }
1410
1453
  #
1411
1454
  else:
1412
1455
  raise NotSupported(self.id + ' fetchTickers() does not support ' + type + ' markets, only spot and swap markets are accepted')
@@ -1415,7 +1458,7 @@ class bitmart(Exchange, ImplicitAPI):
1415
1458
  tickers = self.safe_list(response, 'data', [])
1416
1459
  else:
1417
1460
  data = self.safe_dict(response, 'data', {})
1418
- tickers = self.safe_list(data, 'tickers', [])
1461
+ tickers = self.safe_list(data, 'symbols', [])
1419
1462
  result: dict = {}
1420
1463
  for i in range(0, len(tickers)):
1421
1464
  ticker: dict = {}
@@ -1432,6 +1475,7 @@ class bitmart(Exchange, ImplicitAPI):
1432
1475
  fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
1433
1476
  :see: https://developer-pro.bitmart.com/en/spot/#get-depth-v3
1434
1477
  :see: https://developer-pro.bitmart.com/en/futures/#get-market-depth
1478
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-market-depth
1435
1479
  :param str symbol: unified symbol of the market to fetch the order book for
1436
1480
  :param int [limit]: the maximum amount of order book entries to return
1437
1481
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -1707,7 +1751,7 @@ class bitmart(Exchange, ImplicitAPI):
1707
1751
  """
1708
1752
  fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1709
1753
  :see: https://developer-pro.bitmart.com/en/spot/#get-history-k-line-v3
1710
- :see: https://developer-pro.bitmart.com/en/futures/#get-k-line
1754
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-k-line
1711
1755
  :param str symbol: unified symbol of the market to fetch OHLCV data for
1712
1756
  :param str timeframe: the length of time each candle represents
1713
1757
  :param int [since]: timestamp in ms of the earliest candle to fetch
@@ -1968,6 +2012,7 @@ class bitmart(Exchange, ImplicitAPI):
1968
2012
  query for balance and get the amount of funds available for trading or funds locked in orders
1969
2013
  :see: https://developer-pro.bitmart.com/en/spot/#get-spot-wallet-balance
1970
2014
  :see: https://developer-pro.bitmart.com/en/futures/#get-contract-assets-detail
2015
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-contract-assets-keyed
1971
2016
  :see: https://developer-pro.bitmart.com/en/spot/#get-account-balance
1972
2017
  :see: https://developer-pro.bitmart.com/en/spot/#get-margin-account-details-isolated
1973
2018
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -2319,6 +2364,8 @@ class bitmart(Exchange, ImplicitAPI):
2319
2364
  :see: https://developer-pro.bitmart.com/en/spot/#place-margin-order
2320
2365
  :see: https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2321
2366
  :see: https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2367
+ :see: https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2368
+ :see: https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2322
2369
  :param str symbol: unified symbol of the market to create an order in
2323
2370
  :param str type: 'market', 'limit' or 'trailing' for swap markets only
2324
2371
  :param str side: 'buy' or 'sell'
@@ -2531,9 +2578,10 @@ class bitmart(Exchange, ImplicitAPI):
2531
2578
  if clientOrderId is not None:
2532
2579
  params = self.omit(params, 'clientOrderId')
2533
2580
  request['client_order_id'] = clientOrderId
2534
- leverage = self.safe_integer(params, 'leverage', 1)
2581
+ leverage = self.safe_integer(params, 'leverage')
2535
2582
  params = self.omit(params, ['timeInForce', 'postOnly', 'reduceOnly', 'leverage', 'trailingTriggerPrice', 'trailingPercent', 'triggerPrice', 'stopPrice'])
2536
- request['leverage'] = self.number_to_string(leverage)
2583
+ if leverage is not None:
2584
+ request['leverage'] = self.number_to_string(leverage)
2537
2585
  return self.extend(request, params)
2538
2586
 
2539
2587
  def create_spot_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
@@ -2608,6 +2656,8 @@ class bitmart(Exchange, ImplicitAPI):
2608
2656
  :see: https://developer-pro.bitmart.com/en/spot/#cancel-order-v3-signed
2609
2657
  :see: https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2610
2658
  :see: https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2659
+ :see: https://developer-pro.bitmart.com/en/futures/#cancel-order-signed
2660
+ :see: https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2611
2661
  :param str id: order id
2612
2662
  :param str symbol: unified symbol of the market the order was made in
2613
2663
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -2737,6 +2787,7 @@ class bitmart(Exchange, ImplicitAPI):
2737
2787
  cancel all open orders in a market
2738
2788
  :see: https://developer-pro.bitmart.com/en/spot/#cancel-all-orders
2739
2789
  :see: https://developer-pro.bitmart.com/en/futures/#cancel-all-orders-signed
2790
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#cancel-all-orders-signed
2740
2791
  :param str symbol: unified market symbol of the market to cancel orders in
2741
2792
  :param dict [params]: extra parameters specific to the exchange API endpoint
2742
2793
  :param str [params.side]: *spot only* 'buy' or 'sell'
@@ -2949,6 +3000,7 @@ class bitmart(Exchange, ImplicitAPI):
2949
3000
  """
2950
3001
  :see: https://developer-pro.bitmart.com/en/spot/#account-orders-v4-signed
2951
3002
  :see: https://developer-pro.bitmart.com/en/futures/#get-order-history-keyed
3003
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-order-history-keyed
2952
3004
  fetches information on multiple closed orders made by the user
2953
3005
  :param str symbol: unified market symbol of the market orders were made in
2954
3006
  :param int [since]: the earliest time in ms to fetch orders for
@@ -3006,6 +3058,7 @@ class bitmart(Exchange, ImplicitAPI):
3006
3058
  :see: https://developer-pro.bitmart.com/en/spot/#query-order-by-id-v4-signed
3007
3059
  :see: https://developer-pro.bitmart.com/en/spot/#query-order-by-clientorderid-v4-signed
3008
3060
  :see: https://developer-pro.bitmart.com/en/futures/#get-order-detail-keyed
3061
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-order-detail-keyed
3009
3062
  :param str id: the id of the order
3010
3063
  :param str symbol: unified symbol of the market the order was made in
3011
3064
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -3694,6 +3747,7 @@ class bitmart(Exchange, ImplicitAPI):
3694
3747
  transfer currency internally between wallets on the same account, currently only supports transfer between spot and margin
3695
3748
  :see: https://developer-pro.bitmart.com/en/spot/#margin-asset-transfer-signed
3696
3749
  :see: https://developer-pro.bitmart.com/en/futures/#transfer-signed
3750
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#transfer-signed
3697
3751
  :param str code: unified currency code
3698
3752
  :param float amount: amount to transfer
3699
3753
  :param str fromAccount: account to transfer from
@@ -3955,7 +4009,7 @@ class bitmart(Exchange, ImplicitAPI):
3955
4009
  def fetch_open_interest(self, symbol: str, params={}):
3956
4010
  """
3957
4011
  Retrieves the open interest of a currency
3958
- :see: https://developer-pro.bitmart.com/en/futures/#get-futures-openinterest
4012
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-futures-openinterest
3959
4013
  :param str symbol: Unified CCXT market symbol
3960
4014
  :param dict [params]: exchange specific parameters
3961
4015
  :returns dict} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure:
@@ -4008,6 +4062,7 @@ class bitmart(Exchange, ImplicitAPI):
4008
4062
  """
4009
4063
  set the level of leverage for a market
4010
4064
  :see: https://developer-pro.bitmart.com/en/futures/#submit-leverage-signed
4065
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#submit-leverage-signed
4011
4066
  :param float leverage: the rate of leverage
4012
4067
  :param str symbol: unified market symbol
4013
4068
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -4033,7 +4088,7 @@ class bitmart(Exchange, ImplicitAPI):
4033
4088
  def fetch_funding_rate(self, symbol: str, params={}):
4034
4089
  """
4035
4090
  fetch the current funding rate
4036
- :see: https://developer-pro.bitmart.com/en/futures/#get-current-funding-rate
4091
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-current-funding-rate
4037
4092
  :param str symbol: unified market symbol
4038
4093
  :param dict [params]: extra parameters specific to the exchange API endpoint
4039
4094
  :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
@@ -4097,6 +4152,7 @@ class bitmart(Exchange, ImplicitAPI):
4097
4152
  """
4098
4153
  fetch data on a single open contract trade position
4099
4154
  :see: https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
4155
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-current-position-risk-details-keyed
4100
4156
  :param str symbol: unified market symbol of the market the position is held in
4101
4157
  :param dict [params]: extra parameters specific to the exchange API endpoint
4102
4158
  :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
@@ -4144,6 +4200,7 @@ class bitmart(Exchange, ImplicitAPI):
4144
4200
  """
4145
4201
  fetch all open contract positions
4146
4202
  :see: https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
4203
+ :see: https://developer-pro.bitmart.com/en/futuresv2/#get-current-position-risk-details-keyed
4147
4204
  :param str[]|None symbols: list of unified market symbols
4148
4205
  :param dict [params]: extra parameters specific to the exchange API endpoint
4149
4206
  :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
@@ -4360,7 +4417,11 @@ class bitmart(Exchange, ImplicitAPI):
4360
4417
  return self.milliseconds()
4361
4418
 
4362
4419
  def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
4363
- baseUrl = self.implode_hostname(self.urls['api']['rest'])
4420
+ parts = path.split('/')
4421
+ # to do: refactor api endpoints with spot/swap sections
4422
+ category = self.safe_string(parts, 0, 'spot')
4423
+ market = 'spot' if (category == 'spot' or category == 'account') else 'swap'
4424
+ baseUrl = self.implode_hostname(self.urls['api'][market])
4364
4425
  url = baseUrl + '/' + self.implode_params(path, params)
4365
4426
  query = self.omit(params, self.extract_params(path))
4366
4427
  queryString = ''
ccxt/bybit.py CHANGED
@@ -254,6 +254,7 @@ class bybit(Exchange, ImplicitAPI):
254
254
  },
255
255
  'private': {
256
256
  'get': {
257
+ 'v5/market/instruments-info': 5,
257
258
  # Legacy inverse swap
258
259
  'v2/private/wallet/fund/records': 25, # 120 per minute = 2 per second => cost = 50 / 2 = 25
259
260
  # spot
@@ -999,6 +1000,7 @@ class bybit(Exchange, ImplicitAPI):
999
1000
  },
1000
1001
  'precisionMode': TICK_SIZE,
1001
1002
  'options': {
1003
+ 'usePrivateInstrumentsInfo': False,
1002
1004
  'sandboxMode': False,
1003
1005
  'enableDemoTrading': False,
1004
1006
  'fetchMarkets': ['spot', 'linear', 'inverse', 'option'],
@@ -1457,7 +1459,12 @@ class bybit(Exchange, ImplicitAPI):
1457
1459
  request: dict = {
1458
1460
  'category': 'spot',
1459
1461
  }
1460
- response = self.publicGetV5MarketInstrumentsInfo(self.extend(request, params))
1462
+ usePrivateInstrumentsInfo = self.safe_bool(self.options, 'usePrivateInstrumentsInfo', False)
1463
+ response: dict = None
1464
+ if usePrivateInstrumentsInfo:
1465
+ response = self.privateGetV5MarketInstrumentsInfo(self.extend(request, params))
1466
+ else:
1467
+ response = self.publicGetV5MarketInstrumentsInfo(self.extend(request, params))
1461
1468
  #
1462
1469
  # {
1463
1470
  # "retCode": 0,
@@ -1566,14 +1573,23 @@ class bybit(Exchange, ImplicitAPI):
1566
1573
  def fetch_future_markets(self, params):
1567
1574
  params = self.extend(params)
1568
1575
  params['limit'] = 1000 # minimize number of requests
1569
- response = self.publicGetV5MarketInstrumentsInfo(params)
1576
+ usePrivateInstrumentsInfo = self.safe_bool(self.options, 'usePrivateInstrumentsInfo', False)
1577
+ response: dict = None
1578
+ if usePrivateInstrumentsInfo:
1579
+ response = self.privateGetV5MarketInstrumentsInfo(params)
1580
+ else:
1581
+ response = self.publicGetV5MarketInstrumentsInfo(params)
1570
1582
  data = self.safe_dict(response, 'result', {})
1571
1583
  markets = self.safe_list(data, 'list', [])
1572
1584
  paginationCursor = self.safe_string(data, 'nextPageCursor')
1573
1585
  if paginationCursor is not None:
1574
1586
  while(paginationCursor is not None):
1575
1587
  params['cursor'] = paginationCursor
1576
- responseInner = self.publicGetV5MarketInstrumentsInfo(params)
1588
+ responseInner: dict = None
1589
+ if usePrivateInstrumentsInfo:
1590
+ responseInner = self.privateGetV5MarketInstrumentsInfo(params)
1591
+ else:
1592
+ responseInner = self.publicGetV5MarketInstrumentsInfo(params)
1577
1593
  dataNew = self.safe_dict(responseInner, 'result', {})
1578
1594
  rawMarkets = self.safe_list(dataNew, 'list', [])
1579
1595
  rawMarketsLength = len(rawMarkets)
@@ -1730,7 +1746,12 @@ class bybit(Exchange, ImplicitAPI):
1730
1746
  request: dict = {
1731
1747
  'category': 'option',
1732
1748
  }
1733
- response = self.publicGetV5MarketInstrumentsInfo(self.extend(request, params))
1749
+ usePrivateInstrumentsInfo = self.safe_bool(self.options, 'usePrivateInstrumentsInfo', False)
1750
+ response: dict = None
1751
+ if usePrivateInstrumentsInfo:
1752
+ response = self.privateGetV5MarketInstrumentsInfo(self.extend(request, params))
1753
+ else:
1754
+ response = self.publicGetV5MarketInstrumentsInfo(self.extend(request, params))
1734
1755
  data = self.safe_dict(response, 'result', {})
1735
1756
  markets = self.safe_list(data, 'list', [])
1736
1757
  if self.options['loadAllOptions']:
@@ -1739,7 +1760,11 @@ class bybit(Exchange, ImplicitAPI):
1739
1760
  if paginationCursor is not None:
1740
1761
  while(paginationCursor is not None):
1741
1762
  request['cursor'] = paginationCursor
1742
- responseInner = self.publicGetV5MarketInstrumentsInfo(self.extend(request, params))
1763
+ responseInner: dict = None
1764
+ if usePrivateInstrumentsInfo:
1765
+ responseInner = self.privateGetV5MarketInstrumentsInfo(self.extend(request, params))
1766
+ else:
1767
+ responseInner = self.publicGetV5MarketInstrumentsInfo(self.extend(request, params))
1743
1768
  dataNew = self.safe_dict(responseInner, 'result', {})
1744
1769
  rawMarkets = self.safe_list(dataNew, 'list', [])
1745
1770
  rawMarketsLength = len(rawMarkets)