update
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
[config]
|
[config]
|
||||||
miniQMTPath=D:\\Programs\\DTQMT\\userdata_mini
|
miniQMTPath=D:\\Programs\\DTQMT\\userdata_mini
|
||||||
; miniQMTPath=D:\\Programs\\DTQMT_MN\\userdata_mini ; 测试账号
|
; miniQMTPath=D:\\Programs\\DTQMT_MN\\userdata_mini ; 测试账号
|
||||||
grid_price=1.665,1.660,1.655,1.650,1.645,1.640,1.635,1.630,1.625,1.620,1.615
|
grid_price=1.665,1.660,1.655,1.650,1.645,1.640,1.635,1.630,1.625,1.620,1.615,1.610
|
||||||
; grid_price=11.0,10.0,9.0,8.0,7.0,6.0,5.0,4.0,3.0,2.0,1.0
|
; grid_price=11.0,10.0,9.0,8.0,7.0,6.0,5.0,4.0,3.0,2.0,1.0
|
||||||
grid_volume = 200
|
grid_volume = 200
|
||||||
account_no = '99082560'
|
account_no = '99082560'
|
||||||
|
|||||||
+17
-9
@@ -61,16 +61,16 @@ class SFGridStrategy:
|
|||||||
return bool(self.tradeTarget.enabled)
|
return bool(self.tradeTarget.enabled)
|
||||||
|
|
||||||
def onDataUpdate(self, data):
|
def onDataUpdate(self, data):
|
||||||
if not self.isEnabled():
|
print(f'|- 标的{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name} 市价更新-START')
|
||||||
return
|
|
||||||
self.dataUpdateLock.acquire()
|
self.dataUpdateLock.acquire()
|
||||||
|
try:
|
||||||
index = self.tradeTarget.grid_index
|
index = self.tradeTarget.grid_index
|
||||||
price = sfgrid_constants.grid_price[int(index)] # pyright: ignore[reportArgumentType]
|
price = sfgrid_constants.grid_price[int(index)] # pyright: ignore[reportArgumentType]
|
||||||
lowPrice = sfgrid_constants.grid_price[int(index) + 1] # pyright: ignore[reportArgumentType]
|
lowPrice = sfgrid_constants.grid_price[int(index) + 1] if len(sfgrid_constants.grid_price)>int(index) + 1 else -1.0 # pyright: ignore[reportArgumentType]
|
||||||
highPrice = sfgrid_constants.grid_price[int(index) - 1] # pyright: ignore[reportArgumentType]
|
highPrice = sfgrid_constants.grid_price[int(index) - 1] # pyright: ignore[reportArgumentType]
|
||||||
|
|
||||||
lastPrice = float("{:.3f}".format(data[self.tradeTarget.stock_code]['lastPrice']))
|
lastPrice = float("{:.3f}".format(data[self.tradeTarget.stock_code]['lastPrice']))
|
||||||
print(f"标的{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name} 市价: {lastPrice}, 网格序号: {index}, 网格价格: {price}, 计划多单价: {lowPrice}, 计划空单价: {highPrice}")
|
print(f"|- 标的{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name} 市价信息-价格: {lastPrice}, 网格序号: {index}, 网格价格: {price}, 计划多单价: {lowPrice}, 计划空单价: {highPrice}")
|
||||||
|
|
||||||
if lastPrice <= lowPrice: # 下下方多单
|
if lastPrice <= lowPrice: # 下下方多单
|
||||||
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)
|
||||||
@@ -89,7 +89,6 @@ class SFGridStrategy:
|
|||||||
self.getName(), # strategy_name
|
self.getName(), # strategy_name
|
||||||
self.tradeTarget.stock_code # remark # type: ignore
|
self.tradeTarget.stock_code # remark # type: ignore
|
||||||
)
|
)
|
||||||
self.tradeTarget.grid_index = int(index) + 1 # type: ignore
|
|
||||||
self.tradeTarget.current_buy_price = float(lowPrice) # type: ignore
|
self.tradeTarget.current_buy_price = float(lowPrice) # type: ignore
|
||||||
print(f' |- 下网格多单号 {self.tradeTarget.current_buy_order_no}, 网格基准价 {price}, 下单价 {lowPrice}, 下单量 {sfgrid_constants.grid_volume}')
|
print(f' |- 下网格多单号 {self.tradeTarget.current_buy_order_no}, 网格基准价 {price}, 下单价 {lowPrice}, 下单量 {sfgrid_constants.grid_volume}')
|
||||||
elif lastPrice == highPrice: # 下上方空单
|
elif lastPrice == highPrice: # 下上方空单
|
||||||
@@ -108,15 +107,19 @@ class SFGridStrategy:
|
|||||||
highPrice,
|
highPrice,
|
||||||
self.getName(),
|
self.getName(),
|
||||||
self.tradeTarget.stock_code) # type: ignore
|
self.tradeTarget.stock_code) # type: ignore
|
||||||
self.tradeTarget.grid_index = int(index) - 1 # type: ignore
|
|
||||||
self.tradeTarget.current_sell_price = float(highPrice) # type: ignore
|
self.tradeTarget.current_sell_price = float(highPrice) # type: ignore
|
||||||
print(f' |- 下网格空单号 {self.tradeTarget.current_sell_order_no}, 网格基准价 {price}, 下单价 {highPrice}, 下单量 {sfgrid_constants.grid_volume}')
|
print(f' |- 下网格空单号 {self.tradeTarget.current_sell_order_no}, 网格基准价 {price}, 下单价 {highPrice}, 下单量 {sfgrid_constants.grid_volume}')
|
||||||
self.tradeTarget.save()
|
self.tradeTarget.save()
|
||||||
|
finally:
|
||||||
|
print('onDataUpdate release lock')
|
||||||
self.dataUpdateLock.release()
|
self.dataUpdateLock.release()
|
||||||
|
print(f'|- 标的{self.tradeTarget.stock_code}-{self.tradeTarget.stock_name} 市价更新-END')
|
||||||
|
|
||||||
|
|
||||||
def onAsyncOrderResponse(self, order:XtOrderResponse):
|
def onAsyncOrderResponse(self, order:XtOrderResponse):
|
||||||
|
print(f' |- 委托下单回调')
|
||||||
self.dataUpdateLock.acquire()
|
self.dataUpdateLock.acquire()
|
||||||
|
try:
|
||||||
stockCode = order.order_remark
|
stockCode = order.order_remark
|
||||||
orderSeq = order.seq
|
orderSeq = order.seq
|
||||||
if (self.tradeTarget.status == 1): # 正常交易阶段订单下单成功
|
if (self.tradeTarget.status == 1): # 正常交易阶段订单下单成功
|
||||||
@@ -126,13 +129,16 @@ class SFGridStrategy:
|
|||||||
self.tradeTarget.current_sell_order_no = order.order_id
|
self.tradeTarget.current_sell_order_no = order.order_id
|
||||||
else:
|
else:
|
||||||
print(f' |- 委托回调: 委托单 {order.order_id} {stockCode} {orderSeq} 不在策略监控范围内')
|
print(f' |- 委托回调: 委托单 {order.order_id} {stockCode} {orderSeq} 不在策略监控范围内')
|
||||||
return
|
|
||||||
rc = self.tradeTarget.save()
|
rc = self.tradeTarget.save()
|
||||||
print(f' |- 委托下单成功[{rc}]: 委托单 {order.order_id} {stockCode} {orderSeq} ')
|
finally:
|
||||||
|
print('onAsyncOrderResponse release lock')
|
||||||
self.dataUpdateLock.release()
|
self.dataUpdateLock.release()
|
||||||
|
print(f' |- 委托下单成功[{rc}]: 委托单 {order.order_id} {stockCode} {orderSeq} ')
|
||||||
|
|
||||||
def onOrderTrade(self, trade:XtTrade):
|
def onOrderTrade(self, trade:XtTrade):
|
||||||
|
print(f' |- 委托成交通知')
|
||||||
self.dataUpdateLock.acquire()
|
self.dataUpdateLock.acquire()
|
||||||
|
try:
|
||||||
if int(self.tradeTarget.status) == 0 and trade.order_id == self.initBuyOrderId : # type: ignore
|
if int(self.tradeTarget.status) == 0 and trade.order_id == self.initBuyOrderId : # type: ignore
|
||||||
# 此时为建仓成交
|
# 此时为建仓成交
|
||||||
self.tradeTarget.current_position = int(self.tradeTarget.current_position) + trade.traded_volume # 当前持仓数,账户原有持仓不在策略范围内 # type: ignore
|
self.tradeTarget.current_position = int(self.tradeTarget.current_position) + trade.traded_volume # 当前持仓数,账户原有持仓不在策略范围内 # type: ignore
|
||||||
@@ -167,5 +173,7 @@ class SFGridStrategy:
|
|||||||
else:
|
else:
|
||||||
# 打印订单信息和订单状态
|
# 打印订单信息和订单状态
|
||||||
print(f'|- 非策略内部订单,或订单状态不满足监控条件 {trade.order_id} {trade.stock_code}-{trade.instrument_name} {trade.commission}')
|
print(f'|- 非策略内部订单,或订单状态不满足监控条件 {trade.order_id} {trade.stock_code}-{trade.instrument_name} {trade.commission}')
|
||||||
|
finally:
|
||||||
|
print('onOrderTrade release lock')
|
||||||
self.dataUpdateLock.release()
|
self.dataUpdateLock.release()
|
||||||
|
print(f' |- 委托成交处理完成 {trade.stock_code}')
|
||||||
|
|||||||
BIN
Binary file not shown.
Reference in New Issue
Block a user