ccxt 4.4.4__py2.py3-none-any.whl → 4.4.6__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.
@@ -45,6 +45,9 @@ class mexc(Exchange, ImplicitAPI):
45
45
  'future': False,
46
46
  'option': False,
47
47
  'addMargin': True,
48
+ 'borrowCrossMargin': False,
49
+ 'borrowIsolatedMargin': False,
50
+ 'borrowMargin': False,
48
51
  'cancelAllOrders': True,
49
52
  'cancelOrder': True,
50
53
  'cancelOrders': None,
@@ -58,12 +61,21 @@ class mexc(Exchange, ImplicitAPI):
58
61
  'createOrders': True,
59
62
  'createPostOnlyOrder': True,
60
63
  'createReduceOnlyOrder': True,
64
+ 'createStopLimitOrder': True,
65
+ 'createStopMarketOrder': True,
66
+ 'createStopOrder': True,
67
+ 'createTriggerOrder': True,
61
68
  'deposit': None,
62
69
  'editOrder': None,
63
70
  'fetchAccounts': True,
64
71
  'fetchBalance': True,
65
72
  'fetchBidsAsks': True,
66
- 'fetchBorrowRateHistory': None,
73
+ 'fetchBorrowInterest': False,
74
+ 'fetchBorrowRate': False,
75
+ 'fetchBorrowRateHistories': False,
76
+ 'fetchBorrowRateHistory': False,
77
+ 'fetchBorrowRates': False,
78
+ 'fetchBorrowRatesPerSymbol': False,
67
79
  'fetchCanceledOrders': True,
68
80
  'fetchClosedOrder': None,
69
81
  'fetchClosedOrders': True,
@@ -84,6 +96,7 @@ class mexc(Exchange, ImplicitAPI):
84
96
  'fetchIndexOHLCV': True,
85
97
  'fetchIsolatedBorrowRate': False,
86
98
  'fetchIsolatedBorrowRates': False,
99
+ 'fetchIsolatedPositions': False,
87
100
  'fetchL2OrderBook': True,
88
101
  'fetchLedger': None,
89
102
  'fetchLedgerEntry': None,
@@ -92,11 +105,13 @@ class mexc(Exchange, ImplicitAPI):
92
105
  'fetchLeverageTiers': True,
93
106
  'fetchMarginAdjustmentHistory': False,
94
107
  'fetchMarginMode': False,
95
- 'fetchMarketLeverageTiers': None,
108
+ 'fetchMarketLeverageTiers': 'emulated',
96
109
  'fetchMarkets': True,
97
110
  'fetchMarkOHLCV': True,
98
111
  'fetchMyTrades': True,
99
112
  'fetchOHLCV': True,
113
+ 'fetchOpenInterest': False,
114
+ 'fetchOpenInterestHistory': False,
100
115
  'fetchOpenOrder': None,
101
116
  'fetchOpenOrders': True,
102
117
  'fetchOrder': True,
@@ -104,7 +119,7 @@ class mexc(Exchange, ImplicitAPI):
104
119
  'fetchOrderBooks': None,
105
120
  'fetchOrders': True,
106
121
  'fetchOrderTrades': True,
107
- 'fetchPosition': True,
122
+ 'fetchPosition': 'emulated',
108
123
  'fetchPositionHistory': 'emulated',
109
124
  'fetchPositionMode': True,
110
125
  'fetchPositions': True,
@@ -414,6 +429,8 @@ class mexc(Exchange, ImplicitAPI):
414
429
  },
415
430
  },
