stop loss order added right after a buy order is executued
This commit is contained in:
parent
bfbdddff26
commit
3b7e05e07b
@ -508,6 +508,37 @@ class FreqtradeBot(object):
|
||||
Trade.session.add(trade)
|
||||
Trade.session.flush()
|
||||
|
||||
# Check if stoploss should be added on exchange
|
||||
# If True then here immediately after buy we should
|
||||
# Add the stoploss order
|
||||
if self.strategy.stoploss_on_exchange:
|
||||
stoploss = self.edge.stoploss if self.edge else self.strategy.stoploss
|
||||
stop_price = buy_limit * (1 + stoploss)
|
||||
|
||||
# limit price should be less than stop price.
|
||||
# 0.98 is arbitrary here.
|
||||
limit_price = stop_price * 0.98
|
||||
|
||||
order_id = self.exchange.stoploss_limit(pair=pair, amount=amount,
|
||||
stop_price=stop_price, rate=limit_price)['id']
|
||||
|
||||
trade = Trade(
|
||||
pair=pair,
|
||||
stake_amount=stake_amount,
|
||||
amount=amount,
|
||||
fee_open=fee,
|
||||
fee_close=fee,
|
||||
stoploss=stop_price,
|
||||
open_date=datetime.utcnow(),
|
||||
exchange=self.exchange.id,
|
||||
open_order_id=order_id,
|
||||
strategy=self.strategy.get_strategy_name(),
|
||||
ticker_interval=constants.TICKER_INTERVAL_MINUTES[self.config['ticker_interval']]
|
||||
)
|
||||
|
||||
Trade.session.add(trade)
|
||||
Trade.session.flush()
|
||||
|
||||
# Updating wallets
|
||||
self.wallets.update()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user