Simplify contract conversion code

by reusing "get_contract_size"
This commit is contained in:
Matthias 2022-01-03 18:12:45 +01:00
parent 7f88f9bf27
commit d8cb61278f

View File

@ -399,22 +399,16 @@ class Exchange:
def _amount_to_contracts(self, pair: str, amount: float): def _amount_to_contracts(self, pair: str, amount: float):
contract_size = None contract_size = self._get_contract_size(pair)
if ('contractSize' in self.markets[pair]): if contract_size and contract_size != 1:
contract_size = self.markets[pair]['contractSize']
if (contract_size and self.trading_mode == TradingMode.FUTURES):
return amount / contract_size return amount / contract_size
else: else:
return amount return amount
def _contracts_to_amount(self, pair: str, num_contracts: float): def _contracts_to_amount(self, pair: str, num_contracts: float):
contract_size = None contract_size = self._get_contract_size(pair)
if ('contractSize' in self.markets[pair]): if contract_size and contract_size != 1:
contract_size = self.markets[pair]['contractSize']
if (contract_size and self.trading_mode == TradingMode.FUTURES):
return num_contracts * contract_size return num_contracts * contract_size
else: else:
return num_contracts return num_contracts