mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 18:23:55 +00:00
Merge pull request #1357 from mishaker/fix_dry_run_stop_price
Fix dry run stop price in case of stoploss on exchange
This commit is contained in:
commit
27c2e80cff
|
@ -798,6 +798,12 @@ class FreqtradeBot(object):
|
||||||
if sell_reason in (SellType.STOP_LOSS, SellType.TRAILING_STOP_LOSS):
|
if sell_reason in (SellType.STOP_LOSS, SellType.TRAILING_STOP_LOSS):
|
||||||
sell_type = 'stoploss'
|
sell_type = 'stoploss'
|
||||||
|
|
||||||
|
# if stoploss is on exchange and we are on dry_run mode,
|
||||||
|
# we consider the sell price stop price
|
||||||
|
if self.config.get('dry_run', False) and sell_type == 'stoploss' \
|
||||||
|
and self.strategy.order_types['stoploss_on_exchange']:
|
||||||
|
limit = trade.stop_loss
|
||||||
|
|
||||||
# First cancelling stoploss on exchange ...
|
# First cancelling stoploss on exchange ...
|
||||||
if self.strategy.order_types.get('stoploss_on_exchange') and trade.stoploss_order_id:
|
if self.strategy.order_types.get('stoploss_on_exchange') and trade.stoploss_order_id:
|
||||||
self.exchange.cancel_order(trade.stoploss_order_id, trade.pair)
|
self.exchange.cancel_order(trade.stoploss_order_id, trade.pair)
|
||||||
|
|
|
@ -1562,6 +1562,60 @@ def test_execute_sell_down(default_conf, ticker, fee, ticker_sell_down, markets,
|
||||||
} == last_msg
|
} == last_msg
|
||||||
|
|
||||||
|
|
||||||
|
def test_execute_sell_down_stoploss_on_exchange_dry_run(default_conf, ticker, fee,
|
||||||
|
ticker_sell_down,
|
||||||
|
markets, mocker) -> None:
|
||||||
|
rpc_mock = patch_RPCManager(mocker)
|
||||||
|
mocker.patch.multiple(
|
||||||
|
'freqtrade.exchange.Exchange',
|
||||||
|
_load_markets=MagicMock(return_value={}),
|
||||||
|
get_ticker=ticker,
|
||||||
|
get_fee=fee,
|
||||||
|
get_markets=markets
|
||||||
|
)
|
||||||
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
|
patch_get_signal(freqtrade)
|
||||||
|
|
||||||
|
# Create some test data
|
||||||
|
freqtrade.create_trade()
|
||||||
|
|
||||||
|
trade = Trade.query.first()
|
||||||
|
assert trade
|
||||||
|
|
||||||
|
# Decrease the price and sell it
|
||||||
|
mocker.patch.multiple(
|
||||||
|
'freqtrade.exchange.Exchange',
|
||||||
|
get_ticker=ticker_sell_down
|
||||||
|
)
|
||||||
|
|
||||||
|
default_conf['dry_run'] = True
|
||||||
|
freqtrade.strategy.order_types['stoploss_on_exchange'] = True
|
||||||
|
# Setting trade stoploss to 0.01
|
||||||
|
|
||||||
|
trade.stop_loss = 0.00001099 * 0.99
|
||||||
|
freqtrade.execute_sell(trade=trade, limit=ticker_sell_down()['bid'],
|
||||||
|
sell_reason=SellType.STOP_LOSS)
|
||||||
|
|
||||||
|
assert rpc_mock.call_count == 2
|
||||||
|
last_msg = rpc_mock.call_args_list[-1][0][0]
|
||||||
|
|
||||||
|
assert {
|
||||||
|
'type': RPCMessageType.SELL_NOTIFICATION,
|
||||||
|
'exchange': 'Bittrex',
|
||||||
|
'pair': 'ETH/BTC',
|
||||||
|
'gain': 'loss',
|
||||||
|
'market_url': 'https://bittrex.com/Market/Index?MarketName=BTC-ETH',
|
||||||
|
'limit': 1.08801e-05,
|
||||||
|
'amount': 90.99181073703367,
|
||||||
|
'open_rate': 1.099e-05,
|
||||||
|
'current_rate': 1.044e-05,
|
||||||
|
'profit_amount': -1.498e-05,
|
||||||
|
'profit_percent': -0.01493766,
|
||||||
|
'stake_currency': 'BTC',
|
||||||
|
'fiat_currency': 'USD',
|
||||||
|
} == last_msg
|
||||||
|
|
||||||
|
|
||||||
def test_execute_sell_with_stoploss_on_exchange(default_conf,
|
def test_execute_sell_with_stoploss_on_exchange(default_conf,
|
||||||
ticker, fee, ticker_sell_up,
|
ticker, fee, ticker_sell_up,
|
||||||
markets, mocker) -> None:
|
markets, mocker) -> None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user