exchange._contracts_to_amount and exchange._amount_to_contracts safe checks

This commit is contained in:
Sam Germain
2021-12-31 05:28:25 -06:00
parent 6ab0e870c2
commit f92d47a16b
2 changed files with 36 additions and 4 deletions

View File

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