ccxt 4.2.79__py2.py3-none-any.whl → 4.2.81__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.

Potentially problematic release.


This version of ccxt might be problematic. Click here for more details.

ccxt/gate.py CHANGED
@@ -6,7 +6,7 @@
6
6
  from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.gate import ImplicitAPI
8
8
  import hashlib
9
- from ccxt.base.types import Balances, Currency, FundingHistory, Greeks, Int, Leverage, Leverages, Market, MarketInterface, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
9
+ from ccxt.base.types import Balances, Currency, FundingHistory, Greeks, Int, Leverage, Leverages, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
10
10
  from typing import List
11
11
  from ccxt.base.errors import ExchangeError
12
12
  from ccxt.base.errors import PermissionDenied
@@ -150,6 +150,8 @@ class gate(Exchange, ImplicitAPI):
150
150
  'fetchOpenInterest': False,
151
151
  'fetchOpenInterestHistory': True,
152
152
  'fetchOpenOrders': True,
153
+ 'fetchOption': True,
154
+ 'fetchOptionChain': True,
153
155
  'fetchOrder': True,
154
156
  'fetchOrderBook': True,
155
157
  'fetchPosition': True,
@@ -3959,8 +3961,13 @@ class gate(Exchange, ImplicitAPI):
3959
3961
  'account': account,
3960
3962
  }
3961
3963
  if amount is not None:
3962
- amountKey = 'amount' if (market['spot']) else 'size'
3963
- request[amountKey] = self.amount_to_precision(symbol, amount)
3964
+ if market['spot']:
3965
+ request['amount'] = self.amount_to_precision(symbol, amount)
3966
+ else:
3967
+ if side == 'sell':
3968
+ request['size'] = Precise.string_neg(self.amount_to_precision(symbol, amount))
3969
+ else:
3970
+ request['size'] = self.amount_to_precision(symbol, amount)
3964
3971
  if price is not None:
3965
3972
  request['price'] = self.price_to_precision(symbol, price)
3966
3973
  response = None
