Add first version to fill orders "later" in backtesting
This commit is contained in:
parent
c12e5a3b6c
commit
f7a1cabe23
@ -670,10 +670,11 @@ class Backtesting:
|
|||||||
for open_trade in list(open_trades[pair]):
|
for open_trade in list(open_trades[pair]):
|
||||||
# TODO: should open orders be stored in a separate list?
|
# TODO: should open orders be stored in a separate list?
|
||||||
if open_trade.open_order_id:
|
if open_trade.open_order_id:
|
||||||
# FIXME: check order filling
|
order = open_trade.select_order(is_open=True)
|
||||||
# * Get open order
|
# Check for timeout!!
|
||||||
# * check if filled
|
if self._get_order_filled(order.price):
|
||||||
open_trade.open_order_id = None
|
open_trade.open_order_id = None
|
||||||
|
order.ft_is_open = False
|
||||||
|
|
||||||
# without positionstacking, we can only have one open trade per pair.
|
# without positionstacking, we can only have one open trade per pair.
|
||||||
# max_open_trades must be respected
|
# max_open_trades must be respected
|
||||||
@ -698,6 +699,9 @@ class Backtesting:
|
|||||||
LocalTrade.add_bt_trade(trade)
|
LocalTrade.add_bt_trade(trade)
|
||||||
|
|
||||||
for trade in list(open_trades[pair]):
|
for trade in list(open_trades[pair]):
|
||||||
|
# TODO: This could be avoided with a separate list
|
||||||
|
if trade.open_order_id:
|
||||||
|
continue
|
||||||
# also check the buying candle for sell conditions.
|
# also check the buying candle for sell conditions.
|
||||||
trade_entry = self._get_sell_trade_entry(trade, row)
|
trade_entry = self._get_sell_trade_entry(trade, row)
|
||||||
# Sell occurred
|
# Sell occurred
|
||||||
|
@ -635,13 +635,16 @@ class LocalTrade():
|
|||||||
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)
|
||||||
|
|
||||||
def select_order(self, order_side: str, is_open: Optional[bool]) -> Optional[Order]:
|
def select_order(
|
||||||
|
self, order_side: str = None, is_open: Optional[bool] = None) -> Optional[Order]:
|
||||||
"""
|
"""
|
||||||
Finds latest order for this orderside and status
|
Finds latest order for this orderside and status
|
||||||
:param order_side: Side of the order (either 'buy' or 'sell')
|
:param order_side: Side of the order (either 'buy' or 'sell')
|
||||||
:param is_open: Only search for open orders?
|
:param is_open: Only search for open orders?
|
||||||
:return: latest Order object if it exists, else None
|
:return: latest Order object if it exists, else None
|
||||||
"""
|
"""
|
||||||
|
orders = self.orders
|
||||||
|
if order_side:
|
||||||
orders = [o for o in self.orders if o.side == order_side]
|
orders = [o for o in self.orders if o.side == order_side]
|
||||||
if is_open is not None:
|
if is_open is not None:
|
||||||
orders = [o for o in orders if o.ft_is_open == is_open]
|
orders = [o for o in orders if o.ft_is_open == is_open]
|
||||||
|
Loading…
Reference in New Issue
Block a user