Added in lev prep before creating api order
This commit is contained in:
parent
fa74b95a01
commit
2d679177e5
@ -107,6 +107,7 @@ class Binance(Exchange):
|
|||||||
|
|
||||||
rate = self.price_to_precision(pair, rate)
|
rate = self.price_to_precision(pair, rate)
|
||||||
|
|
||||||
|
self._lev_prep(pair, leverage)
|
||||||
order = self._api.create_order(symbol=pair, type=ordertype, side=side,
|
order = self._api.create_order(symbol=pair, type=ordertype, side=side,
|
||||||
amount=amount, price=rate, params=params)
|
amount=amount, price=rate, params=params)
|
||||||
logger.info('stoploss limit order added for %s. '
|
logger.info('stoploss limit order added for %s. '
|
||||||
|
@ -773,10 +773,11 @@ class Exchange:
|
|||||||
# Order handling
|
# Order handling
|
||||||
|
|
||||||
def _lev_prep(self, pair: str, leverage: float):
|
def _lev_prep(self, pair: str, leverage: float):
|
||||||
self.set_margin_mode(pair, self.collateral)
|
if self.trading_mode != TradingMode.SPOT:
|
||||||
self._set_leverage(leverage, pair)
|
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()
|
params = self._params.copy()
|
||||||
if time_in_force != 'gtc' and ordertype != 'market':
|
if time_in_force != 'gtc' and ordertype != 'market':
|
||||||
param = self._ft_has.get('time_in_force_parameter', '')
|
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)
|
dry_order = self.create_dry_run_order(pair, ordertype, side, amount, rate, leverage)
|
||||||
return dry_order
|
return dry_order
|
||||||
|
|
||||||
if self.trading_mode != TradingMode.SPOT:
|
params = self._get_params(ordertype, leverage, time_in_force)
|
||||||
self._lev_prep(pair, leverage)
|
|
||||||
|
|
||||||
params = self._get_params(time_in_force, ordertype, leverage)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Set the precision for amount and price(rate) as accepted by the exchange
|
# 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))
|
or self._api.options.get("createMarketBuyOrderRequiresPrice", False))
|
||||||
rate_for_order = self.price_to_precision(pair, rate) if needs_price else None
|
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,
|
order = self._api.create_order(pair, ordertype, side,
|
||||||
amount, rate_for_order, params)
|
amount, rate_for_order, params)
|
||||||
self._log_exchange_response('create_order', order)
|
self._log_exchange_response('create_order', order)
|
||||||
|
@ -81,6 +81,7 @@ class Ftx(Exchange):
|
|||||||
params['stopPrice'] = stop_price
|
params['stopPrice'] = stop_price
|
||||||
amount = self.amount_to_precision(pair, amount)
|
amount = self.amount_to_precision(pair, amount)
|
||||||
|
|
||||||
|
self._lev_prep(pair, leverage)
|
||||||
order = self._api.create_order(symbol=pair, type=ordertype, side=side,
|
order = self._api.create_order(symbol=pair, type=ordertype, side=side,
|
||||||
amount=amount, params=params)
|
amount=amount, params=params)
|
||||||
self._log_exchange_response('create_stoploss_order', order)
|
self._log_exchange_response('create_stoploss_order', order)
|
||||||
|
@ -184,8 +184,8 @@ class Kraken(Exchange):
|
|||||||
"""
|
"""
|
||||||
return
|
return
|
||||||
|
|
||||||
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 = super()._get_params(time_in_force, ordertype, leverage)
|
params = super()._get_params(ordertype, leverage, time_in_force)
|
||||||
if leverage > 1.0:
|
if leverage > 1.0:
|
||||||
params['leverage'] = leverage
|
params['leverage'] = leverage
|
||||||
return params
|
return params
|
||||||
|
Loading…
Reference in New Issue
Block a user