@@ -4690,8 +4697,8 @@ class gate(Exchange, ImplicitAPI):
4690
4697
  """
4691
4698
  self.load_markets()
4692
4699
  market = None if (symbol is None) else self.market(symbol)
4693
- stop = self.safe_value(params, 'stop')
4694
- params = self.omit(params, 'stop')
4700
+ stop = self.safe_bool_2(params, 'stop', 'trigger')
4701
+ params = self.omit(params, ['stop', 'trigger'])
4695
4702
  type, query = self.handle_market_type_and_params('cancelAllOrders', market, params)
4696
4703
  request, requestParams = self.multi_order_spot_prepare_request(market, stop, query) if (type == 'spot') else self.prepare_request(market, type, query)
4697
4704
  response = None
@@ -4985,7 +4992,7 @@ class gate(Exchange, ImplicitAPI):
4985
4992
  'unrealizedPnl': self.parse_number(unrealisedPnl),
4986
4993
  'realizedPnl': self.safe_number(position, 'realised_pnl'),
4987
4994
  'contracts': self.parse_number(Precise.string_abs(size)),
4988
- 'contractSize': self.safe_value(market, 'contractSize'),
4995
+ 'contractSize': self.safe_number(market, 'contractSize'),
4989
4996
  # 'realisedPnl': position['realised_pnl'],
4990
4997
  'marginRatio': None,
4991
4998
  'liquidationPrice': self.safe_number(position, 'liq_price'),
@@ -6682,6 +6689,186 @@ class gate(Exchange, ImplicitAPI):
6682
6689
  'shortLeverage': leverageValue,
6683
6690
  }
6684
6691
 
6692
+ def fetch_option(self, symbol: str, params={}) -> Option:
6693
+ """
6694
+ fetches option data that is commonly found in an option chain
6695
+ :see: https://www.gate.io/docs/developers/apiv4/en/#query-specified-contract-detail
6696
+ :param str symbol: unified market symbol
6697
+ :param dict [params]: extra parameters specific to the exchange API endpoint
6698
+ :returns dict: an `option chain structure <https://docs.ccxt.com/#/?id=option-chain-structure>`
6699
+ """
6700
+ self.load_markets()
6701
+ market = self.market(symbol)
6702
+ request = {
6703
+ 'contract': market['id'],
6704
+ }
6705
+ response = self.publicOptionsGetContractsContract(self.extend(request, params))
6706
+ #
6707
+ # {
6708
+ # "is_active": True,
6709
+ # "mark_price_round": "0.01",
6710
+ # "settle_fee_rate": "0.00015",
6711
+ # "bid1_size": 30,
6712
+ # "taker_fee_rate": "0.0003",
6713
+ # "price_limit_fee_rate": "0.1",
6714
+ # "order_price_round": "0.1",
6715
+ # "tag": "month",
6716
+ # "ref_rebate_rate": "0",
6717
+ # "name": "ETH_USDT-20240628-4500-C",
6718
+ # "strike_price": "4500",
6719
+ # "ask1_price": "280.5",
6720
+ # "ref_discount_rate": "0",
6721
+ # "order_price_deviate": "0.2",
6722
+ # "ask1_size": -19,
6723
+ # "mark_price_down": "155.45",
6724
+ # "orderbook_id": 11724695,
6725
+ # "is_call": True,
6726
+ # "last_price": "188.7",
6727
+ # "mark_price": "274.26",
6728
+ # "underlying": "ETH_USDT",
6729
+ # "create_time": 1688024882,
6730
+ # "settle_limit_fee_rate": "0.1",
6731
+ # "orders_limit": 10,
6732
+ # "mark_price_up": "403.83",
6733
+ # "position_size": 80,
6734
+ # "order_size_max": 10000,
6735
+ # "position_limit": 100000,
6736
+ # "multiplier": "0.01",
6737
+ # "order_size_min": 1,
6738
+ # "trade_size": 229,
6739
+ # "underlying_price": "3326.6",
6740
+ # "maker_fee_rate": "0.0003",
6741
+ # "expiration_time": 1719561600,
6742
+ # "trade_id": 15,
6743
+ # "bid1_price": "269.3"
6744
+ # }
6745
+ #
6746
+ return self.parse_option(response, None, market)
6747
+
6748
+ def fetch_option_chain(self, code: str, params={}) -> OptionChain:
6749
+ """
6750
+ fetches data for an underlying asset that is commonly found in an option chain
6751
+ :see: https://www.gate.io/docs/developers/apiv4/en/#list-all-the-contracts-with-specified-underlying-and-expiration-time
6752
+ :param str currency: base currency to fetch an option chain for
6753
+ :param dict [params]: extra parameters specific to the exchange API endpoint
6754
+ :param str [params.underlying]: the underlying asset, can be obtained from fetchUnderlyingAssets()
6755
+ :param int [params.expiration]: unix timestamp of the expiration time
6756
+ :returns dict: a list of `option chain structures <https://docs.ccxt.com/#/?id=option-chain-structure>`
6757
+ """
6758
+ self.load_markets()
6759
+ currency = self.currency(code)
6760
+ request = {
6761
+ 'underlying': currency['code'] + '_USDT',
6762
+ }
6763
+ response = self.publicOptionsGetContracts(self.extend(request, params))
6764
+ #
6765
+ # [
6766
+ # {
6767
+ # "is_active": True,
6768
+ # "mark_price_round": "0.1",
6769
+ # "settle_fee_rate": "0.00015",
6770
+ # "bid1_size": 434,
6771
+ # "taker_fee_rate": "0.0003",
6772
+ # "price_limit_fee_rate": "0.1",
6773
+ # "order_price_round": "1",
6774
+ # "tag": "day",
6775
+ # "ref_rebate_rate": "0",
6776
+ # "name": "BTC_USDT-20240324-63500-P",
6777
+ # "strike_price": "63500",
6778
+ # "ask1_price": "387",
6779
+ # "ref_discount_rate": "0",
6780
+ # "order_price_deviate": "0.15",
6781
+ # "ask1_size": -454,
6782
+ # "mark_price_down": "124.3",
6783
+ # "orderbook_id": 29600,
6784
+ # "is_call": False,
6785
+ # "last_price": "0",
6786
+ # "mark_price": "366.6",
6787
+ # "underlying": "BTC_USDT",
6788
+ # "create_time": 1711118829,
6789
+ # "settle_limit_fee_rate": "0.1",
6790
+ # "orders_limit": 10,
6791
+ # "mark_price_up": "630",
6792
+ # "position_size": 0,
6793
+ # "order_size_max": 10000,
6794
+ # "position_limit": 10000,
6795
+ # "multiplier": "0.01",
6796
+ # "order_size_min": 1,
6797
+ # "trade_size": 0,
6798
+ # "underlying_price": "64084.65",
6799
+ # "maker_fee_rate": "0.0003",
6800
+ # "expiration_time": 1711267200,
6801
+ # "trade_id": 0,
6802
+ # "bid1_price": "307"
6803
+ # },
6804
+ # ]
6805
+ #
6806
+ return self.parse_option_chain(response, None, 'name')
6807
+
6808
+ def parse_option(self, chain, currency: Currency = None, market: Market = None):
6809
+ #
6810
+ # {
6811
+ # "is_active": True,
6812
+ # "mark_price_round": "0.1",
6813
+ # "settle_fee_rate": "0.00015",
6814
+ # "bid1_size": 434,
6815
+ # "taker_fee_rate": "0.0003",
6816
+ # "price_limit_fee_rate": "0.1",
6817
+ # "order_price_round": "1",
6818
+ # "tag": "day",
6819
+ # "ref_rebate_rate": "0",
6820
+ # "name": "BTC_USDT-20240324-63500-P",
6821
+ # "strike_price": "63500",
6822
+ # "ask1_price": "387",
6823
+ # "ref_discount_rate": "0",
6824
+ # "order_price_deviate": "0.15",
6825
+ # "ask1_size": -454,
6826
+ # "mark_price_down": "124.3",
6827
+ # "orderbook_id": 29600,
6828
+ # "is_call": False,
6829
+ # "last_price": "0",
6830
+ # "mark_price": "366.6",
6831
+ # "underlying": "BTC_USDT",
6832
+ # "create_time": 1711118829,
6833
+ # "settle_limit_fee_rate": "0.1",
6834
+ # "orders_limit": 10,
6835
+ # "mark_price_up": "630",
6836
+ # "position_size": 0,
6837
+ # "order_size_max": 10000,
6838
+ # "position_limit": 10000,
6839
+ # "multiplier": "0.01",
6840
+ # "order_size_min": 1,
6841
+ # "trade_size": 0,
6842
+ # "underlying_price": "64084.65",
6843
+ # "maker_fee_rate": "0.0003",
6844
+ # "expiration_time": 1711267200,
6845
+ # "trade_id": 0,
6846
+ # "bid1_price": "307"
6847
+ # }
6848
+ #
6849
+ marketId = self.safe_string(chain, 'name')
6850
+ market = self.safe_market(marketId, market)
6851
+ timestamp = self.safe_timestamp(chain, 'create_time')
6852
+ return {
6853
+ 'info': chain,
6854
+ 'currency': None,
6855
+ 'symbol': market['symbol'],
6856
+ 'timestamp': timestamp,
6857
+ 'datetime': self.iso8601(timestamp),
6858
+ 'impliedVolatility': None,
6859
+ 'openInterest': None,
6860
+ 'bidPrice': self.safe_number(chain, 'bid1_price'),
6861
+ 'askPrice': self.safe_number(chain, 'ask1_price'),
6862
+ 'midPrice': None,
6863
+ 'markPrice': self.safe_number(chain, 'mark_price'),
6864
+ 'lastPrice': self.safe_number(chain, 'last_price'),
6865
+ 'underlyingPrice': self.safe_number(chain, 'underlying_price'),
6866
+ 'change': None,
6867
+ 'percentage': None,
6868
+ 'baseVolume': None,
6869
+ 'quoteVolume': None,
6870
+ }
6871
+
6685
6872
  def handle_errors(self, code, reason, url, method, headers, body, response, requestHeaders, requestBody):
6686
6873
  if response is None:
6687
6874
  return None
ccxt/hyperliquid.py CHANGED
@@ -754,6 +754,8 @@ class hyperliquid(Exchange, ImplicitAPI):
754
754
  """
