Added in lev prep before creating api order

This commit is contained in:
Sam Germain 2021-09-19 03:05:58 -06:00
parent fa74b95a01
commit 2d679177e5
4 changed files with 10 additions and 9 deletions

View File

@ -107,6 +107,7 @@ class Binance(Exchange):
rate = self.price_to_precision(pair, rate)
self._lev_prep(pair, leverage)
order = self._api.create_order(symbol=pair, type=ordertype, side=side,
amount=amount, price=rate, params=params)
logger.info('stoploss limit order added for %s. '

View File

@ -773,10 +773,11 @@ class Exchange:
# Order handling
def _lev_prep(self, pair: str, leverage: float):
self.set_margin_mode(pair, self.collateral)
self._set_leverage(leverage, pair)
if self.trading_mode != TradingMode.SPOT:
self.set_margin_mode(pair, self.collateral)
self._set_leverage(leverage, pair)
def _get_params(self, time_in_force: str, ordertype: str, leverage: float) -> Dict:
def _get_params(self, ordertype: str, leverage: float, time_in_force: str = 'gtc') -> Dict:
params = self._params.copy()
if time_in_force != 'gtc' and ordertype != 'market':
param = self._ft_has.get('time_in_force_parameter', '')
@ -790,10 +791,7 @@ class Exchange:
dry_order = self.create_dry_run_order(pair, ordertype, side, amount, rate, leverage)
return dry_order
if self.trading_mode != TradingMode.SPOT:
self._lev_prep(pair, leverage)
params = self._get_params(time_in_force, ordertype, leverage)
params = self._get_params(ordertype, leverage, time_in_force)
try:
# Set the precision for amount and price(rate) as accepted by the exchange
@ -802,6 +800,7 @@ class Exchange:
or self._api.options.get("createMarketBuyOrderRequiresPrice", False))
rate_for_order = self.price_to_precision(pair, rate) if needs_price else None
self._lev_prep(pair, leverage)
order = self._api.create_order(pair, ordertype, side,
amount, rate_for_order, params)
self._log_exchange_response('create_order', order)

View File

@ -81,6 +81,7 @@ class Ftx(Exchange):
params['stopPrice'] = stop_price
amount = self.amount_to_precision(pair, amount)
self._lev_prep(pair, leverage)
order = self._api.create_order(symbol=pair, type=ordertype, side=side,
amount=amount, params=params)
self._log_exchange_response('create_stoploss_order', order)

View File

@ -184,8 +184,8 @@ class Kraken(Exchange):
"""
return
def _get_params(self, time_in_force: str, ordertype: str, leverage: float) -> Dict:
params = super()._get_params(time_in_force, ordertype, leverage)
def _get_params(self, ordertype: str, leverage: float, time_in_force: str = 'gtc') -> Dict:
params = super()._get_params(ordertype, leverage, time_in_force)
if leverage > 1.0:
params['leverage'] = leverage
return params