set reduceOnly for futures exit orders
This commit is contained in:
parent
b3477c4802
commit
386be2d889
@ -86,14 +86,22 @@ class Binance(Exchange):
|
|||||||
try:
|
try:
|
||||||
params = self._params.copy()
|
params = self._params.copy()
|
||||||
params.update({'stopPrice': stop_price})
|
params.update({'stopPrice': stop_price})
|
||||||
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
|
params.update({'reduceOnly': True})
|
||||||
|
|
||||||
amount = self.amount_to_precision(pair, amount)
|
amount = self.amount_to_precision(pair, amount)
|
||||||
|
|
||||||
rate = self.price_to_precision(pair, rate)
|
rate = self.price_to_precision(pair, rate)
|
||||||
|
|
||||||
self._lev_prep(pair, leverage)
|
self._lev_prep(pair, leverage)
|
||||||
order = self._api.create_order(symbol=pair, type=ordertype, side=side,
|
order = self._api.create_order(
|
||||||
amount=amount, price=rate, params=params)
|
symbol=pair,
|
||||||
|
type=ordertype,
|
||||||
|
side=side,
|
||||||
|
amount=amount,
|
||||||
|
price=rate,
|
||||||
|
params=params
|
||||||
|
)
|
||||||
logger.info('stoploss limit order added for %s. '
|
logger.info('stoploss limit order added for %s. '
|
||||||
'stop price: %s. limit: %s', pair, stop_price, rate)
|
'stop price: %s. limit: %s', pair, stop_price, rate)
|
||||||
self._log_exchange_response('create_stoploss_order', order)
|
self._log_exchange_response('create_stoploss_order', order)
|
||||||
|
@ -882,21 +882,38 @@ class Exchange:
|
|||||||
self.set_margin_mode(pair, self.margin_mode)
|
self.set_margin_mode(pair, self.margin_mode)
|
||||||
self._set_leverage(leverage, pair)
|
self._set_leverage(leverage, pair)
|
||||||
|
|
||||||
def _get_params(self, ordertype: str, leverage: float, time_in_force: str = 'gtc') -> Dict:
|
def _get_params(
|
||||||
|
self,
|
||||||
|
ordertype: str,
|
||||||
|
leverage: float,
|
||||||
|
reduceOnly: bool,
|
||||||
|
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', '')
|
||||||
params.update({param: time_in_force})
|
params.update({param: time_in_force})
|
||||||
|
if reduceOnly:
|
||||||
|
params.update({'reduceOnly': True})
|
||||||
return params
|
return params
|
||||||
|
|
||||||
def create_order(self, pair: str, ordertype: str, side: str, amount: float,
|
def create_order(
|
||||||
rate: float, leverage: float = 1.0, time_in_force: str = 'gtc') -> Dict:
|
self,
|
||||||
|
pair: str,
|
||||||
|
ordertype: str,
|
||||||
|
side: str,
|
||||||
|
amount: float,
|
||||||
|
rate: float,
|
||||||
|
reduceOnly: bool = False,
|
||||||
|
leverage: float = 1.0,
|
||||||
|
time_in_force: str = 'gtc',
|
||||||
|
) -> Dict:
|
||||||
# TODO-lev: remove default for leverage
|
# TODO-lev: remove default for leverage
|
||||||
if self._config['dry_run']:
|
if self._config['dry_run']:
|
||||||
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
|
||||||
|
|
||||||
params = self._get_params(ordertype, leverage, time_in_force)
|
params = self._get_params(ordertype, leverage, reduceOnly, time_in_force)
|
||||||
|
|
||||||
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
|
||||||
@ -905,7 +922,9 @@ 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)
|
if not reduceOnly:
|
||||||
|
self._lev_prep(pair, leverage)
|
||||||
|
|
||||||
order = self._api.create_order(
|
order = self._api.create_order(
|
||||||
pair,
|
pair,
|
||||||
ordertype,
|
ordertype,
|
||||||
|
@ -70,6 +70,8 @@ class Ftx(Exchange):
|
|||||||
if order_types.get('stoploss', 'market') == 'limit':
|
if order_types.get('stoploss', 'market') == 'limit':
|
||||||
# set orderPrice to place limit order, otherwise it's a market order
|
# set orderPrice to place limit order, otherwise it's a market order
|
||||||
params['orderPrice'] = limit_rate
|
params['orderPrice'] = limit_rate
|
||||||
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
|
params.update({'reduceOnly': True})
|
||||||
|
|
||||||
params['stopPrice'] = stop_price
|
params['stopPrice'] = stop_price
|
||||||
amount = self.amount_to_precision(pair, amount)
|
amount = self.amount_to_precision(pair, amount)
|
||||||
|
@ -101,6 +101,8 @@ class Kraken(Exchange):
|
|||||||
Stoploss market orders is the only stoploss type supported by kraken.
|
Stoploss market orders is the only stoploss type supported by kraken.
|
||||||
"""
|
"""
|
||||||
params = self._params.copy()
|
params = self._params.copy()
|
||||||
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
|
params.update({'reduceOnly': True})
|
||||||
|
|
||||||
if order_types.get('stoploss', 'market') == 'limit':
|
if order_types.get('stoploss', 'market') == 'limit':
|
||||||
ordertype = "stop-loss-limit"
|
ordertype = "stop-loss-limit"
|
||||||
@ -159,8 +161,14 @@ class Kraken(Exchange):
|
|||||||
"""
|
"""
|
||||||
return
|
return
|
||||||
|
|
||||||
def _get_params(self, ordertype: str, leverage: float, time_in_force: str = 'gtc') -> Dict:
|
def _get_params(
|
||||||
params = super()._get_params(ordertype, leverage, time_in_force)
|
self,
|
||||||
|
ordertype: str,
|
||||||
|
leverage: float,
|
||||||
|
reduceOnly: bool,
|
||||||
|
time_in_force: str = 'gtc'
|
||||||
|
) -> Dict:
|
||||||
|
params = super()._get_params(ordertype, leverage, reduceOnly, time_in_force)
|
||||||
if leverage > 1.0:
|
if leverage > 1.0:
|
||||||
params['leverage'] = leverage
|
params['leverage'] = leverage
|
||||||
return params
|
return params
|
||||||
|
@ -699,6 +699,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
side=side,
|
side=side,
|
||||||
amount=amount,
|
amount=amount,
|
||||||
rate=enter_limit_requested,
|
rate=enter_limit_requested,
|
||||||
|
reduceOnly=False,
|
||||||
time_in_force=time_in_force,
|
time_in_force=time_in_force,
|
||||||
leverage=leverage
|
leverage=leverage
|
||||||
)
|
)
|
||||||
@ -1422,6 +1423,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
side=trade.exit_side,
|
side=trade.exit_side,
|
||||||
amount=amount,
|
amount=amount,
|
||||||
rate=limit,
|
rate=limit,
|
||||||
|
reduceOnly=self.trading_mode == TradingMode.FUTURES,
|
||||||
time_in_force=time_in_force
|
time_in_force=time_in_force
|
||||||
)
|
)
|
||||||
except InsufficientFundsError as e:
|
except InsufficientFundsError as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user