755
755
  self.load_markets()
756
756
  market = self.market(symbol)
757
+ vaultAddress = self.safe_string(params, 'vaultAddress')
758
+ params = self.omit(params, 'vaultAddress')
757
759
  symbol = market['symbol']
758
760
  order = {
759
761
  'symbol': symbol,
@@ -763,7 +765,10 @@ class hyperliquid(Exchange, ImplicitAPI):
763
765
  'price': price,
764
766
  'params': params,
765
767
  }
766
- response = self.create_orders([order], params)
768
+ globalParams = {}
769
+ if vaultAddress is not None:
770
+ globalParams['vaultAddress'] = vaultAddress
771
+ response = self.create_orders([order], globalParams)
767
772
  first = self.safe_dict(response, 0)
768
773
  return first
769
774
 
@@ -807,7 +812,6 @@ class hyperliquid(Exchange, ImplicitAPI):
807
812
  amount = self.safe_string(rawOrder, 'amount')
808
813
  price = self.safe_string(rawOrder, 'price')
809
814
  orderParams = self.safe_dict(rawOrder, 'params', {})
810
- orderParams = self.extend(params, orderParams)
811
815
  clientOrderId = self.safe_string_2(orderParams, 'clientOrderId', 'client_id')
812
816
  slippage = self.safe_string(orderParams, 'slippage', defaultSlippage)
