updated requested changes in PR #6545

This commit is contained in:
மனோஜ்குமார் பழனிச்சாமி 2022-03-26 10:44:59 +05:30
parent b640905647
commit ab7cdca68e
2 changed files with 22 additions and 14 deletions

View File

@ -1139,7 +1139,7 @@ class Exchange:
conf_strategy = self._config.get(strat_name, {}) conf_strategy = self._config.get(strat_name, {})
if conf_strategy.get('use_order_book', False) and ('use_order_book' in conf_strategy): if conf_strategy.get('use_order_book', False):
order_book_top = conf_strategy.get('order_book_top', 1) order_book_top = conf_strategy.get('order_book_top', 1)
if order_book is None: if order_book is None:
@ -1178,14 +1178,15 @@ class Exchange:
return rate return rate
def get_rates(self, pair: str, refresh: bool) -> Tuple[float, float]: def get_rates(self, pair: str, refresh: bool) -> Tuple[float, float]:
buy_rate = sell_rate = None buy_rate = None
sell_rate = None
if not refresh: if not refresh:
buy_rate, sell_rate = self._buy_rate_cache.get(pair), self._sell_rate_cache.get(pair) buy_rate, sell_rate = self._buy_rate_cache.get(pair), self._sell_rate_cache.get(pair)
bid_strategy = self._config.get('bid_strategy', {}) bid_strategy = self._config.get('bid_strategy', {})
ask_strategy = self._config.get('ask_strategy', {}) ask_strategy = self._config.get('ask_strategy', {})
order_book = ticker = None order_book = ticker = None
if bid_strategy.get('use_order_book', False) and ('use_order_book' in bid_strategy): if bid_strategy.get('use_order_book', False):
order_book_top = max(bid_strategy.get('order_book_top', 1), order_book_top = max(bid_strategy.get('order_book_top', 1),
ask_strategy.get('order_book_top', 1)) ask_strategy.get('order_book_top', 1))
order_book = self.fetch_l2_order_book(pair, order_book_top) order_book = self.fetch_l2_order_book(pair, order_book_top)

View File

@ -454,20 +454,27 @@ class FreqtradeBot(LoggingMixin):
Once that completes, the existing trade is modified to match new data. Once that completes, the existing trade is modified to match new data.
""" """
current_entry_rate, current_exit_rate = self.exchange.get_rates(trade.pair, True) current_entry_rate, current_exit_rate = self.exchange.get_rates(trade.pair, True)
current_rate = current_entry_rate # backward compatibilty
current_profit = trade.calc_profit_ratio(current_rate)
min_stake_amount = self.exchange.get_min_pair_stake_amount(trade.pair, current_entry_profit = trade.calc_profit_ratio(current_entry_rate)
current_rate, current_exit_profit = trade.calc_profit_ratio(current_exit_rate)
self.strategy.stoploss)
max_stake_amount = self.wallets.get_available_stake_amount() min_entry_stake = self.exchange.get_min_pair_stake_amount(trade.pair,
current_entry_rate,
self.strategy.stoploss)
min_exit_stake = self.exchange.get_min_pair_stake_amount(trade.pair,
current_exit_rate,
self.strategy.stoploss)
max_stake = self.wallets.get_available_stake_amount()
logger.debug(f"Calling adjust_trade_position for pair {trade.pair}") logger.debug(f"Calling adjust_trade_position for pair {trade.pair}")
stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position, stake_amount = strategy_safe_wrapper(self.strategy.adjust_trade_position,
default_retval=None)( default_retval=None)(
trade=trade, current_time=datetime.now(timezone.utc), current_rate=current_rate, trade=trade, current_time=datetime.now(timezone.utc), current_rate=current_entry_rate,
current_profit=current_profit, min_stake=min_stake_amount, current_profit=current_entry_profit, min_stake=min_entry_stake,
max_stake=max_stake_amount, current_entry_rate=current_entry_rate, max_stake=max_stake,
current_exit_rate=current_exit_rate) current_entry_rate=current_entry_rate, current_exit_rate=current_exit_rate,
current_entry_profit=current_entry_profit, current_exit_profit=current_exit_profit,
min_entry_stake=min_entry_stake, min_exit_stake=min_exit_stake
)
if stake_amount is not None and stake_amount > 0.0: if stake_amount is not None and stake_amount > 0.0:
# We should increase our position # We should increase our position
@ -484,7 +491,7 @@ class FreqtradeBot(LoggingMixin):
# We should decrease our position # We should decrease our position
# Strategy should return value as Decimal for accuracy. # Strategy should return value as Decimal for accuracy.
amount = abs(float(Decimal(stake_amount) / Decimal(current_exit_rate))) amount = abs(float(Decimal(stake_amount) / Decimal(current_exit_rate)))
if trade.amount - amount < min_stake_amount: if trade.amount - amount < min_exit_stake_amount:
logger.info('Remaining amount would be too small') logger.info('Remaining amount would be too small')
return return
if amount > trade.amount: if amount > trade.amount: