Skip to content

Commit

Permalink
Reenable stoploss_on_exchange for dry-run
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Sep 1, 2019
1 parent a7e45c5 commit aae9c31
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
5 changes: 4 additions & 1 deletion freqtrade/exchange/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def symbol_price_prec(self, pair, price: float):
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,
Expand All @@ -382,6 +382,7 @@ def dry_run_order(self, pair: str, ordertype: str, side: str, amount: float,
"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:
Expand All @@ -392,6 +393,8 @@ def _store_dry_order(self, dry_order: Dict) -> None:
"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,
Expand Down
8 changes: 1 addition & 7 deletions freqtrade/freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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

Expand Down Expand Up @@ -79,12 +79,6 @@ def __init__(self, config: Dict[str, Any]) -> None:
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
Expand Down
3 changes: 1 addition & 2 deletions freqtrade/tests/test_freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aae9c31

Please sign in to comment.