813
817
  defaultTimeInForce = 'ioc' if (isMarket) else 'gtc'
@@ -847,6 +851,7 @@ class hyperliquid(Exchange, ImplicitAPI):
847
851
  orderType['limit'] = {
848
852
  'tif': timeInForce,
849
853
  }
854
+ orderParams = self.omit(orderParams, ['clientOrderId', 'slippage', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice', 'timeInForce', 'client_id'])
850
855
  orderObj = {
851
856
  'a': self.parse_to_int(market['baseId']),
852
857
  'b': isBuy,
@@ -858,8 +863,8 @@ class hyperliquid(Exchange, ImplicitAPI):
858
863
  }
859
864
  if clientOrderId is not None:
860
865
  orderObj['c'] = clientOrderId
861
- orderReq.append(orderObj)
862
- vaultAddress = self.safe_string(params, 'vaultAddress')
866
+ orderReq.append(self.extend(orderObj, orderParams))
867
+ vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
863
868
  orderAction = {
864
869
  'type': 'order',
865
870
  'orders': orderReq,
@@ -875,6 +880,9 @@ class hyperliquid(Exchange, ImplicitAPI):
875
880
  'signature': signature,
876
881
  # 'vaultAddress': vaultAddress,
877
882
  }
883
+ if vaultAddress is not None:
884
+ params = self.omit(params, 'vaultAddress')
885
+ request['vaultAddress'] = vaultAddress
878
886
  response = self.privatePostExchange(self.extend(request, params))
879
887
  #
880
888
  # {
@@ -957,10 +965,13 @@ class hyperliquid(Exchange, ImplicitAPI):
957
965
  'o': self.parse_to_numeric(ids[i]),
958
966
  })
959
967
  cancelAction['cancels'] = cancelReq
960
- vaultAddress = self.safe_string(params, 'vaultAddress')
968
+ vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
961
969
  signature = self.sign_l1_action(cancelAction, nonce, vaultAddress)
962
970
  request['action'] = cancelAction
963
971
  request['signature'] = signature
972
+ if vaultAddress is not None:
973
+ params = self.omit(params, 'vaultAddress')
974
+ request['vaultAddress'] = vaultAddress
964
975
  response = self.privatePostExchange(self.extend(request, params))
965
976
  #
966
977
  # {
@@ -1066,7 +1077,7 @@ class hyperliquid(Exchange, ImplicitAPI):
1066
1077
  'type': 'batchModify',
1067
1078
  'modifies': [modifyReq],
1068
1079
  }
1069
- vaultAddress = self.safe_string(params, 'vaultAddress')
1080
+ vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
1070
1081
  signature = self.sign_l1_action(modifyAction, nonce, vaultAddress)
1071
1082
  request = {
1072
1083
  'action': modifyAction,
@@ -1074,6 +1085,9 @@ class hyperliquid(Exchange, ImplicitAPI):
1074
1085
  'signature': signature,
1075
1086
  # 'vaultAddress': vaultAddress,
1076
1087
  }
1088
+ if vaultAddress is not None:
1089
+ params = self.omit(params, 'vaultAddress')
1090
+ request['vaultAddress'] = vaultAddress
1077
1091
  response = self.privatePostExchange(self.extend(request, params))
1078
1092
  #
1079
1093
  # {
@@ -1643,7 +1657,7 @@ class hyperliquid(Exchange, ImplicitAPI):
1643
1657
  'isolated': isIsolated,
1644
1658
  'hedged': None,
1645
1659
  'side': side,
1646
- 'contracts': self.parse_number(quantity),
1660
+ 'contracts': self.safe_number(entry, 'szi'),
1647
1661
  'contractSize': None,
