mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
add comments and logs for failing test, create untied_assets propertyto Trade
This commit is contained in:
parent
79ce1ddaef
commit
730bef2920
|
@ -178,6 +178,7 @@ class Order(ModelBase):
|
||||||
return (
|
return (
|
||||||
f"Order(id={self.id}, trade={self.ft_trade_id}, order_id={self.order_id}, "
|
f"Order(id={self.id}, trade={self.ft_trade_id}, order_id={self.order_id}, "
|
||||||
f"side={self.side}, filled={self.safe_filled}, price={self.safe_price}, "
|
f"side={self.side}, filled={self.safe_filled}, price={self.safe_price}, "
|
||||||
|
f"amount={self.amount}, "
|
||||||
f"status={self.status}, date={self.order_date_utc:{DATETIME_PRINT_FORMAT}})"
|
f"status={self.status}, date={self.order_date_utc:{DATETIME_PRINT_FORMAT}})"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -616,10 +617,7 @@ class LocalTrade:
|
||||||
return (entry_orders_filled_qty - exit_orders_filled_qty) > 0
|
return (entry_orders_filled_qty - exit_orders_filled_qty) > 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def has_untied_assets(self) -> bool:
|
def untied_assets(self) -> float:
|
||||||
"""
|
|
||||||
True if there is still remaining position not yet tied up to exit order
|
|
||||||
"""
|
|
||||||
entry_orders = [
|
entry_orders = [
|
||||||
o for o in self.orders
|
o for o in self.orders
|
||||||
if o.ft_order_side == self.entry_side
|
if o.ft_order_side == self.entry_side
|
||||||
|
@ -633,7 +631,21 @@ class LocalTrade:
|
||||||
exit_orders_remaining_qty = sum(exo.safe_remaining for exo in exit_orders)
|
exit_orders_remaining_qty = sum(exo.safe_remaining for exo in exit_orders)
|
||||||
untied_remaining = entry_orders_filled_qty - exit_orders_remaining_qty
|
untied_remaining = entry_orders_filled_qty - exit_orders_remaining_qty
|
||||||
|
|
||||||
return untied_remaining > 0
|
logger.info(f"entry_orders: {entry_orders}")
|
||||||
|
logger.info(f"exit_orders: {exit_orders}")
|
||||||
|
logger.info(f"entry_orders_filled_qty: {entry_orders_filled_qty}")
|
||||||
|
logger.info(f"exit_orders_remaining_qty: {exit_orders_remaining_qty}")
|
||||||
|
|
||||||
|
logger.info(f"untied_remaining: {untied_remaining}")
|
||||||
|
|
||||||
|
return untied_remaining
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_untied_assets(self) -> bool:
|
||||||
|
"""
|
||||||
|
True if there is still remaining position not yet tied up to exit order
|
||||||
|
"""
|
||||||
|
return self.untied_assets > 0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def open_sl_orders(self) -> List[Order]:
|
def open_sl_orders(self) -> List[Order]:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import time
|
import time
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
@ -347,8 +348,8 @@ def test_dca_short(default_conf_usdt, ticker_usdt, fee, mocker) -> None:
|
||||||
assert trade.nr_of_successful_exits == 1
|
assert trade.nr_of_successful_exits == 1
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("leverage", [1, 2])
|
@pytest.mark.parametrize("leverage", [1])
|
||||||
def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker) -> None:
|
def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker, caplog) -> None:
|
||||||
default_conf_usdt["position_adjustment_enable"] = True
|
default_conf_usdt["position_adjustment_enable"] = True
|
||||||
default_conf_usdt["trading_mode"] = "futures"
|
default_conf_usdt["trading_mode"] = "futures"
|
||||||
default_conf_usdt["margin_mode"] = "isolated"
|
default_conf_usdt["margin_mode"] = "isolated"
|
||||||
|
@ -478,9 +479,24 @@ def test_dca_order_adjust(default_conf_usdt, ticker_usdt, leverage, fee, mocker)
|
||||||
assert pytest.approx(trade.amount) == 91.689215 * leverage
|
assert pytest.approx(trade.amount) == 91.689215 * leverage
|
||||||
assert pytest.approx(trade.orders[-1].amount) == 91.689215 * leverage
|
assert pytest.approx(trade.orders[-1].amount) == 91.689215 * leverage
|
||||||
assert freqtrade.strategy.adjust_entry_price.call_count == 0
|
assert freqtrade.strategy.adjust_entry_price.call_count == 0
|
||||||
|
|
||||||
|
print("BEFORE Process trade.orders")
|
||||||
|
print(trade.orders)
|
||||||
|
|
||||||
|
# adding this will prevent the second exit order creation, but this test case must be handled properly
|
||||||
|
#freqtrade.strategy.custom_exit = MagicMock(return_value=None)
|
||||||
|
|
||||||
|
caplog.clear()
|
||||||
|
caplog.set_level(logging.DEBUG)
|
||||||
# Process again, should not adjust entry price
|
# Process again, should not adjust entry price
|
||||||
freqtrade.process()
|
freqtrade.process()
|
||||||
trade = Trade.get_trades().first()
|
trade = Trade.get_trades().first()
|
||||||
|
|
||||||
|
print(f"DEBUG TEST")
|
||||||
|
print(caplog.text)
|
||||||
|
print("AFTER Process trade.orders")
|
||||||
|
print(trade.orders)
|
||||||
|
|
||||||
assert len(trade.orders) == 5
|
assert len(trade.orders) == 5
|
||||||
assert trade.orders[-1].status == "open"
|
assert trade.orders[-1].status == "open"
|
||||||
assert trade.orders[-1].price == 2.02
|
assert trade.orders[-1].price == 2.02
|
||||||
|
|
Loading…
Reference in New Issue
Block a user