updated unit tests
This commit is contained in:
parent
dcba781ef7
commit
988a9f05f2
@ -518,22 +518,11 @@ class LocalTrade():
|
|||||||
|
|
||||||
def process_sell_sub_trade(self, order: Order, is_closed: bool = True, is_non_bt: bool = True) -> None:
|
def process_sell_sub_trade(self, order: Order, is_closed: bool = True, is_non_bt: bool = True) -> None:
|
||||||
orders = (self.select_filled_orders('buy'))
|
orders = (self.select_filled_orders('buy'))
|
||||||
|
|
||||||
if len(orders) < 1:
|
|
||||||
# Todo /test_freqtradebot.py::test_execute_trade_exit_market_order
|
|
||||||
self.close(order.safe_price)
|
|
||||||
if is_non_bt: Trade.commit()
|
|
||||||
logger.info("*:"*500)
|
|
||||||
return
|
|
||||||
logger.info('debug')
|
|
||||||
for o in orders:logger.info(o.to_json())
|
|
||||||
logger.info(order.to_json())
|
|
||||||
sell_amount = order.safe_filled
|
sell_amount = order.safe_filled
|
||||||
sell_rate = order.safe_price
|
sell_rate = order.safe_price
|
||||||
sell_stake_amount = sell_rate * sell_amount * (1 - self.fee_close)
|
sell_stake_amount = sell_rate * sell_amount * (1 - self.fee_close)
|
||||||
if is_closed:
|
if is_closed:
|
||||||
if sell_amount >= self.amount:
|
if sell_amount == self.amount:
|
||||||
# Todo tests/rpc/test_rpc.py::test_rpc_trade_statistics
|
|
||||||
self.close(sell_rate)
|
self.close(sell_rate)
|
||||||
if is_non_bt: Trade.commit()
|
if is_non_bt: Trade.commit()
|
||||||
return
|
return
|
||||||
@ -541,8 +530,8 @@ class LocalTrade():
|
|||||||
idx = -1
|
idx = -1
|
||||||
while sell_amount:
|
while sell_amount:
|
||||||
b_order = orders[idx]
|
b_order = orders[idx]
|
||||||
buy_amount = b_order.filled or b_order.amount
|
buy_amount = b_order.safe_amount_after_fee
|
||||||
buy_rate = b_order.average or b_order.price
|
buy_rate = b_order.safe_price
|
||||||
if sell_amount < buy_amount:
|
if sell_amount < buy_amount:
|
||||||
amount = sell_amount
|
amount = sell_amount
|
||||||
else:
|
else:
|
||||||
@ -550,7 +539,6 @@ class LocalTrade():
|
|||||||
amount = buy_amount
|
amount = buy_amount
|
||||||
if is_closed:
|
if is_closed:
|
||||||
b_order.filled -= amount
|
b_order.filled -= amount
|
||||||
self.update_order(b_order)
|
|
||||||
sell_amount -= amount
|
sell_amount -= amount
|
||||||
profit += self.calc_profit2(buy_rate, sell_rate, amount)
|
profit += self.calc_profit2(buy_rate, sell_rate, amount)
|
||||||
if is_closed:
|
if is_closed:
|
||||||
@ -704,11 +692,9 @@ class LocalTrade():
|
|||||||
return float(f"{profit_ratio:.8f}")
|
return float(f"{profit_ratio:.8f}")
|
||||||
|
|
||||||
def recalc_trade_from_orders(self):
|
def recalc_trade_from_orders(self):
|
||||||
if len(self.select_filled_orders('buy')) < 2:
|
# mdebug
|
||||||
# Just in case, still recalc open trade value
|
# import json
|
||||||
# needs to remove
|
# logger.info(json.dumps(self.to_json(), indent =4))
|
||||||
self.recalc_open_trade_value()
|
|
||||||
return
|
|
||||||
total_amount = 0.0
|
total_amount = 0.0
|
||||||
total_stake = 0.0
|
total_stake = 0.0
|
||||||
for o in self.orders:
|
for o in self.orders:
|
||||||
@ -732,6 +718,7 @@ class LocalTrade():
|
|||||||
self.recalc_open_trade_value()
|
self.recalc_open_trade_value()
|
||||||
if self.stop_loss_pct is not None and self.open_rate is not None:
|
if self.stop_loss_pct is not None and self.open_rate is not None:
|
||||||
self.adjust_stop_loss(self.open_rate, self.stop_loss_pct)
|
self.adjust_stop_loss(self.open_rate, self.stop_loss_pct)
|
||||||
|
# logger.info(json.dumps(self.to_json(), indent =4))
|
||||||
|
|
||||||
def select_order_by_order_id(self, order_id: str) -> Optional[Order]:
|
def select_order_by_order_id(self, order_id: str) -> Optional[Order]:
|
||||||
"""
|
"""
|
||||||
|
@ -408,7 +408,7 @@ class Telegram(RPCHandler):
|
|||||||
for x, order in enumerate(filled_orders):
|
for x, order in enumerate(filled_orders):
|
||||||
cur_entry_datetime = arrow.get(order["order_filled_date"])
|
cur_entry_datetime = arrow.get(order["order_filled_date"])
|
||||||
cur_entry_amount = order["filled"] or order["amount"]
|
cur_entry_amount = order["filled"] or order["amount"]
|
||||||
cur_entry_average = order["safeprice"]
|
cur_entry_average = order["safe_price"]
|
||||||
lines.append(" ")
|
lines.append(" ")
|
||||||
if x == 0:
|
if x == 0:
|
||||||
lines.append(f"*Entry #{x+1}:*")
|
lines.append(f"*Entry #{x+1}:*")
|
||||||
|
@ -418,7 +418,7 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
|
|||||||
freqtradebot.enter_positions()
|
freqtradebot.enter_positions()
|
||||||
trade = Trade.query.first()
|
trade = Trade.query.first()
|
||||||
# Simulate fulfilled LIMIT_BUY order for trade
|
# Simulate fulfilled LIMIT_BUY order for trade
|
||||||
oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'sell')
|
oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy')
|
||||||
trade.update_trade(oobj)
|
trade.update_trade(oobj)
|
||||||
|
|
||||||
# Update the ticker with a market going up
|
# Update the ticker with a market going up
|
||||||
|
@ -1049,6 +1049,8 @@ def test_telegram_forcesell_handle(default_conf, update, ticker, fee,
|
|||||||
'open_date': ANY,
|
'open_date': ANY,
|
||||||
'close_date': ANY,
|
'close_date': ANY,
|
||||||
'close_rate': ANY,
|
'close_rate': ANY,
|
||||||
|
'stake_amount': 0.0009999999999054,
|
||||||
|
'sub_trade': False,
|
||||||
} == last_msg
|
} == last_msg
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,8 +227,7 @@ def test_edge_overrides_stoploss(limit_buy_order_usdt, fee, caplog, mocker,
|
|||||||
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
|
freqtrade.strategy.min_roi_reached = MagicMock(return_value=False)
|
||||||
freqtrade.enter_positions()
|
freqtrade.enter_positions()
|
||||||
trade = Trade.query.first()
|
trade = Trade.query.first()
|
||||||
oobj = Order.parse_from_ccxt_object(limit_buy_order_usdt, 'ADA/USDT', 'buy')
|
trade.open_rate = 2
|
||||||
trade.update_trade(oobj)
|
|
||||||
#############################################
|
#############################################
|
||||||
|
|
||||||
# stoploss shoud be hit
|
# stoploss shoud be hit
|
||||||
|
Loading…
Reference in New Issue
Block a user