tqsdk实盘
This commit is contained in:
@@ -42,6 +42,7 @@ class ExecutionSimulator:
|
||||
self.trade_log: List[Trade] = []
|
||||
self.pending_orders: Dict[str, Order] = {}
|
||||
self._current_time: Optional[datetime] = None
|
||||
self.indicator_dict = {}
|
||||
|
||||
print(
|
||||
f"模拟器初始化:初始资金={self.initial_capital:.2f}, 滑点率={self.slippage_rate}, 佣金率={self.commission_rate}"
|
||||
@@ -117,7 +118,7 @@ class ExecutionSimulator:
|
||||
self.pending_orders[order.id] = order
|
||||
return order
|
||||
|
||||
def process_pending_orders(self, current_bar: Bar):
|
||||
def process_pending_orders(self, current_bar: Bar, indicator_dict: Dict[str, float]):
|
||||
"""
|
||||
处理所有待撮合的订单。在每个K线数据到来时调用。
|
||||
"""
|
||||
@@ -132,7 +133,16 @@ class ExecutionSimulator:
|
||||
if order.symbol != current_bar.symbol:
|
||||
continue
|
||||
|
||||
self._execute_single_order(order, current_bar)
|
||||
trade = self._execute_single_order(order, current_bar)
|
||||
if trade:
|
||||
self.trade_log.append(trade)
|
||||
|
||||
if trade.is_open_trade:
|
||||
self.indicator_dict = indicator_dict
|
||||
elif trade.is_close_trade:
|
||||
trade.indicator_dict = self.indicator_dict.copy()
|
||||
|
||||
|
||||
|
||||
def _execute_single_order(self, order: Order, current_bar: Bar) -> Optional[Trade]:
|
||||
"""
|
||||
@@ -295,7 +305,6 @@ class ExecutionSimulator:
|
||||
is_open_trade=is_trade_an_open_operation,
|
||||
is_close_trade=is_trade_a_close_operation,
|
||||
)
|
||||
self.trade_log.append(executed_trade)
|
||||
|
||||
if order.id in self.pending_orders:
|
||||
del self.pending_orders[order.id]
|
||||
|
||||
Reference in New Issue
Block a user