Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lumibot/backtesting/backtesting_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ def _process_filled_order(self, order, price, quantity):
"""
BackTesting needs to create/update positions when orders are filled becuase there is no broker to do it
"""
# If the order has a "buy_to_open" or "buy_to_close" side, then we should change it to "buy"
if order.is_buy_order():
order.side = Order.OrderSide.BUY
# If the order has a "sell_to_open" or "sell_to_close" side, then we should change it to "sell"
if order.is_sell_order():
order.side = Order.OrderSide.SELL
Comment on lines +451 to +456

This comment was marked as resolved.

@grzesir grzesir Sep 17, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im not sure this is a good idea, this will return less data back to the user, no? it sounds like we will be pretending that buy_to_open order and buy_to_close would be the same thing. maybe im wrong, but we should be preserving those values. perhaps we can do this transformation somewhere else where do not have to modify the data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You raise a good point about preserving order type information. Let's explore alternatives that maintain order specificity while addressing the position tracking issue. Perhaps we could introduce a separate field for normalized sides used in position calculations, keeping the original order type intact. This would preserve data fidelity while ensuring consistent position tracking. What are your thoughts on this approach?

# This is a parent order, typically for a Multileg strategy. The parent order itself is expected to be
# filled after all child orders are filled.
if order.is_parent() and order.order_class in [Order.OrderClass.MULTILEG, Order.OrderClass.OCO]:
Expand Down
Loading