1648
1662
  'entryPrice': self.safe_number(entry, 'entryPx'),
1649
1663
  'markPrice': None,
@@ -1687,6 +1701,10 @@ class hyperliquid(Exchange, ImplicitAPI):
1687
1701
  'leverage': leverage,
1688
1702
  }
1689
1703
  vaultAddress = self.safe_string(params, 'vaultAddress')
1704
+ if vaultAddress is not None:
1705
+ params = self.omit(params, 'vaultAddress')
1706
+ if vaultAddress.startswith('0x'):
1707
+ vaultAddress = vaultAddress.replace('0x', '')
1690
1708
  signature = self.sign_l1_action(updateAction, nonce, vaultAddress)
1691
1709
  request = {
1692
1710
  'action': updateAction,
@@ -1694,6 +1712,8 @@ class hyperliquid(Exchange, ImplicitAPI):
1694
1712
  'signature': signature,
1695
1713
  # 'vaultAddress': vaultAddress,
1696
1714
  }
1715
+ if vaultAddress is not None:
1716
+ request['vaultAddress'] = vaultAddress
1697
1717
  response = self.privatePostExchange(self.extend(request, params))
1698
1718
  #
1699
1719
  # {
@@ -1729,7 +1749,7 @@ class hyperliquid(Exchange, ImplicitAPI):
1729
1749
  'isCross': isCross,
1730
1750
  'leverage': leverage,
1731
1751
  }
1732
- vaultAddress = self.safe_string(params, 'vaultAddress')
1752
+ vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
1733
1753
  signature = self.sign_l1_action(updateAction, nonce, vaultAddress)
1734
1754
  request = {
1735
1755
  'action': updateAction,
@@ -1737,6 +1757,9 @@ class hyperliquid(Exchange, ImplicitAPI):
1737
1757
  'signature': signature,
1738
1758
  # 'vaultAddress': vaultAddress,
1739
1759
  }
1760
+ if vaultAddress is not None:
1761
+ params = self.omit(params, 'vaultAddress')
1762
+ request['vaultAddress'] = vaultAddress
1740
1763
  response = self.privatePostExchange(self.extend(request, params))
1741
1764
  #
1742
1765
  # {
@@ -1784,7 +1807,7 @@ class hyperliquid(Exchange, ImplicitAPI):
1784
1807
  'isBuy': True,
1785
1808
  'ntli': sz,
1786
1809
  }
1787
- vaultAddress = self.safe_string(params, 'vaultAddress')
1810
+ vaultAddress = self.format_vault_address(self.safe_string(params, 'vaultAddress'))
1788
1811
  signature = self.sign_l1_action(updateAction, nonce, vaultAddress)
1789
1812
  request = {
1790
1813
  'action': updateAction,
@@ -1792,6 +1815,9 @@ class hyperliquid(Exchange, ImplicitAPI):
1792
1815
  'signature': signature,
1793
1816
  # 'vaultAddress': vaultAddress,
1794
1817
  }
1818
+ if vaultAddress is not None:
1819
+ params = self.omit(params, 'vaultAddress')
1820
+ request['vaultAddress'] = vaultAddress
1795
1821
  response = self.privatePostExchange(self.extend(request, params))
1796
1822
  #
1797
1823
  # {
@@ -1882,6 +1908,13 @@ class hyperliquid(Exchange, ImplicitAPI):
1882
1908
  response = self.privatePostExchange(self.extend(request, params))
1883
1909
  return response
1884
1910
 
1911
+ def format_vault_address(self, address: Str = None):
1912
+ if address is None:
1913
+ return None
1914
+ if address.startswith('0x'):
1915
+ return address.replace('0x', '')
1916
+ return address
1917
+
1885
1918
  def handle_public_address(self, methodName: str, params: dict):
1886
1919
  userAux = None
1887
1920
  userAux, params = self.handle_option_and_params(params, methodName, 'user')
ccxt/mexc.py CHANGED
@@ -899,8 +899,8 @@ class mexc(Exchange, ImplicitAPI):
899
899
  '30032': InvalidOrder, # Cannot exceed the maximum position
900
900
  '30041': InvalidOrder, # current order type can not place order
901
901
  '60005': ExchangeError, # your account is abnormal
