Merge pull request #6588 from samgermain/contracts

Add amount_to_contracts and order_contracts_to_amount to exchange.stoploss
This commit is contained in:
Matthias
2022-03-25 19:18:01 +01:00
committed by GitHub
2 changed files with 73 additions and 3 deletions

View File

@@ -401,7 +401,7 @@ class Exchange:
return trades
def _order_contracts_to_amount(self, order: Dict) -> Dict:
if 'symbol' in order:
if 'symbol' in order and order['symbol'] is not None:
contract_size = self._get_contract_size(order['symbol'])
if contract_size != 1:
for prop in ['amount', 'cost', 'filled', 'remaining']:
@@ -1102,14 +1102,15 @@ class Exchange:
if self.trading_mode == TradingMode.FUTURES:
params['reduceOnly'] = True
amount = self.amount_to_precision(pair, amount)
amount = self.amount_to_precision(pair, self._amount_to_contracts(pair, amount))
self._lev_prep(pair, leverage, side)
order = self._api.create_order(symbol=pair, type=ordertype, side=side,
amount=amount, price=rate, params=params)
self._log_exchange_response('create_stoploss_order', order)
order = self._order_contracts_to_amount(order)
logger.info(f"stoploss {user_order_type} order added for {pair}. "
f"stop price: {stop_price}. limit: {rate}")
self._log_exchange_response('create_stoploss_order', order)
return order
except ccxt.InsufficientFunds as e:
raise InsufficientFundsError(