updated requested change in PR #6545
Co-Authored-By: மனோஜ்குமார் பழனிச்சாமி <smartmanoj42857@gmail.com>
This commit is contained in:
@@ -452,15 +452,8 @@ class FreqtradeBot(LoggingMixin):
|
||||
If the strategy triggers the adjustment, a new order gets issued.
|
||||
Once that completes, the existing trade is modified to match new data.
|
||||
"""
|
||||
if self.strategy.max_entry_position_adjustment > -1:
|
||||
count_of_buys = trade.nr_of_successful_buys
|
||||
if count_of_buys > self.strategy.max_entry_position_adjustment:
|
||||
logger.debug(f"Max adjustment entries for {trade.pair} has been reached.")
|
||||
return
|
||||
else:
|
||||
logger.debug("Max adjustment entries is set to unlimited.")
|
||||
current_entry_rate = self.exchange.get_rate(trade.pair, refresh=True, side="buy")
|
||||
current_exit_rate = self.exchange.get_rate(trade.pair, refresh=True, side="sell")
|
||||
current_exit_rate = current_entry_rate
|
||||
current_rate = current_entry_rate # backward compatibilty
|
||||
current_profit = trade.calc_profit_ratio(current_rate)
|
||||
|
||||
@@ -478,11 +471,18 @@ class FreqtradeBot(LoggingMixin):
|
||||
|
||||
if stake_amount is not None and stake_amount > 0.0:
|
||||
# We should increase our position
|
||||
if self.strategy.max_entry_position_adjustment > -1:
|
||||
count_of_buys = trade.nr_of_successful_buys
|
||||
if count_of_buys > self.strategy.max_entry_position_adjustment:
|
||||
logger.debug(f"Max adjustment entries for {trade.pair} has been reached.")
|
||||
return
|
||||
else:
|
||||
logger.debug("Max adjustment entries is set to unlimited.")
|
||||
self.execute_entry(trade.pair, stake_amount, trade=trade)
|
||||
|
||||
if stake_amount is not None and stake_amount < 0.0:
|
||||
# We should decrease our position
|
||||
amount = -stake_amount / current_exit_rate
|
||||
amount = abs(stake_amount) / current_exit_rate
|
||||
if trade.amount - amount < min_stake_amount:
|
||||
logger.info('Remaining amount would be too small')
|
||||
return
|
||||
@@ -1270,6 +1270,8 @@ class FreqtradeBot(LoggingMixin):
|
||||
current_rate = self.exchange.get_rate(
|
||||
trade.pair, refresh=False, side="sell") if not fill else None
|
||||
if sub_trade:
|
||||
|
||||
# for mypy only; order will always be passed during sub trade
|
||||
assert order is not None
|
||||
amount = order.safe_filled
|
||||
profit_rate = order.safe_price
|
||||
@@ -1279,13 +1281,11 @@ class FreqtradeBot(LoggingMixin):
|
||||
|
||||
profit_ratio = trade.close_profit
|
||||
profit = trade.close_profit_abs
|
||||
open_rate = trade.get_open_rate(profit, profit_rate, amount)
|
||||
else:
|
||||
profit_rate = trade.close_rate if trade.close_rate else trade.close_rate_requested
|
||||
profit = trade.calc_profit(rate=profit_rate)
|
||||
profit_ratio = trade.calc_profit_ratio(profit_rate)
|
||||
amount = trade.amount
|
||||
open_rate = trade.open_rate
|
||||
gain = "profit" if profit_ratio > 0 else "loss"
|
||||
|
||||
msg = {
|
||||
@@ -1298,7 +1298,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
'limit': profit_rate,
|
||||
'order_type': order_type,
|
||||
'amount': amount,
|
||||
'open_rate': open_rate,
|
||||
'open_rate': trade.open_rate,
|
||||
'close_rate': profit_rate,
|
||||
'current_rate': current_rate,
|
||||
'profit_amount': profit,
|
||||
@@ -1409,6 +1409,7 @@ class FreqtradeBot(LoggingMixin):
|
||||
self.handle_order_fee(trade, order_obj, order)
|
||||
|
||||
trade.update_trade(order_obj)
|
||||
Trade.commit()
|
||||
|
||||
if order['status'] in constants.NON_OPEN_EXCHANGE_STATES:
|
||||
# If a buy order was closed, force update on stoploss on exchange
|
||||
|
||||
@@ -816,7 +816,7 @@ class Backtesting:
|
||||
sub_trade = order.safe_amount_after_fee != trade.amount
|
||||
if sub_trade:
|
||||
order.close_bt_order(current_time)
|
||||
trade.process_sell_sub_trade(order, is_non_bt=False)
|
||||
trade.process_sell_sub_trade(order)
|
||||
trade.recalc_trade_from_orders()
|
||||
else:
|
||||
trade.close_date = current_time
|
||||
|
||||
@@ -127,7 +127,6 @@ class Order(_DECL_BASE):
|
||||
side = Column(String(25), nullable=True)
|
||||
price = Column(Float, nullable=True)
|
||||
average = Column(Float, nullable=True)
|
||||
initial_average = Column(Float, nullable=True)
|
||||
amount = Column(Float, nullable=True)
|
||||
filled = Column(Float, nullable=True)
|
||||
remaining = Column(Float, nullable=True)
|
||||
@@ -500,8 +499,10 @@ class LocalTrade():
|
||||
# condition to avoid reset value when updating fees
|
||||
if self.open_order_id == order.order_id:
|
||||
self.open_order_id = None
|
||||
self.process_sell_sub_trade(order)
|
||||
return
|
||||
if self.amount == order.safe_amount_after_fee:
|
||||
self.close(order.safe_price)
|
||||
else:
|
||||
self.process_sell_sub_trade(order)
|
||||
elif order.ft_order_side == 'stoploss':
|
||||
self.stoploss_order_id = None
|
||||
self.close_rate_requested = self.stop_loss
|
||||
@@ -518,12 +519,6 @@ class LocalTrade():
|
||||
sell_amount = order.safe_amount_after_fee
|
||||
sell_rate = order.safe_price
|
||||
sell_stake_amount = sell_rate * sell_amount * (1 - self.fee_close)
|
||||
if sell_amount == self.amount:
|
||||
if is_closed:
|
||||
self.close(sell_rate)
|
||||
if is_non_bt:
|
||||
Trade.commit()
|
||||
return
|
||||
profit = self.calc_profit2(self.open_rate, sell_rate, sell_amount)
|
||||
if is_closed:
|
||||
self.amount -= sell_amount
|
||||
@@ -533,8 +528,6 @@ class LocalTrade():
|
||||
self.close_profit_abs = profit
|
||||
self.close_profit = sell_stake_amount / (sell_stake_amount - profit) - 1
|
||||
self.recalc_open_trade_value()
|
||||
if is_non_bt:
|
||||
Trade.commit()
|
||||
|
||||
def calc_profit2(self, open_rate: float, close_rate: float,
|
||||
amount: float) -> float:
|
||||
@@ -542,12 +535,6 @@ class LocalTrade():
|
||||
(Decimal(1 - self.fee_close) * Decimal(close_rate) -
|
||||
Decimal(1 + self.fee_open) * Decimal(open_rate)))
|
||||
|
||||
def get_open_rate(self, profit: float, close_rate: float,
|
||||
amount: float) -> float:
|
||||
return float((Decimal(amount) *
|
||||
(Decimal(1 - self.fee_close) * Decimal(close_rate)) -
|
||||
Decimal(profit))/(Decimal(amount) * Decimal(1 + self.fee_open)))
|
||||
|
||||
def close(self, rate: float, *, show_msg: bool = True) -> None:
|
||||
"""
|
||||
Sets close_rate to the given rate, calculates total profit
|
||||
@@ -685,10 +672,11 @@ class LocalTrade():
|
||||
tmp_amount = o.safe_amount_after_fee
|
||||
tmp_price = o.safe_price
|
||||
is_sell = o.ft_order_side != 'buy'
|
||||
side = [1, -1][is_sell]
|
||||
side = -1 if is_sell else 1
|
||||
if tmp_amount > 0.0 and tmp_price is not None:
|
||||
total_amount += tmp_amount * side
|
||||
total_stake += [tmp_price, avg_price][is_sell] * tmp_amount * side
|
||||
price = avg_price if is_sell else tmp_price
|
||||
total_stake += price * tmp_amount * side
|
||||
if total_amount > 0:
|
||||
avg_price = total_stake / total_amount
|
||||
|
||||
|
||||
Reference in New Issue
Block a user