902
- '700001': AuthenticationError, # API-key format invalid
903
- '700002': AuthenticationError, # Signature for self request is not valid
902
+ '700001': AuthenticationError, # {"code":700002,"msg":"Signature for self request is not valid."} # same message for expired API keys
903
+ '700002': AuthenticationError, # Signature for self request is not valid # or the API secret is incorrect
904
904
  '700004': BadRequest, # Param 'origClientOrderId' or 'orderId' must be sent, but both were empty/null
905
905
  '700005': InvalidNonce, # recvWindow must less than 60000
906
906
  '700006': BadRequest, # IP non white list
ccxt/okx.py CHANGED
@@ -1833,16 +1833,27 @@ class okx(Exchange, ImplicitAPI):
1833
1833
  first = self.safe_value(data, 0, {})
1834
1834
  return self.parse_ticker(first, market)
1835
1835
 
1836
- def fetch_tickers_by_type(self, type, symbols: Strings = None, params={}):
1836
+ def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
1837
+ """
1838
+ fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1839
+ :see: https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-tickers
1840
+ :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1841
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1842
+ :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
1843
+ """
1837
1844
  self.load_markets()
1845
+ symbols = self.market_symbols(symbols)
1846
+ market = self.get_market_from_symbols(symbols)
1847
+ marketType = None
1848
+ marketType, params = self.handle_market_type_and_params('fetchTickers', market, params)
1838
1849
  request = {
1839
- 'instType': self.convert_to_instrument_type(type),
1850
+ 'instType': self.convert_to_instrument_type(marketType),
1840
1851
  }
1841
- if type == 'option':
1852
+ if marketType == 'option':
1842
1853
  defaultUnderlying = self.safe_value(self.options, 'defaultUnderlying', 'BTC-USD')
1843
1854
  currencyId = self.safe_string_2(params, 'uly', 'marketId', defaultUnderlying)
1844
1855
  if currencyId is None:
1845
- raise ArgumentsRequired(self.id + ' fetchTickersByType() requires an underlying uly or marketId parameter for options markets')
1856
+ raise ArgumentsRequired(self.id + ' fetchTickers() requires an underlying uly or marketId parameter for options markets')
1846
1857
  else:
1847
1858
  request['uly'] = currencyId
1848
1859
  response = self.publicGetMarketTickers(self.extend(request, params))
@@ -1872,26 +1883,9 @@ class okx(Exchange, ImplicitAPI):
1872
1883
  # ]
1873
1884
  # }
1874
1885
  #
1875
- tickers = self.safe_value(response, 'data', [])
1886
+ tickers = self.safe_list(response, 'data', [])
1876
1887
  return self.parse_tickers(tickers, symbols)
1877
1888
 
1878
- def fetch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
1879
- """
1880
- fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1881
- :see: https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-tickers
1882
- :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1883
- :param dict [params]: extra parameters specific to the exchange API endpoint
1884
- :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
1885
- """
1886
- self.load_markets()
1887
- symbols = self.market_symbols(symbols)
1888
- first = self.safe_string(symbols, 0)
1889
- market = None
1890
- if first is not None:
1891
- market = self.market(first)
1892
- type, query = self.handle_market_type_and_params('fetchTickers', market, params)
1893
- return self.fetch_tickers_by_type(type, symbols, query)
1894
-
1895
1889
  def parse_trade(self, trade, market: Market = None) -> Trade:
1896
1890
  #
1897
1891
  # public fetchTrades
@@ -4438,18 +4432,7 @@ class okx(Exchange, ImplicitAPI):
4438
4432
  if fee is None:
4439
4433
  raise ArgumentsRequired(self.id + ' withdraw() requires a "fee" string parameter, network transaction fee must be ≥ 0. Withdrawals to OKCoin or OKX are fee-free, please set "0". Withdrawing to external digital asset address requires network transaction fee.')
4440
4434
  request['fee'] = self.number_to_string(fee) # withdrawals to OKCoin or OKX are fee-free, please set 0
4441
- if 'password' in params:
4442
- request['pwd'] = params['password']
4443
- elif 'pwd' in params:
4444
- request['pwd'] = params['pwd']
4445
- else:
4446
- options = self.safe_value(self.options, 'withdraw', {})
4447
- password = self.safe_string_2(options, 'password', 'pwd')
4448
- if password is not None:
4449
- request['pwd'] = password
4450
- query = self.omit(params, ['fee', 'password', 'pwd'])
4451
- if not ('pwd' in request):
4452
- raise ExchangeError(self.id + ' withdraw() requires a password parameter or a pwd parameter, it must be the funding password, not the API passphrase')
4435
+ query = self.omit(params, ['fee'])
4453
4436
  response = self.privatePostAssetWithdrawal(self.extend(request, query))