416
431
  'options': {
432
+ 'adjustForTimeDifference': False,
433
+ 'timeDifference': 0,
417
434
  'createMarketBuyOrderRequiresPrice': True,
418
435
  'unavailableContracts': {
419
436
  'BTC/USDT:USDT': True,
@@ -468,6 +485,7 @@ class mexc(Exchange, ImplicitAPI):
468
485
  'AVAXC': 'AVAX_CCHAIN',
469
486
  'ERC20': 'ETH',
470
487
  'ACA': 'ACALA',
488
+ 'BEP20': 'BSC',
471
489
  # 'ADA': 'Cardano(ADA)',
472
490
  # 'AE': 'AE',
473
491
  # 'ALGO': 'Algorand(ALGO)',
@@ -1008,6 +1026,8 @@ class mexc(Exchange, ImplicitAPI):
1008
1026
  :param dict [params]: extra parameters specific to the exchange API endpoint
1009
1027
  :returns dict[]: an array of objects representing market data
1010
1028
  """
1029
+ if self.options['adjustForTimeDifference']:
1030
+ await self.load_time_difference()
1011
1031
  spotMarketPromise = self.fetch_spot_markets(params)
1012
1032
  swapMarketPromise = self.fetch_swap_markets(params)
1013
1033
  spotMarket, swapMarket = await asyncio.gather(*[spotMarketPromise, swapMarketPromise])
@@ -2737,6 +2757,9 @@ class mexc(Exchange, ImplicitAPI):
2737
2757
  async def cancel_order(self, id: str, symbol: Str = None, params={}):
2738
2758
  """
2739
2759
  cancels an open order
2760
+ :see: https://mexcdevelop.github.io/apidocs/spot_v3_en/#cancel-order
2761
+ :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-the-order-under-maintenance
2762
+ :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-the-stop-limit-trigger-order-under-maintenance
2740
2763
  :param str id: order id
2741
2764
  :param str symbol: unified symbol of the market the order was made in
2742
2765
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -2839,6 +2862,7 @@ class mexc(Exchange, ImplicitAPI):
2839
2862
  async def cancel_orders(self, ids, symbol: Str = None, params={}):
2840
2863
  """
2841
2864
  cancel multiple orders
2865
+ :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#cancel-the-order-under-maintenance
2842
2866
  :param str[] ids: order ids
2843
2867
  :param str symbol: unified market symbol, default is None
2844
2868
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -4244,7 +4268,7 @@ class mexc(Exchange, ImplicitAPI):
4244
4268
  # 'coin': currency['id'] + network example: USDT-TRX,
4245
4269
  # 'status': 'status',
4246
4270
  # 'startTime': since, # default 90 days
4247
- # 'endTime': self.milliseconds(),
4271
+ # 'endTime': self.nonce(),
4248
4272
  # 'limit': limit, # default 1000, maximum 1000
4249
4273
  }
4250
4274
  currency = None
@@ -4297,7 +4321,7 @@ class mexc(Exchange, ImplicitAPI):
4297
4321
  # 'coin': currency['id'],
4298
4322
  # 'status': 'status',
4299
4323
  # 'startTime': since, # default 90 days
4300
- # 'endTime': self.milliseconds(),
4324
+ # 'endTime': self.nonce(),
4301
4325
  # 'limit': limit, # default 1000, maximum 1000
4302
4326
  }
4303
4327
  currency = None
@@ -4452,6 +4476,7 @@ class mexc(Exchange, ImplicitAPI):
4452
4476
  async def fetch_position(self, symbol: str, params={}):
4453
4477
  """
4454
4478
  fetch data on a single open contract trade position
4479
+ :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-user-s-history-position-information
4455
4480
  :param str symbol: unified market symbol of the market the position is held in, default is None
4456
4481
  :param dict [params]: extra parameters specific to the exchange API endpoint
4457
4482
  :returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
@@ -4467,6 +4492,7 @@ class mexc(Exchange, ImplicitAPI):
4467
4492
  async def fetch_positions(self, symbols: Strings = None, params={}):
4468
4493
  """
4469
4494
  fetch all open positions
4495
+ :see: https://mexcdevelop.github.io/apidocs/contract_v1_en/#get-the-user-s-history-position-information
4470
4496
  :param str[]|None symbols: list of unified market symbols
4471
4497
  :param dict [params]: extra parameters specific to the exchange API endpoint
4472
4498
  :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
@@ -5260,6 +5286,9 @@ class mexc(Exchange, ImplicitAPI):
5260
5286
  positions = self.parse_positions(data, symbols, params)
5261
5287
  return self.filter_by_since_limit(positions, since, limit)
5262
5288
 
5289
+ def nonce(self):
5290
+ return self.milliseconds() - self.safe_integer(self.options, 'timeDifference', 0)
5291
+
5263
5292
  def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
5264
5293
  section = self.safe_string(api, 0)
5265
5294
  access = self.safe_string(api, 1)
@@ -5272,7 +5301,7 @@ class mexc(Exchange, ImplicitAPI):
5272
5301
  url = self.urls['api'][section][access] + '/api/' + self.version + '/' + path
5273
5302
  paramsEncoded = ''
5274
5303
  if access == 'private':
5275
- params['timestamp'] = self.milliseconds()
5304
+ params['timestamp'] = self.nonce()
5276
5305
  params['recvWindow'] = self.safe_integer(self.options, 'recvWindow', 5000)
5277
5306
  if params:
5278
5307
  paramsEncoded = self.urlencode(params)
@@ -5295,7 +5324,7 @@ class mexc(Exchange, ImplicitAPI):
5295
5324
  url += '?' + self.urlencode(params)
5296
5325
  else:
5297
5326
  self.check_required_credentials()
5298
- timestamp = str(self.milliseconds())
5327
+ timestamp = str(self.nonce())
5299
5328
  auth = ''
5300
5329
  headers = {
5301
5330
  'ApiKey': self.apiKey,
@@ -640,7 +640,7 @@ class paradex(Exchange, ImplicitAPI):
640
640
  'low': None,
641
641
  'bid': self.safe_string(ticker, 'bid'),
642
642
  'bidVolume': None,
643
- 'ask': self.safe_string(ticker, 'sdk'),
643
+ 'ask': self.safe_string(ticker, 'ask'),
644
644
  'askVolume': None,
645
645
  'vwap': None,
646
646
  'open': None,
ccxt/base/exchange.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.4.4'
7
+ __version__ = '4.4.6'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
ccxt/binance.py CHANGED
@@ -1222,6 +1222,7 @@ class binance(Exchange, ImplicitAPI):
1222
1222
  # exchange-specific options
1223
1223
  'options': {
1224
1224
  'sandboxMode': False,
1225
+ 'fetchMargins': True,
1225
1226
  'fetchMarkets': [
1226
1227
  'spot', # allows CORS in browsers
1227
1228
  'linear', # allows CORS in browsers
@@ -2853,13 +2854,12 @@ class binance(Exchange, ImplicitAPI):
2853
2854
  if type == 'option' and sandboxMode:
2854
2855
  continue
2855
2856
  fetchMarkets.append(type)
2856
- fetchMargins = False
2857
+ fetchMargins = self.safe_bool(self.options, 'fetchMargins', False)
2857
2858
  for i in range(0, len(fetchMarkets)):
2858
2859
  marketType = fetchMarkets[i]
2859
2860
  if marketType == 'spot':
2860
2861
  promisesRaw.append(self.publicGetExchangeInfo(params))
2861
- if self.check_required_credentials(False) and not sandboxMode:
2862
- fetchMargins = True
2862
+ if fetchMargins and self.check_required_credentials(False) and not sandboxMode:
2863
2863
  promisesRaw.append(self.sapiGetMarginAllPairs(params))
2864
2864
  promisesRaw.append(self.sapiGetMarginIsolatedAllPairs(params))
2865
2865
  elif marketType == 'linear':
ccxt/binanceus.py CHANGED
@@ -44,6 +44,7 @@ class binanceus(binance, ImplicitAPI):
44
44
  'options': {
45
45
  'fetchMarkets': ['spot'],
46
46
  'defaultType': 'spot',
47
+ 'fetchMargins': False,
47
48
  'quoteOrderQty': False,
48
49
  },
49
50
  'has': {
ccxt/bitflyer.py CHANGED
@@ -995,8 +995,8 @@ class bitflyer(Exchange, ImplicitAPI):
995
995
  feedback = self.id + ' ' + body
996
996
  # i.e. {"status":-2,"error_message":"Under maintenance","data":null}
997
997
  errorMessage = self.safe_string(response, 'error_message')
998
- statusCode = self.safe_number(response, 'status')
998
+ statusCode = self.safe_integer(response, 'status')
999
999
  if errorMessage is not None:
1000
1000
  self.throw_exactly_matched_exception(self.exceptions['exact'], statusCode, feedback)
1001
- self.throw_broadly_matched_exception(self.exceptions['broad'], errorMessage, feedback)
1001
+ raise ExchangeError(feedback)
1002
1002
  return None
ccxt/bitget.py CHANGED
@@ -1336,6 +1336,8 @@ class bitget(Exchange, ImplicitAPI):
1336
1336
  'TONCOIN': 'TON',
1337
1337
  },
1338
1338
  'options': {
1339
+ 'timeDifference': 0, # the difference between system clock and Binance clock
1340
+ 'adjustForTimeDifference': False, # controls the adjustment logic upon instantiation
1339
1341
  'timeframes': {
1340
1342
  'spot': {
1341
1343
  '1m': '1min',
@@ -1534,17 +1536,21 @@ class bitget(Exchange, ImplicitAPI):
1534
1536
  retrieves data on all markets for bitget
1535
1537
  :see: https://www.bitget.com/api-doc/spot/market/Get-Symbols
1536
1538
  :see: https://www.bitget.com/api-doc/contract/market/Get-All-Symbols-Contracts
1539
+ :see: https://www.bitget.com/api-doc/margin/common/support-currencies
1537
1540
  :param dict [params]: extra parameters specific to the exchange API endpoint
1538
1541
  :returns dict[]: an array of objects representing market data
1539
1542
  """
1543
+ if self.options['adjustForTimeDifference']:
1544
+ self.load_time_difference()
1540
1545
  sandboxMode = self.safe_bool(self.options, 'sandboxMode', False)
1541
1546
  types = self.safe_value(self.options, 'fetchMarkets', ['spot', 'swap'])
1542
1547
  if sandboxMode:
1543
1548
  types = ['swap']
1544
1549
  promises = []
1550
+ fetchMargins = False
1545
1551
  for i in range(0, len(types)):
1546
1552
  type = types[i]
1547
- if type == 'swap':
1553
+ if (type == 'swap') or (type == 'future'):
1548
1554
  subTypes = None
1549
1555
  if sandboxMode:
1550
1556
  # the following are simulated trading markets ['SUSDT-FUTURES', 'SCOIN-FUTURES', 'SUSDC-FUTURES']
@@ -1552,15 +1558,33 @@ class bitget(Exchange, ImplicitAPI):
1552
1558
  else:
1553
1559
  subTypes = ['USDT-FUTURES', 'COIN-FUTURES', 'USDC-FUTURES']
1554
1560
  for j in range(0, len(subTypes)):
1555
- promises.append(self.fetch_markets_by_type(type, self.extend(params, {
1561
+ promises.append(self.publicMixGetV2MixMarketContracts(self.extend(params, {
1556
1562
  'productType': subTypes[j],
1557
1563
  })))
1564
+ elif type == 'spot':
1565
+ promises.append(self.publicSpotGetV2SpotPublicSymbols(params))
1566
+ fetchMargins = True
1567
+ promises.append(self.publicMarginGetV2MarginCurrencies(params))
1568
+ else:
1569
+ raise NotSupported(self.id + ' does not support ' + type + ' market')
1570
+ results = promises
1571
+ markets = []
1572
+ self.options['crossMarginPairsData'] = []
1573
+ self.options['isolatedMarginPairsData'] = []
1574
+ for i in range(0, len(results)):
1575
+ res = self.safe_dict(results, i)
1576
+ data = self.safe_list(res, 'data', [])
1577
+ firstData = self.safe_dict(data, 0, {})
1578
+ isBorrowable = self.safe_string(firstData, 'isBorrowable')
1579
+ if fetchMargins and isBorrowable is not None:
1580
+ keysList = list(self.index_by(data, 'symbol').keys())
1581
+ self.options['crossMarginPairsData'] = keysList
1582
+ self.options['isolatedMarginPairsData'] = keysList
1558
1583
  else:
1559
- promises.append(self.fetch_markets_by_type(types[i], params))
1560
- promises = promises
1561
- result = promises[0]
1562
- for i in range(1, len(promises)):
1563
- result = self.array_concat(result, promises[i])
1584
+ markets = self.array_concat(markets, data)
1585
+ result = []
1586
+ for i in range(0, len(markets)):
1587
+ result.append(self.parse_market(markets[i]))
1564
1588
  return result
1565
1589
 
1566
1590
  def parse_market(self, market: dict) -> Market:
@@ -1648,11 +1672,20 @@ class bitget(Exchange, ImplicitAPI):
1648
1672
  expiry = None
1649
1673
  expiryDatetime = None
1650
1674
  symbolType = self.safe_string(market, 'symbolType')
1675
+ marginModes = None
1676
+ isMarginTradingAllowed = False
1651
1677
  if symbolType is None:
1652
1678
  type = 'spot'
1653
1679
  spot = True
1654
1680
  pricePrecision = self.parse_number(self.parse_precision(self.safe_string(market, 'pricePrecision')))
1655
1681
  amountPrecision = self.parse_number(self.parse_precision(self.safe_string(market, 'quantityPrecision')))
1682
+ hasCrossMargin = self.in_array(marketId, self.options['crossMarginPairsData'])
1683
+ hasIsolatedMargin = self.in_array(marketId, self.options['isolatedMarginPairsData'])
1684
+ marginModes = {
1685
+ 'cross': hasCrossMargin,
1686
+ 'isolated': hasIsolatedMargin,
1687
+ }
1688
+ isMarginTradingAllowed = hasCrossMargin or hasCrossMargin
1656
1689
  else:
1657
1690
  if symbolType == 'perpetual':
1658
1691
  type = 'swap'
@@ -1688,6 +1721,10 @@ class bitget(Exchange, ImplicitAPI):
1688
1721
  preciseAmount.reduce()
1689
1722
  amountString = str(preciseAmount)
1690
1723
  amountPrecision = self.parse_number(amountString)
1724
+ marginModes = {
1725
+ 'cross': True,
1726
+ 'isolated': True,
1727
+ }
1691
1728
  status = self.safe_string_2(market, 'status', 'symbolStatus')
1692
1729
  active = None
1693
1730
  if status is not None:
@@ -1707,7 +1744,8 @@ class bitget(Exchange, ImplicitAPI):
1707
1744
  'settleId': settleId,
1708
1745
  'type': type,
1709
1746
  'spot': spot,
1710
- 'margin': None,
1747
+ 'margin': spot and isMarginTradingAllowed,
1748
+ 'marginModes': marginModes,
1711
1749
  'swap': swap,
1712
1750
  'future': future,
1713
1751
  'option': False,
@@ -1748,88 +1786,6 @@ class bitget(Exchange, ImplicitAPI):
1748
1786
  'info': market,
1749
1787
  }
1750
1788
 
1751
- def fetch_markets_by_type(self, type, params={}):
1752
- response = None
1753
- if type == 'spot':
1754
- response = self.publicSpotGetV2SpotPublicSymbols(params)
1755
- elif (type == 'swap') or (type == 'future'):
1756
- response = self.publicMixGetV2MixMarketContracts(params)
1757
- else:
1758
- raise NotSupported(self.id + ' does not support ' + type + ' market')
1759
- #
1760
- # spot
1761
- #
1762
- # {
1763
- # "code": "00000",
1764
- # "msg": "success",
1765
- # "requestTime": 1700102364653,
1766
- # "data": [
1767
- # {
1768
- # "symbol": "TRXUSDT",
1769
- # "baseCoin": "TRX",
1770
- # "quoteCoin": "USDT",
1771
- # "minTradeAmount": "0",
1772
- # "maxTradeAmount": "10000000000",
1773
- # "takerFeeRate": "0.002",
1774
- # "makerFeeRate": "0.002",
1775
- # "pricePrecision": "6",
1776
- # "quantityPrecision": "4",
1777
- # "quotePrecision": "6",
1778
- # "status": "online",
1779
- # "minTradeUSDT": "5",
1780
- # "buyLimitPriceRatio": "0.05",
1781
- # "sellLimitPriceRatio": "0.05"
1782
- # },
1783
- # ]
1784
- # }
1785
- #
1786
- # swap and future
1787
- #
1788
- # {
1789
- # "code": "00000",
1790
- # "msg": "success",
1791
- # "requestTime": 1700102364709,
1792
- # "data": [
1793
- # {
1794
- # "symbol": "BTCUSDT",
1795
- # "baseCoin": "BTC",
1796
- # "quoteCoin": "USDT",
1797
- # "buyLimitPriceRatio": "0.01",
1798
- # "sellLimitPriceRatio": "0.01",
1799
- # "feeRateUpRatio": "0.005",
1800
- # "makerFeeRate": "0.0002",
1801
- # "takerFeeRate": "0.0006",
1802
- # "openCostUpRatio": "0.01",
1803
- # "supportMarginCoins": ["USDT"],
1804
- # "minTradeNum": "0.001",
1805
- # "priceEndStep": "1",
1806
- # "volumePlace": "3",
1807
- # "pricePlace": "1",
1808
- # "sizeMultiplier": "0.001",
1809
- # "symbolType": "perpetual",
1810
- # "minTradeUSDT": "5",
1811
- # "maxSymbolOrderNum": "200",
1812
- # "maxProductOrderNum": "400",
1813
- # "maxPositionNum": "150",
1814
- # "symbolStatus": "normal",
1815
- # "offTime": "-1",
1816
- # "limitOpenTime": "-1",
1817
- # "deliveryTime": "",
1818
- # "deliveryStartTime": "",
1819
- # "deliveryPeriod": "",
1820
- # "launchTime": "",
1821
- # "fundInterval": "8",
1822
- # "minLever": "1",
1823
- # "maxLever": "125",
1824
- # "posLimit": "0.05",
1825
- # "maintainTime": ""
1826
- # },
1827
- # ]
1828
- # }
1829
- #
1830
- data = self.safe_value(response, 'data', [])
1831
- return self.parse_markets(data)
1832
-
1833
1789
  def fetch_currencies(self, params={}) -> Currencies:
1834
1790
  """
1835
1791
  fetches all available currencies on an exchange
@@ -8250,6 +8206,9 @@ class bitget(Exchange, ImplicitAPI):
8250
8206
  raise ExchangeError(feedback) # unknown message
8251
8207
  return None
8252
8208
 
8209
+ def nonce(self):
8210
+ return self.milliseconds() - self.options['timeDifference']
8211
+
8253
8212
  def sign(self, path, api=[], method='GET', params={}, headers=None, body=None):
8254
8213
  signed = api[0] == 'private'
8255
8214
  endpoint = api[1]
@@ -8265,7 +8224,7 @@ class bitget(Exchange, ImplicitAPI):
8265
8224
  url = url + '?' + self.urlencode(query)
8266
8225
  if signed:
8267
8226
  self.check_required_credentials()
8268
- timestamp = str(self.milliseconds())
8227
+ timestamp = str(self.nonce())
8269
8228
  auth = timestamp + method + payload
8270
8229
  if method == 'POST':
8271
8230
  body = self.json(params)