|
27 | 27 | from tradix.events.fill import FillEvent |
28 | 28 | from tradix.broker.commission import CommissionModel, KoreaStockCommission |
29 | 29 | from tradix.broker.slippage import SlippageModel, PercentSlippage |
30 | | -from tradix.broker.fill import FillModel, CloseFill |
| 30 | +from tradix.broker.fill import FillModel, CloseFill, OpenFill |
31 | 31 |
|
32 | 32 |
|
33 | 33 | @dataclass |
@@ -89,7 +89,33 @@ def processOrder(self, order: Order, bar: Bar) -> FillEvent: |
89 | 89 | commission, and slippage details. Returns zero-filled |
90 | 90 | event if fill price is non-positive. |
91 | 91 | """ |
92 | | - basePrice = self.fillModel.getFillPrice(order, bar) |
| 92 | + return self._processWithFillModel(order, bar, self.fillModel) |
| 93 | + |
| 94 | + def processOrderAtOpen(self, order: Order, bar: Bar) -> FillEvent: |
| 95 | + """ |
| 96 | + Process an order using the bar's opening price. |
| 97 | +
|
| 98 | + BacktestEngine fills queued market orders on the next bar's open to |
| 99 | + prevent look-ahead bias. This method gives BrokerSimulator the same |
| 100 | + contract as the legacy SimpleBroker used by the engine. |
| 101 | +
|
| 102 | + Args: |
| 103 | + order (Order): The order to execute. 실행할 주문. |
| 104 | + bar (Bar): Current bar data for price reference. 현재 바 데이터. |
| 105 | +
|
| 106 | + Returns: |
| 107 | + FillEvent: Fill generated from the bar's open price. |
| 108 | + """ |
| 109 | + return self._processWithFillModel(order, bar, OpenFill()) |
| 110 | + |
| 111 | + def _processWithFillModel( |
| 112 | + self, |
| 113 | + order: Order, |
| 114 | + bar: Bar, |
| 115 | + fillModel: FillModel, |
| 116 | + ) -> FillEvent: |
| 117 | + """Generate a fill event using the supplied fill model.""" |
| 118 | + basePrice = fillModel.getFillPrice(order, bar) |
93 | 119 |
|
94 | 120 | if basePrice <= 0: |
95 | 121 | return FillEvent( |
|
0 commit comments