ccxt 4.2.39__py2.py3-none-any.whl → 4.2.40__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/async_support/okx.py CHANGED
@@ -3462,10 +3462,8 @@ class okx(Exchange, ImplicitAPI):
3462
3462
  method = 'privateGetTradeOrdersAlgoPending'
3463
3463
  if trailing:
3464
3464
  request['ordType'] = 'move_order_stop'
3465
- elif stop or (ordType in algoOrderTypes):
3466
- if stop:
3467
- if ordType is None:
3468
- raise ArgumentsRequired(self.id + ' fetchOpenOrders() requires an "ordType" string parameter, "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"')
3465
+ elif stop and (ordType is None):
3466
+ request['ordType'] = 'trigger'
3469
3467
  query = self.omit(params, ['method', 'stop', 'trigger', 'trailing'])
3470
3468
  response = None
3471
3469
  if method == 'privateGetTradeOrdersAlgoPending':
@@ -3753,7 +3751,7 @@ class okx(Exchange, ImplicitAPI):
3753
3751
  :param int [since]: the earliest time in ms to fetch orders for
3754
3752
  :param int [limit]: the maximum number of order structures to retrieve
3755
3753
  :param dict [params]: extra parameters specific to the exchange API endpoint
3756
- :param bool [params.stop]: True if fetching trigger or conditional orders
3754
+ :param bool [params.trigger]: True if fetching trigger or conditional orders
3757
3755
  :param str [params.ordType]: "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"
3758
3756
  :param str [params.algoId]: Algo ID "'433845797218942976'"
3759
3757
  :param int [params.until]: timestamp in ms to fetch orders for
@@ -3788,22 +3786,21 @@ class okx(Exchange, ImplicitAPI):
3788
3786
  request['instType'] = self.convert_to_instrument_type(type)
3789
3787
  if limit is not None:
3790
3788
  request['limit'] = limit # default 100, max 100
3791
- options = self.safe_value(self.options, 'fetchClosedOrders', {})
3792
- algoOrderTypes = self.safe_value(self.options, 'algoOrderTypes', {})
3789
+ options = self.safe_dict(self.options, 'fetchClosedOrders', {})
3790
+ algoOrderTypes = self.safe_dict(self.options, 'algoOrderTypes', {})
3793
3791
  defaultMethod = self.safe_string(options, 'method', 'privateGetTradeOrdersHistory')
3794
3792
  method = self.safe_string(params, 'method', defaultMethod)
3795
3793
  ordType = self.safe_string(params, 'ordType')
3796
- stop = self.safe_value_2(params, 'stop', 'trigger')
3794
+ stop = self.safe_bool_2(params, 'stop', 'trigger')
3797
3795
  trailing = self.safe_bool(params, 'trailing', False)
3798
3796
  if trailing or stop or (ordType in algoOrderTypes):
3799
3797
  method = 'privateGetTradeOrdersAlgoHistory'
3800
3798
  request['state'] = 'effective'
3801
3799
  if trailing:
3802
3800
  request['ordType'] = 'move_order_stop'
3803
- elif stop or (ordType in algoOrderTypes):
3804
- if stop:
3805
- if ordType is None:
3806
- raise ArgumentsRequired(self.id + ' fetchClosedOrders() requires an "ordType" string parameter, "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"')
3801
+ elif stop:
3802
+ if ordType is None:
3803
+ request['ordType'] = 'trigger'
3807
3804
  else:
3808
3805
  if since is not None:
3809
3806
  request['begin'] = since
@@ -50,6 +50,7 @@ class phemex(Exchange, ImplicitAPI):
50
50
  'addMargin': False,
51
51
  'cancelAllOrders': True,
52
52
  'cancelOrder': True,
53
+ 'closePosition': False,
53
54
  'createOrder': True,
54
55
  'createReduceOnlyOrder': True,
55
56
  'createStopLimitOrder': True,
ccxt/base/exchange.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.2.39'
7
+ __version__ = '4.2.40'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
@@ -3255,15 +3255,15 @@ class Exchange(object):
3255
3255
  # if it was not defined by user, we should not set it from 'defaultNetworks', because handleNetworkCodeAndParams is for only request-side and thus we do not fill it with anything. We can only use 'defaultNetworks' after parsing response-side
