From b7f9d29c5413027bd1b30a7708cfbd4640aa6b8c Mon Sep 17 00:00:00 2001 From: "GDP\\solonot" Date: Fri, 7 Nov 2025 11:00:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/sfgrid_strategy.py | 10 +++++++--- core/ui.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/core/sfgrid_strategy.py b/core/sfgrid_strategy.py index f4439c7..fe53e1c 100644 --- a/core/sfgrid_strategy.py +++ b/core/sfgrid_strategy.py @@ -4,7 +4,7 @@ from peewee import IntegerField from core import strategy_db from core.eventbus import MarketDataUpdate, event_bus from core.strategy_db import OrderTypeBuy, OrderTypeInit, OrderTypeSell, TradeTarget -from core.util import queryPendingOrder +from core.util import queryPendingOrder, is_trading_time from xtquant import xttrader, xtconstant from xtquant.xttype import StockAccount, XtOrder, XtTrade @@ -59,6 +59,10 @@ class SFGridStrategy: self.tradeTarget.market_price = lastPrice # type: ignore self.saveProxy() + if not is_trading_time(): + print(f"|- 市价更新[{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name}] - 非交易时间,不进行自动交易") + return + if not self.tradeTarget.enabled: # 未建仓,自动交易暂停 print(f"|- 市价更新[{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name}] - 未建仓或交易监控暂停,不进行自动交易") return @@ -74,7 +78,7 @@ class SFGridStrategy: gridBasePrice = -1 if index>=len(sfgrid_constants.grid_price) or index < 0 else sfgrid_constants.grid_price[int(index)] # pyright: ignore[reportArgumentType] - if self.tradeTarget.enabled and self.tradeTarget.status == 0: # 已启用,未建仓,建仓 + if self.tradeTarget.enabled and self.tradeTarget.status == 0 and lastPrice <= sfgrid_constants.grid_price[1]: # 已启用,未建仓,建仓 orderPrice = sfgrid_constants.grid_price[index] orderType = xtconstant.STOCK_BUY orderRemark = OrderTypeInit @@ -97,7 +101,7 @@ class SFGridStrategy: orders = queryPendingOrder(str(self.tradeTarget.stock_code), self.getName(), self.xt_trader, self.account) if len([order for order in orders if order.order_type == orderType and order.price == orderPrice]) > 0: # 已存在未交易的多单 - print(f' |- 已存在未交易的{"多单" if orderType == xtconstant.STOCK_BUY else "空单"},不重复下单') + print(f' |- [{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name}]已存在未交易的{"多单" if orderType == xtconstant.STOCK_BUY else "空单"},不重复下单') else: print(f' |- 下网格{"多单" if orderType == xtconstant.STOCK_BUY else "空单"}') self.tradeTarget.current_order_no = self.xt_trader.order_stock_async( diff --git a/core/ui.py b/core/ui.py index 54fcbb1..38bcac5 100644 --- a/core/ui.py +++ b/core/ui.py @@ -113,14 +113,14 @@ class TradeTargetUI: # 市场数据监听开关 self.market_data_switch_var = tk.BooleanVar(value=False) - self.market_data_switch = ttk.Checkbutton( - toolbar_frame, - text="📊 市场数据", - variable=self.market_data_switch_var, - command=self.toggle_market_data, - width=12 - ) - self.market_data_switch.pack(side=tk.LEFT, padx=2) + # self.market_data_switch = ttk.Checkbutton( + # toolbar_frame, + # text="📊 市场数据", + # variable=self.market_data_switch_var, + # command=self.toggle_market_data, + # width=12 + # ) + # self.market_data_switch.pack(side=tk.LEFT, padx=2) # 日志显示/隐藏按钮 self.log_toggle_btn = ttk.Button(toolbar_frame, text="📋 显示日志",