4454
4437
  #
4455
4438
  # {
ccxt/pro/__init__.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # ----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.2.79'
7
+ __version__ = '4.2.81'
8
8
 
9
9
  # ----------------------------------------------------------------------------
10
10
 
ccxt/pro/binance.py CHANGED
@@ -89,7 +89,7 @@ class binance(ccxt.async_support.binance):
89
89
  'future': 200,
90
90
  'delivery': 200,
91
91
  },
92
- 'streamBySubscriptionsHash': {},
92
+ 'streamBySubscriptionsHash': self.create_safe_dictionary(),
93
93
  'streamIndex': -1,
94
94
  # get updates every 1000ms or 100ms
95
95
  # or every 0ms in real-time for futures
@@ -97,7 +97,7 @@ class binance(ccxt.async_support.binance):
97
97
  'tradesLimit': 1000,
98
98
  'ordersLimit': 1000,
99
99
  'OHLCVLimit': 1000,
100
- 'requestId': {},
100
+ 'requestId': self.create_safe_dictionary(),
101
101
  'watchOrderBookLimit': 1000, # default limit
102
102
  'watchTrades': {
103
103
  'name': 'trade', # 'trade' or 'aggTrade'
@@ -131,14 +131,14 @@ class binance(ccxt.async_support.binance):
131
131
  })
132
132
 
133
133
  def request_id(self, url):
134
- options = self.safe_value(self.options, 'requestId', {})
134
+ options = self.safe_dict(self.options, 'requestId', self.create_safe_dictionary())
135
135
  previousValue = self.safe_integer(options, url, 0)
136
136
  newValue = self.sum(previousValue, 1)
137
137
  self.options['requestId'][url] = newValue
138
138
  return newValue
139
139
 
140
140
  def stream(self, type, subscriptionHash, numSubscriptions=1):
141
- streamBySubscriptionsHash = self.safe_value(self.options, 'streamBySubscriptionsHash', {})
141
+ streamBySubscriptionsHash = self.safe_dict(self.options, 'streamBySubscriptionsHash', self.create_safe_dictionary())
142
142
  stream = self.safe_string(streamBySubscriptionsHash, subscriptionHash)
143
143
  if stream is None:
144
144
  streamIndex = self.safe_integer(self.options, 'streamIndex', -1)
@@ -151,7 +151,7 @@ class binance(ccxt.async_support.binance):
151
151
  self.options['streamBySubscriptionsHash'][subscriptionHash] = stream
152
152
  subscriptionsByStreams = self.safe_value(self.options, 'numSubscriptionsByStream')
153
153
  if subscriptionsByStreams is None:
154
- self.options['numSubscriptionsByStream'] = {}
154
+ self.options['numSubscriptionsByStream'] = self.create_safe_dictionary()
155
155
  subscriptionsByStream = self.safe_integer(self.options['numSubscriptionsByStream'], stream, 0)
156
156
  newNumSubscriptions = subscriptionsByStream + numSubscriptions
157
157
  subscriptionLimitByStream = self.safe_integer(self.options['subscriptionLimitByStream'], type, 200)
ccxt/pro/bitopro.py CHANGED
@@ -364,7 +364,8 @@ class bitopro(ccxt.async_support.bitopro):
364
364
  },
365
365
  },
366
366
  }
367
- self.options = self.extend(defaultOptions, self.options)
367
+ # self.options = self.extend(defaultOptions, self.options)
368
+ self.extend_exchange_options(defaultOptions)
368
369
  originalHeaders = self.options['ws']['options']['headers']
