Reenable stoploss_on_exchange for dry-run

This commit is contained in:
Matthias 2019-09-01 17:48:06 +02:00
parent a7e45c5a73
commit aae9c3194f
3 changed files with 6 additions and 10 deletions

View File

@ -367,7 +367,7 @@ class Exchange(object):
def dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,
rate: float, params: Dict = {}) -> Dict[str, Any]:
order_id = f'dry_run_{side}_{randint(0, 10**6)}'
dry_order = { # TODO: additional entry should be added for stoploss limit
dry_order = {
"id": order_id,
'pair': pair,
'price': rate,
@ -382,6 +382,7 @@ class Exchange(object):
"info": {}
}
self._store_dry_order(dry_order)
# Copy order and close it - so the returned order is open unless it's a market order
return dry_order
def _store_dry_order(self, dry_order: Dict) -> None:
@ -392,6 +393,8 @@ class Exchange(object):
"filled": closed_order["amount"],
"remaining": 0
})
if closed_order["type"] in ["stop_loss_limit"]:
closed_order["info"].update({"stopPrice": closed_order["price"]})
self._dry_run_open_orders[closed_order["id"]] = closed_order
def create_order(self, pair: str, ordertype: str, side: str, amount: float,

View File

@ -21,7 +21,7 @@ from freqtrade.exchange import timeframe_to_minutes, timeframe_to_next_date
from freqtrade.persistence import Trade
from freqtrade.rpc import RPCManager, RPCMessageType
from freqtrade.resolvers import ExchangeResolver, StrategyResolver, PairListResolver
from freqtrade.state import State, RunMode
from freqtrade.state import State
from freqtrade.strategy.interface import SellType, IStrategy
from freqtrade.wallets import Wallets
@ -79,12 +79,6 @@ class FreqtradeBot(object):
persistence.init(self.config.get('db_url', None),
clean_open_orders=self.config.get('dry_run', False))
# Stoploss on exchange does not make sense, therefore we need to disable that.
if (self.dataprovider.runmode == RunMode.DRY_RUN and
self.strategy.order_types.get('stoploss_on_exchange', False)):
logger.info("Disabling stoploss_on_exchange during dry-run.")
self.strategy.order_types['stoploss_on_exchange'] = False
config['order_types']['stoploss_on_exchange'] = False
# Set initial bot state from config
initial_state = self.config.get('initial_state')
self.state = State[initial_state.upper()] if initial_state else State.STOPPED

View File

@ -147,8 +147,7 @@ def test_order_dict_dry_run(default_conf, mocker, caplog) -> None:
}
freqtrade = FreqtradeBot(conf)
assert log_has("Disabling stoploss_on_exchange during dry-run.", caplog)
assert not freqtrade.strategy.order_types['stoploss_on_exchange']
assert freqtrade.strategy.order_types['stoploss_on_exchange']
caplog.clear()
# is left untouched