3256
3256
  return [networkCodeInParams, params]
3257
3257
 
3258
- def default_network_code(self, currencyCode):
3258
+ def default_network_code(self, currencyCode: str):
3259
3259
  defaultNetworkCode = None
3260
- defaultNetworks = self.safe_value(self.options, 'defaultNetworks', {})
3260
+ defaultNetworks = self.safe_dict(self.options, 'defaultNetworks', {})
3261
3261
  if currencyCode in defaultNetworks:
3262
3262
  # if currency had set its network in "defaultNetworks", use it
3263
3263
  defaultNetworkCode = defaultNetworks[currencyCode]
3264
3264
  else:
3265
3265
  # otherwise, try to use the global-scope 'defaultNetwork' value(even if that network is not supported by currency, it doesn't make any problem, self will be just used "at first" if currency supports self network at all)
3266
- defaultNetwork = self.safe_value(self.options, 'defaultNetwork')
3266
+ defaultNetwork = self.safe_dict(self.options, 'defaultNetwork')
3267
3267
  if defaultNetwork is not None:
3268
3268
  defaultNetworkCode = defaultNetwork
3269
3269
  return defaultNetworkCode
@@ -3299,7 +3299,7 @@ class Exchange(object):
3299
3299
  chosenNetworkId = defaultNetworkId if (defaultNetworkId in indexedNetworkEntries) else availableNetworkIds[0]
3300
3300
  return chosenNetworkId
3301
3301
 
3302
- def safe_number_2(self, dictionary, key1, key2, d=None):
3302
+ def safe_number_2(self, dictionary: object, key1: IndexType, key2: IndexType, d=None):
3303
3303
  value = self.safe_string_2(dictionary, key1, key2)
3304
3304
  return self.parse_number(value, d)
3305
3305
 
@@ -3701,13 +3701,13 @@ class Exchange(object):
3701
3701
  raise NotSupported(self.id + ' fetchStatus() is not supported yet')
3702
3702
 
3703
3703
  def fetch_funding_fee(self, code: str, params={}):
3704
- warnOnFetchFundingFee = self.safe_value(self.options, 'warnOnFetchFundingFee', True)
3704
+ warnOnFetchFundingFee = self.safe_bool(self.options, 'warnOnFetchFundingFee', True)
3705
3705
  if warnOnFetchFundingFee:
3706
3706
  raise NotSupported(self.id + ' fetchFundingFee() method is deprecated, it will be removed in July 2022, please, use fetchTransactionFee() or set exchange.options["warnOnFetchFundingFee"] = False to suppress self warning')
3707
3707
  return self.fetch_transaction_fee(code, params)
3708
3708
 
3709
3709
  def fetch_funding_fees(self, codes: List[str] = None, params={}):
3710
- warnOnFetchFundingFees = self.safe_value(self.options, 'warnOnFetchFundingFees', True)
3710
+ warnOnFetchFundingFees = self.safe_bool(self.options, 'warnOnFetchFundingFees', True)
3711
3711
  if warnOnFetchFundingFees:
3712
3712
  raise NotSupported(self.id + ' fetchFundingFees() method is deprecated, it will be removed in July 2022. Please, use fetchTransactionFees() or set exchange.options["warnOnFetchFundingFees"] = False to suppress self warning')
3713
3713
  return self.fetch_transaction_fees(codes, params)
@@ -3750,12 +3750,12 @@ class Exchange(object):
3750
3750
  if not self.has['fetchBorrowRates']:
3751
3751
  raise NotSupported(self.id + ' fetchIsolatedBorrowRate() is not supported yet')
3752
3752
  borrowRates = self.fetchIsolatedBorrowRates(params)
3753
- rate = self.safe_value(borrowRates, symbol)
3753
+ rate = self.safe_dict(borrowRates, symbol)
3754
3754
  if rate is None:
3755
3755
  raise ExchangeError(self.id + ' fetchIsolatedBorrowRate() could not find the borrow rate for market symbol ' + symbol)
