update
This commit is contained in:
@@ -47,6 +47,7 @@ class SFGridStrategy:
|
|||||||
|
|
||||||
def refreshGridOrder(self): # 下网格单
|
def refreshGridOrder(self): # 下网格单
|
||||||
if not qmtv.isMarketActive or not self.tradeTarget.enabled:
|
if not qmtv.isMarketActive or not self.tradeTarget.enabled:
|
||||||
|
PrintLog(LogLevel.INFO, f'|- 市场 {qmtv.isMarketActive}, 策略 {self.getName()} {self.tradeTarget.enabled}, 不下单')
|
||||||
return
|
return
|
||||||
|
|
||||||
currentIdx:int = 0
|
currentIdx:int = 0
|
||||||
@@ -67,7 +68,7 @@ class SFGridStrategy:
|
|||||||
)
|
)
|
||||||
self.orderGrid[1] = tmpOrderSeq # seq
|
self.orderGrid[1] = tmpOrderSeq # seq
|
||||||
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 初始化: 建仓单,建仓价: {price:.3f}')
|
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 初始化: 建仓单,建仓价: {price:.3f}')
|
||||||
else:
|
elif self.tradeTarget.status == 1: # 下网格单
|
||||||
currentIdx = self.tradeTarget.grid_index # type: ignore
|
currentIdx = self.tradeTarget.grid_index # type: ignore
|
||||||
orders = qmtv.queryPendingOrder(self.tradeTarget.stock_code, self.getName()) # type: ignore
|
orders = qmtv.queryPendingOrder(self.tradeTarget.stock_code, self.getName()) # type: ignore
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ class SFGridStrategy:
|
|||||||
sellIdx = currentIdx - 1
|
sellIdx = currentIdx - 1
|
||||||
sellPrice = self.tradeTarget.getPriceGrid()[sellIdx]
|
sellPrice = self.tradeTarget.getPriceGrid()[sellIdx]
|
||||||
remark = f'{OrderTypeSell},{sellIdx},{self.tradeTarget.stock_code}'
|
remark = f'{OrderTypeSell},{sellIdx},{self.tradeTarget.stock_code}'
|
||||||
if len([order for order in orders if order.order_type == xtconstant.STOCK_SELL and order.price == sellPrice]) == 0:
|
if len([order for order in orders if order.order_remark == remark]) == 0: # 网格节点没有卖单,下单
|
||||||
# 不存在策略内同价位订单,下单
|
# 不存在策略内同价位订单,下单
|
||||||
tmpOrderSeq = qmtv.orderAsync(
|
tmpOrderSeq = qmtv.orderAsync(
|
||||||
str(self.tradeTarget.stock_code),
|
str(self.tradeTarget.stock_code),
|
||||||
@@ -88,10 +89,11 @@ class SFGridStrategy:
|
|||||||
self.getName(), # strategy_name
|
self.getName(), # strategy_name
|
||||||
)
|
)
|
||||||
self.orderGrid[sellIdx] = tmpOrderSeq # seq
|
self.orderGrid[sellIdx] = tmpOrderSeq # seq
|
||||||
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 初始化: 下空单,价格: {sellPrice:.3f}')
|
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 网格策略: 下空单,价格: {sellPrice:.3f}')
|
||||||
else:
|
else:
|
||||||
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 初始化: 已存在同价位空单,跳过下单')
|
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 网格策略: 已存在同价位空单,跳过下单')
|
||||||
if currentIdx < len(self.tradeTarget.getPriceGrid()) - 1: # 可以下多单
|
if currentIdx < len(self.tradeTarget.getPriceGrid()) - 1: # 可以下多单
|
||||||
|
print(f'length: {len(self.tradeTarget.getPriceGrid())}, currentIdx = {currentIdx}')
|
||||||
buyIdx = currentIdx + 1
|
buyIdx = currentIdx + 1
|
||||||
buyPrice = self.tradeTarget.getPriceGrid()[buyIdx]
|
buyPrice = self.tradeTarget.getPriceGrid()[buyIdx]
|
||||||
remark = f'{OrderTypeInit},{buyIdx},{self.tradeTarget.stock_code}'
|
remark = f'{OrderTypeInit},{buyIdx},{self.tradeTarget.stock_code}'
|
||||||
@@ -106,9 +108,11 @@ class SFGridStrategy:
|
|||||||
self.getName(), # strategy_name
|
self.getName(), # strategy_name
|
||||||
)
|
)
|
||||||
self.orderGrid[buyIdx] = tmpOrderSeq # seq
|
self.orderGrid[buyIdx] = tmpOrderSeq # seq
|
||||||
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 初始化: 下多单,价格: {buyPrice:.3f}')
|
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 网格策略: 下多单,价格: {buyPrice:.3f}')
|
||||||
else:
|
else:
|
||||||
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 初始化: 已存在同价位多单,跳过下单')
|
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 网格策略: 已存在同价位多单,跳过下单')
|
||||||
|
else:
|
||||||
|
PrintLog(LogLevel.INFO, f'|- 标的[{self.tradeTarget.targetName()}] 网格策略: 已过下边界,停止多单交易')
|
||||||
|
|
||||||
def deleteTradeTarget(self, tradeTarget:model.SFGridTradeTarget):
|
def deleteTradeTarget(self, tradeTarget:model.SFGridTradeTarget):
|
||||||
PrintLog(LogLevel.INFO, f'|- 标的{tradeTarget.targetName()}信息删除: START')
|
PrintLog(LogLevel.INFO, f'|- 标的{tradeTarget.targetName()}信息删除: START')
|
||||||
@@ -196,7 +200,7 @@ class SFGridStrategy:
|
|||||||
self.tradeTarget.grid_match_count += 1
|
self.tradeTarget.grid_match_count += 1
|
||||||
self.tradeTarget.grid_total_profit += self.tradeTarget.grid_size * trade.traded_volume
|
self.tradeTarget.grid_total_profit += self.tradeTarget.grid_size * trade.traded_volume
|
||||||
self.tradeTarget.grid_index -= 1
|
self.tradeTarget.grid_index -= 1
|
||||||
elif gridIdx == self.tradeTarget.grid_index:
|
else:
|
||||||
type = "保持格, 理论上不应该输出"
|
type = "保持格, 理论上不应该输出"
|
||||||
PrintLog(LogLevel.INFO, f'|- 委托成交通知[{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name} - 原网格位置 {oriIdx}, 现网格位置 {self.tradeTarget.grid_index}')
|
PrintLog(LogLevel.INFO, f'|- 委托成交通知[{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name} - 原网格位置 {oriIdx}, 现网格位置 {self.tradeTarget.grid_index}')
|
||||||
|
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ class TradeTargetUI(ttk.Frame):
|
|||||||
self.tradeTargetData[id] = target
|
self.tradeTargetData[id] = target
|
||||||
|
|
||||||
if id not in self.strategy_ctrl:
|
if id not in self.strategy_ctrl:
|
||||||
|
self.targetAvgPrice[id] = 0.0
|
||||||
self.stockCodeIdMap[target.stock_code] = id # type: ignore
|
self.stockCodeIdMap[target.stock_code] = id # type: ignore
|
||||||
self.strategy_ctrl[id] = SFGridStrategy(target) # pyright: ignore[reportArgumentType]
|
self.strategy_ctrl[id] = SFGridStrategy(target) # pyright: ignore[reportArgumentType]
|
||||||
|
|
||||||
@@ -283,7 +284,7 @@ class TradeTargetUI(ttk.Frame):
|
|||||||
|
|
||||||
values = [
|
values = [
|
||||||
time_str,
|
time_str,
|
||||||
data['stock_name']+f"{stock_code}",
|
data['stock_name']+f"-{stock_code}",
|
||||||
f"{data['last_price']:.3f}",
|
f"{data['last_price']:.3f}",
|
||||||
stock_code
|
stock_code
|
||||||
]
|
]
|
||||||
@@ -342,7 +343,7 @@ class TradeTargetUI(ttk.Frame):
|
|||||||
f"{self.targetMarketPrice[id]:.3f}" if id in self.targetMarketPrice else '-', # "市场价"
|
f"{self.targetMarketPrice[id]:.3f}" if id in self.targetMarketPrice else '-', # "市场价"
|
||||||
target.current_position, # "当前持仓"
|
target.current_position, # "当前持仓"
|
||||||
'-' if target.init_price is None else f"{target.init_price:.3f}", # "建仓成本"
|
'-' if target.init_price is None else f"{target.init_price:.3f}", # "建仓成本"
|
||||||
f"{self.targetAvgPrice[id]:.3f}" if id in self.targetMarketPrice else '-', # "平均成本"
|
'-' if id not in self.targetMarketPrice else f"{self.targetAvgPrice[id]:.3f}", # "平均成本"
|
||||||
target.grid_match_count, # "网格匹配次数"
|
target.grid_match_count, # "网格匹配次数"
|
||||||
f"{target.grid_total_profit:.3f}", # "网格收益"
|
f"{target.grid_total_profit:.3f}", # "网格收益"
|
||||||
self.get_trade_enabled_indicator(target.enabled) # type: ignore
|
self.get_trade_enabled_indicator(target.enabled) # type: ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user