369
370
  headers = {
370
371
  'X-BITOPRO-API': 'ccxt',
ccxt/pro/gemini.py CHANGED
@@ -6,7 +6,7 @@
6
6
  import ccxt.async_support
7
7
  from ccxt.async_support.base.ws.cache import ArrayCache, ArrayCacheBySymbolById, ArrayCacheByTimestamp
8
8
  import hashlib
9
- from ccxt.base.types import Int, Order, OrderBook, Str, Tickers, Trade
9
+ from ccxt.base.types import Int, Order, OrderBook, Str, Strings, Tickers, Trade
10
10
  from ccxt.async_support.base.ws.client import Client
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
@@ -393,7 +393,7 @@ class gemini(ccxt.async_support.gemini):
393
393
  orderbook = await self.helper_for_watch_multiple_construct('orderbook', symbols, params)
394
394
  return orderbook.limit()
395
395
 
396
- async def watch_bids_asks(self, symbols: List[str], limit: Int = None, params={}) -> Tickers:
396
+ async def watch_bids_asks(self, symbols: Strings = None, params={}) -> Tickers:
397
397
  """
398
398
  watches best bid & ask for symbols
399
399
  :see: https://docs.gemini.com/websocket-api/#multi-market-data
@@ -851,7 +851,8 @@ class gemini(ccxt.async_support.gemini):
851
851
  },
852
852
  },
853
853
  }
854
- self.options = self.extend(defaultOptions, self.options)
854
+ # self.options = self.extend(defaultOptions, self.options)
855
+ self.extend_exchange_options(defaultOptions)
855
856
  originalHeaders = self.options['ws']['options']['headers']
856
857
  headers = {
857
858
  'X-GEMINI-APIKEY': self.apiKey,
ccxt/pro/phemex.py CHANGED
@@ -27,6 +27,10 @@ class phemex(ccxt.async_support.phemex):
27
27
  'watchOrderBook': True,
28
28
  'watchOHLCV': True,
29
29
  'watchPositions': None, # TODO
30
+ # mutli-endpoints are not supported: https://github.com/ccxt/ccxt/pull/21490
31
+ 'watchOrderBookForSymbols': False,
32
+ 'watchTradesForSymbols': False,
33
+ 'watchOHLCVForSymbols': False,
30
34
  },
31
35
  'urls': {
32
36
  'test': {
@@ -536,9 +540,10 @@ class phemex(ccxt.async_support.phemex):
536
540
 
537
541
  async def watch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
538
542
  """
543
+ :see: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md#subscribe-orderbook
539
544
  :see: https://github.com/phemex/phemex-api-docs/blob/master/Public-Hedged-Perpetual-API.md#subscribe-orderbook-for-new-model
540
545
  :see: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#subscribe-30-levels-orderbook
541
- :see: https://github.com/phemex/phemex-api-docs/blob/master/Public-Spot-API-en.md#subscribe-orderbook
546
+ :see: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#subscribe-full-orderbook
542
547
  watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
543
548
  :param str symbol: unified symbol of the market to fetch the order book for
544
549
  :param int [limit]: the maximum amount of order book entries to return
@@ -21,8 +21,9 @@ def test_ohlcv(exchange, skipped_properties, method, entry, symbol, now):
21
21
  test_shared_methods.assert_timestamp_and_datetime(exchange, skipped_properties, method, entry, now, 0)
22
22
  log_text = test_shared_methods.log_template(exchange, method, entry)
23
23
  #
24
- length = len(entry)
25
- assert length >= 6, 'ohlcv array length should be >= 6;' + log_text
24
+ assert len(entry) >= 6, 'ohlcv array length should be >= 6;' + log_text
25
+ if not ('roundTimestamp' in skipped_properties):
26
+ test_shared_methods.assert_round_minute_timestamp(exchange, skipped_properties, method, entry, 0)
26
27
  high = exchange.safe_string(entry, 2)
27
28
  low = exchange.safe_string(entry, 3)
28
29
  test_shared_methods.assert_less_or_equal(exchange, skipped_properties, method, entry, '1', high)
@@ -343,3 +343,11 @@ def assert_non_emtpy_array(exchange, skipped_properties, method, entry, hint=Non
343
343
  if not ('emptyResponse' in skipped_properties):
344
344
  return
345
345
  assert len(entry) > 0, 'response is expected to be a non-empty array' + log_text + ' (add \"emptyResponse\" in skip-tests.json to skip this check)'
346
+
347
+
348
+ def assert_round_minute_timestamp(exchange, skipped_properties, method, entry, key):
349
+ if key in skipped_properties:
350
+ return
351
+ log_text = log_template(exchange, method, entry)
352
+ ts = exchange.safe_string(entry, key)
353
+ assert Precise.string_mod(ts, '60000') == '0', 'timestamp should be a multiple of 60 seconds (1 minute)' + log_text