Use combined stoploss_adjust where possible
This commit is contained in:
parent
d831d7d317
commit
cf6b75a3f3
@ -42,24 +42,6 @@ class Binance(Exchange):
|
|||||||
(TradingMode.FUTURES, MarginMode.ISOLATED)
|
(TradingMode.FUTURES, MarginMode.ISOLATED)
|
||||||
]
|
]
|
||||||
|
|
||||||
def stoploss_adjust(self, stop_loss: float, order: Dict, side: str) -> bool:
|
|
||||||
"""
|
|
||||||
Verify stop_loss against stoploss-order value (limit or price)
|
|
||||||
Returns True if adjustment is necessary.
|
|
||||||
:param side: "buy" or "sell"
|
|
||||||
"""
|
|
||||||
order_types = ('stop_loss_limit', 'stop', 'stop_market')
|
|
||||||
|
|
||||||
return (
|
|
||||||
order.get('stopPrice', None) is None
|
|
||||||
or (
|
|
||||||
order['type'] in order_types
|
|
||||||
and (
|
|
||||||
(side == "sell" and stop_loss > float(order['stopPrice'])) or
|
|
||||||
(side == "buy" and stop_loss < float(order['stopPrice']))
|
|
||||||
)
|
|
||||||
))
|
|
||||||
|
|
||||||
def get_tickers(self, symbols: Optional[List[str]] = None, cached: bool = False) -> Tickers:
|
def get_tickers(self, symbols: Optional[List[str]] = None, cached: bool = False) -> Tickers:
|
||||||
tickers = super().get_tickers(symbols=symbols, cached=cached)
|
tickers = super().get_tickers(symbols=symbols, cached=cached)
|
||||||
if self.trading_mode == TradingMode.FUTURES:
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
|
@ -1076,7 +1076,11 @@ class Exchange:
|
|||||||
Verify stop_loss against stoploss-order value (limit or price)
|
Verify stop_loss against stoploss-order value (limit or price)
|
||||||
Returns True if adjustment is necessary.
|
Returns True if adjustment is necessary.
|
||||||
"""
|
"""
|
||||||
raise OperationalException(f"stoploss is not implemented for {self.name}.")
|
if not self._ft_has.get('stoploss_on_exchange'):
|
||||||
|
raise OperationalException(f"stoploss is not implemented for {self.name}.")
|
||||||
|
|
||||||
|
return ((side == "sell" and stop_loss > float(order['stopPrice'])) or
|
||||||
|
(side == "buy" and stop_loss < float(order['stopPrice'])))
|
||||||
|
|
||||||
def _get_stop_order_type(self, user_order_type) -> Tuple[str, str]:
|
def _get_stop_order_type(self, user_order_type) -> Tuple[str, str]:
|
||||||
|
|
||||||
|
@ -126,13 +126,3 @@ class Gateio(Exchange):
|
|||||||
pair=pair,
|
pair=pair,
|
||||||
params={'stop': True}
|
params={'stop': True}
|
||||||
)
|
)
|
||||||
|
|
||||||
def stoploss_adjust(self, stop_loss: float, order: Dict, side: str) -> bool:
|
|
||||||
"""
|
|
||||||
Verify stop_loss against stoploss-order value (limit or price)
|
|
||||||
Returns True if adjustment is necessary.
|
|
||||||
"""
|
|
||||||
return (order.get('stopPrice', None) is None or (
|
|
||||||
side == "sell" and stop_loss > float(order['stopPrice'])) or
|
|
||||||
(side == "buy" and stop_loss < float(order['stopPrice']))
|
|
||||||
)
|
|
||||||
|
@ -162,9 +162,6 @@ def test_stoploss_adjust_binance(mocker, default_conf, sl1, sl2, sl3, side):
|
|||||||
}
|
}
|
||||||
assert exchange.stoploss_adjust(sl1, order, side=side)
|
assert exchange.stoploss_adjust(sl1, order, side=side)
|
||||||
assert not exchange.stoploss_adjust(sl2, order, side=side)
|
assert not exchange.stoploss_adjust(sl2, order, side=side)
|
||||||
# Test with invalid order case
|
|
||||||
order['type'] = 'stop_loss'
|
|
||||||
assert not exchange.stoploss_adjust(sl3, order, side=side)
|
|
||||||
|
|
||||||
|
|
||||||
def test_fill_leverage_tiers_binance(default_conf, mocker):
|
def test_fill_leverage_tiers_binance(default_conf, mocker):
|
||||||
|
Loading…
Reference in New Issue
Block a user