3756
3756
  return rate
3757
3757
 
3758
- def handle_option_and_params(self, params, methodName, optionName, defaultValue=None):
3758
+ def handle_option_and_params(self, params: object, methodName: str, optionName: str, defaultValue=None):
3759
3759
  # This method can be used to obtain method specific properties, i.e: self.handle_option_and_params(params, 'fetchPosition', 'marginMode', 'isolated')
3760
3760
  defaultOptionName = 'default' + self.capitalize(optionName) # we also need to check the 'defaultXyzWhatever'
3761
3761
  # check if params contain the key
@@ -3775,7 +3775,7 @@ class Exchange(object):
3775
3775
  value = value if (value is not None) else defaultValue
3776
3776
  return [value, params]
3777
3777
 
3778
- def handle_option_and_params_2(self, params, methodName, methodName2, optionName, defaultValue=None):
3778
+ def handle_option_and_params_2(self, params: object, methodName: str, methodName2: str, optionName: str, defaultValue=None):
3779
3779
  # This method can be used to obtain method specific properties, i.e: self.handle_option_and_params(params, 'fetchPosition', 'marginMode', 'isolated')
3780
3780
  defaultOptionName = 'default' + self.capitalize(optionName) # we also need to check the 'defaultXyzWhatever'
3781
3781
  # check if params contain the key
@@ -3795,14 +3795,14 @@ class Exchange(object):
3795
3795
  value = value if (value is not None) else defaultValue
3796
3796
  return [value, params]
3797
3797
 
3798
- def handle_option(self, methodName, optionName, defaultValue=None):
3798
+ def handle_option(self, methodName: str, optionName: str, defaultValue=None):
3799
3799
  # eslint-disable-next-line no-unused-vars
3800
3800
  result, empty = self.handle_option_and_params({}, methodName, optionName, defaultValue)
3801
3801
  return result
3802
3802
 
3803
3803
  def handle_market_type_and_params(self, methodName: str, market: Market = None, params={}):
3804
3804
  defaultType = self.safe_string_2(self.options, 'defaultType', 'type', 'spot')
3805
- methodOptions = self.safe_value(self.options, methodName)
3805
+ methodOptions = self.safe_dict(self.options, methodName)
3806
3806
  methodType = defaultType
3807
3807
  if methodOptions is not None:
3808
3808
  if isinstance(methodOptions, str):
@@ -3814,7 +3814,7 @@ class Exchange(object):
3814
3814
  params = self.omit(params, ['defaultType', 'type'])
3815
3815
  return [type, params]
3816
3816
 
3817
- def handle_sub_type_and_params(self, methodName, market=None, params={}, defaultValue=None):
3817
+ def handle_sub_type_and_params(self, methodName: str, market=None, params={}, defaultValue=None):
3818
3818
  subType = None
3819
3819
  # if set in params, it takes precedence
3820
3820
  subTypeInParams = self.safe_string_2(params, 'subType', 'defaultSubType')
@@ -3831,11 +3831,11 @@ class Exchange(object):
3831
3831
  subType = 'inverse'
3832
3832
  # if it was not defined in market object
3833
3833
  if subType is None:
3834
- values = self.handle_option_and_params(None, methodName, 'subType', defaultValue) # no need to re-test params here
3834
+ values = self.handle_option_and_params({}, methodName, 'subType', defaultValue) # no need to re-test params here
3835
3835
  subType = values[0]
3836
3836
  return [subType, params]
3837
3837
 
