This commit is contained in:
2025-11-07 11:00:41 +08:00
parent d988f5eb48
commit b7f9d29c54
2 changed files with 15 additions and 11 deletions
+7 -3
View File
@@ -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(