调试
This commit is contained in:
@@ -4,7 +4,7 @@ from peewee import IntegerField
|
|||||||
from core import strategy_db
|
from core import strategy_db
|
||||||
from core.eventbus import MarketDataUpdate, event_bus
|
from core.eventbus import MarketDataUpdate, event_bus
|
||||||
from core.strategy_db import OrderTypeBuy, OrderTypeInit, OrderTypeSell, TradeTarget
|
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 import xttrader, xtconstant
|
||||||
from xtquant.xttype import StockAccount, XtOrder, XtTrade
|
from xtquant.xttype import StockAccount, XtOrder, XtTrade
|
||||||
@@ -59,6 +59,10 @@ class SFGridStrategy:
|
|||||||
self.tradeTarget.market_price = lastPrice # type: ignore
|
self.tradeTarget.market_price = lastPrice # type: ignore
|
||||||
self.saveProxy()
|
self.saveProxy()
|
||||||
|
|
||||||
|
if not is_trading_time():
|
||||||
|
print(f"|- 市价更新[{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name}] - 非交易时间,不进行自动交易")
|
||||||
|
return
|
||||||
|
|
||||||
if not self.tradeTarget.enabled: # 未建仓,自动交易暂停
|
if not self.tradeTarget.enabled: # 未建仓,自动交易暂停
|
||||||
print(f"|- 市价更新[{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name}] - 未建仓或交易监控暂停,不进行自动交易")
|
print(f"|- 市价更新[{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name}] - 未建仓或交易监控暂停,不进行自动交易")
|
||||||
return
|
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]
|
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]
|
orderPrice = sfgrid_constants.grid_price[index]
|
||||||
orderType = xtconstant.STOCK_BUY
|
orderType = xtconstant.STOCK_BUY
|
||||||
orderRemark = OrderTypeInit
|
orderRemark = OrderTypeInit
|
||||||
@@ -97,7 +101,7 @@ class SFGridStrategy:
|
|||||||
orders = queryPendingOrder(str(self.tradeTarget.stock_code), self.getName(), self.xt_trader, self.account)
|
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:
|
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:
|
else:
|
||||||
print(f' |- 下网格{"多单" if orderType == xtconstant.STOCK_BUY else "空单"}')
|
print(f' |- 下网格{"多单" if orderType == xtconstant.STOCK_BUY else "空单"}')
|
||||||
self.tradeTarget.current_order_no = self.xt_trader.order_stock_async(
|
self.tradeTarget.current_order_no = self.xt_trader.order_stock_async(
|
||||||
|
|||||||
+8
-8
@@ -113,14 +113,14 @@ class TradeTargetUI:
|
|||||||
|
|
||||||
# 市场数据监听开关
|
# 市场数据监听开关
|
||||||
self.market_data_switch_var = tk.BooleanVar(value=False)
|
self.market_data_switch_var = tk.BooleanVar(value=False)
|
||||||
self.market_data_switch = ttk.Checkbutton(
|
# self.market_data_switch = ttk.Checkbutton(
|
||||||
toolbar_frame,
|
# toolbar_frame,
|
||||||
text="📊 市场数据",
|
# text="📊 市场数据",
|
||||||
variable=self.market_data_switch_var,
|
# variable=self.market_data_switch_var,
|
||||||
command=self.toggle_market_data,
|
# command=self.toggle_market_data,
|
||||||
width=12
|
# width=12
|
||||||
)
|
# )
|
||||||
self.market_data_switch.pack(side=tk.LEFT, padx=2)
|
# self.market_data_switch.pack(side=tk.LEFT, padx=2)
|
||||||
|
|
||||||
# 日志显示/隐藏按钮
|
# 日志显示/隐藏按钮
|
||||||
self.log_toggle_btn = ttk.Button(toolbar_frame, text="📋 显示日志",
|
self.log_toggle_btn = ttk.Button(toolbar_frame, text="📋 显示日志",
|
||||||
|
|||||||
Reference in New Issue
Block a user