3838
- def handle_margin_mode_and_params(self, methodName, params={}, defaultValue=None):
3838
+ def handle_margin_mode_and_params(self, methodName: str, params={}, defaultValue=None):
3839
3839
  """
3840
3840
  * @ignore
3841
3841
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -3878,7 +3878,7 @@ class Exchange(object):
3878
3878
  market = self.market(symbol)
3879
3879
  symbol = market['symbol']
3880
3880
  tickers = self.fetch_tickers([symbol], params)
3881
- ticker = self.safe_value(tickers, symbol)
3881
+ ticker = self.safe_dict(tickers, symbol)
3882
3882
  if ticker is None:
3883
3883
  raise NullResponse(self.id + ' fetchTickers() could not find a ticker for ' + symbol)
3884
3884
  else:
@@ -3911,7 +3911,7 @@ class Exchange(object):
3911
3911
  return order['status']
3912
3912
 
3913
3913
  def fetch_unified_order(self, order, params={}):
3914
- return self.fetch_order(self.safe_value(order, 'id'), self.safe_value(order, 'symbol'), params)
3914
+ return self.fetch_order(self.safe_string(order, 'id'), self.safe_string(order, 'symbol'), params)
3915
3915
 
3916
3916
  def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: float = None, params={}):
3917
3917
  raise NotSupported(self.id + ' createOrder() is not supported yet')
@@ -4136,7 +4136,7 @@ class Exchange(object):
4136
4136
  raise NotSupported(self.id + ' cancelAllOrdersWs() is not supported yet')
4137
4137
 
4138
4138
  def cancel_unified_order(self, order, params={}):
4139
- return self.cancelOrder(self.safe_value(order, 'id'), self.safe_value(order, 'symbol'), params)
4139
+ return self.cancelOrder(self.safe_string(order, 'id'), self.safe_string(order, 'symbol'), params)
4140
4140
 
4141
4141
  def fetch_orders(self, symbol: str = None, since: Int = None, limit: Int = None, params={}):
4142
4142
  if self.has['fetchOpenOrders'] and self.has['fetchClosedOrders']:
@@ -4261,7 +4261,7 @@ class Exchange(object):
4261
4261
  return currency
4262
4262
  return self.safe_string(self.commonCurrencies, currency, currency)
4263
4263
 
4264
- def currency(self, code):
4264
+ def currency(self, code: str):
4265
4265
  if self.currencies is None:
4266
4266
  raise ExchangeError(self.id + ' currencies not loaded')
4267
4267
  if isinstance(code, str):
@@ -4570,7 +4570,7 @@ class Exchange(object):
4570
4570
  return result
4571
4571
 
4572
4572
  def is_trigger_order(self, params):
4573
- isTrigger = self.safe_value_2(params, 'trigger', 'stop')
4573
+ isTrigger = self.safe_bool_2(params, 'trigger', 'stop')
4574
4574
  if isTrigger:
4575
4575
  params = self.omit(params, ['trigger', 'stop'])
4576
4576
  return [isTrigger, params]
@@ -4584,7 +4584,7 @@ class Exchange(object):
4584
4584
  :returns boolean: True if a post only order, False otherwise
4585
4585
  """
4586
4586
  timeInForce = self.safe_string_upper(params, 'timeInForce')
4587
- postOnly = self.safe_value_2(params, 'postOnly', 'post_only', False)
4587
+ postOnly = self.safe_bool_2(params, 'postOnly', 'post_only', False)
4588
4588
  # we assume timeInForce is uppercase from safeStringUpper(params, 'timeInForce')
4589
4589
  ioc = timeInForce == 'IOC'
4590
4590
  fok = timeInForce == 'FOK'
@@ -4744,7 +4744,7 @@ class Exchange(object):
4744
4744
  :param str account: key for account name in self.options['accountsByType']
4745
4745
  :returns: the exchange specific account name or the isolated margin id for transfers
4746
4746
  """
4747
- accountsByType = self.safe_value(self.options, 'accountsByType', {})
4747
+ accountsByType = self.safe_dict(self.options, 'accountsByType', {})
4748
4748
  lowercaseAccount = account.lower()
4749
4749
  if lowercaseAccount in accountsByType:
4750
4750
  return accountsByType[lowercaseAccount]
@@ -5137,7 +5137,7 @@ class Exchange(object):
5137
5137
  return input
5138
5138
 
5139
5139
  def handle_until_option(self, key, request, params, multiplier=1):
5140
- until = self.safe_value_2(params, 'until', 'till')
5140
+ until = self.safe_integer_2(params, 'until', 'till')
5141
5141
  if until is not None:
5142
5142
  request[key] = self.parseToInt(until * multiplier)
5143
5143
  params = self.omit(params, ['until', 'till'])