conflict resolved
This commit is contained in:
@@ -54,6 +54,7 @@ class FreqtradeBot(object):
|
||||
# Init objects
|
||||
self.config = config
|
||||
self.strategy: IStrategy = StrategyResolver(self.config).strategy
|
||||
|
||||
self.rpc: RPCManager = RPCManager(self)
|
||||
self.persistence = None
|
||||
self.exchange = Exchange(self.config)
|
||||
@@ -107,7 +108,7 @@ class FreqtradeBot(object):
|
||||
})
|
||||
logger.info('Changing state to: %s', state.name)
|
||||
if state == State.RUNNING:
|
||||
self._startup_messages()
|
||||
self.rpc.startup_messages(self.config)
|
||||
|
||||
if state == State.STOPPED:
|
||||
time.sleep(1)
|
||||
@@ -121,38 +122,6 @@ class FreqtradeBot(object):
|
||||
min_secs=min_secs)
|
||||
return state
|
||||
|
||||
def _startup_messages(self) -> None:
|
||||
if self.config.get('dry_run', False):
|
||||
self.rpc.send_msg({
|
||||
'type': RPCMessageType.WARNING_NOTIFICATION,
|
||||
'status': 'Dry run is enabled. All trades are simulated.'
|
||||
})
|
||||
stake_currency = self.config['stake_currency']
|
||||
stake_amount = self.config['stake_amount']
|
||||
minimal_roi = self.config['minimal_roi']
|
||||
ticker_interval = self.config['ticker_interval']
|
||||
exchange_name = self.config['exchange']['name']
|
||||
strategy_name = self.config.get('strategy', '')
|
||||
self.rpc.send_msg({
|
||||
'type': RPCMessageType.CUSTOM_NOTIFICATION,
|
||||
'status': f'*Exchange:* `{exchange_name}`\n'
|
||||
f'*Stake per trade:* `{stake_amount} {stake_currency}`\n'
|
||||
f'*Minimum ROI:* `{minimal_roi}`\n'
|
||||
f'*Ticker Interval:* `{ticker_interval}`\n'
|
||||
f'*Strategy:* `{strategy_name}`'
|
||||
})
|
||||
if self.config.get('dynamic_whitelist', False):
|
||||
top_pairs = 'top volume ' + str(self.config.get('dynamic_whitelist', 20))
|
||||
specific_pairs = ''
|
||||
else:
|
||||
top_pairs = 'whitelisted'
|
||||
specific_pairs = '\n' + ', '.join(self.config['exchange'].get('pair_whitelist', ''))
|
||||
self.rpc.send_msg({
|
||||
'type': RPCMessageType.STATUS_NOTIFICATION,
|
||||
'status': f'Searching for {top_pairs} {stake_currency} pairs to buy and sell...'
|
||||
f'{specific_pairs}'
|
||||
})
|
||||
|
||||
def _throttle(self, func: Callable[..., Any], min_secs: float, *args, **kwargs) -> Any:
|
||||
"""
|
||||
Throttles the given callable that it
|
||||
@@ -501,6 +470,7 @@ class FreqtradeBot(object):
|
||||
'stake_currency': stake_currency,
|
||||
'fiat_currency': fiat_currency
|
||||
})
|
||||
|
||||
# Fee is applied twice because we make a LIMIT_BUY and LIMIT_SELL
|
||||
fee = self.exchange.get_fee(symbol=pair, taker_or_maker='maker')
|
||||
trade = Trade(
|
||||
@@ -517,6 +487,7 @@ class FreqtradeBot(object):
|
||||
strategy=self.strategy.get_strategy_name(),
|
||||
ticker_interval=constants.TICKER_INTERVAL_MINUTES[self.config['ticker_interval']]
|
||||
)
|
||||
|
||||
Trade.session.add(trade)
|
||||
Trade.session.flush()
|
||||
|
||||
@@ -565,6 +536,12 @@ class FreqtradeBot(object):
|
||||
|
||||
trade.update(order)
|
||||
|
||||
if self.strategy.order_types.get('stoploss_on_exchange') and trade.is_open:
|
||||
result = self.handle_stoploss_on_exchange(trade)
|
||||
if result:
|
||||
self.wallets.update()
|
||||
return result
|
||||
|
||||
if trade.is_open and trade.open_order_id is None:
|
||||
# Check if we can sell our current pair
|
||||
result = self.handle_trade(trade)
|
||||
@@ -662,13 +639,54 @@ class FreqtradeBot(object):
|
||||
return True
|
||||
break
|
||||
else:
|
||||
logger.info('checking sell')
|
||||
logger.debug('checking sell')
|
||||
if self.check_sell(trade, sell_rate, buy, sell):
|
||||
return True
|
||||
|
||||
logger.info('Found no sell signals for whitelisted currencies. Trying again..')
|
||||
logger.debug('Found no sell signal for %s.', trade)
|
||||
return False
|
||||
|
||||
def handle_stoploss_on_exchange(self, trade: Trade) -> bool:
|
||||
"""
|
||||
Check if trade is fulfilled in which case the stoploss
|
||||
on exchange should be added immediately if stoploss on exchnage
|
||||
is enabled.
|
||||
"""
|
||||
|
||||
result = False
|
||||
|
||||
# If trade is open and the buy order is fulfilled but there is no stoploss,
|
||||
# then we add a stoploss on exchange
|
||||
if not trade.open_order_id and not trade.stoploss_order_id:
|
||||
if self.edge:
|
||||
stoploss = self.edge.stoploss(pair=trade.pair)
|
||||
else:
|
||||
stoploss = self.strategy.stoploss
|
||||
|
||||
stop_price = trade.open_rate * (1 + stoploss)
|
||||
|
||||
# limit price should be less than stop price.
|
||||
# 0.98 is arbitrary here.
|
||||
limit_price = stop_price * 0.98
|
||||
|
||||
stoploss_order_id = self.exchange.stoploss_limit(
|
||||
pair=trade.pair, amount=trade.amount, stop_price=stop_price, rate=limit_price
|
||||
)['id']
|
||||
trade.stoploss_order_id = str(stoploss_order_id)
|
||||
|
||||
# Or the trade open and there is already a stoploss on exchange.
|
||||
# so we check if it is hit ...
|
||||
elif trade.stoploss_order_id:
|
||||
logger.debug('Handling stoploss on exchange %s ...', trade)
|
||||
order = self.exchange.get_order(trade.stoploss_order_id, trade.pair)
|
||||
if order['status'] == 'closed':
|
||||
trade.sell_reason = SellType.STOPLOSS_ON_EXCHANGE.value
|
||||
trade.update(order)
|
||||
result = True
|
||||
else:
|
||||
result = False
|
||||
return result
|
||||
|
||||
def check_sell(self, trade: Trade, sell_rate: float, buy: bool, sell: bool) -> bool:
|
||||
if self.edge:
|
||||
stoploss = self.edge.stoploss(trade.pair)
|
||||
@@ -793,6 +811,17 @@ class FreqtradeBot(object):
|
||||
sell_type = 'sell'
|
||||
if sell_reason in (SellType.STOP_LOSS, SellType.TRAILING_STOP_LOSS):
|
||||
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 ...
|
||||
if self.strategy.order_types.get('stoploss_on_exchange') and trade.stoploss_order_id:
|
||||
self.exchange.cancel_order(trade.stoploss_order_id, trade.pair)
|
||||
|
||||
# Execute sell and update trade record
|
||||
order_id = self.exchange.sell(pair=str(trade.pair),
|
||||
ordertype=self.strategy.order_types[sell_type],
|
||||
|
Reference in New Issue
Block a user