3 分钟快速生成代码
输入想法,AI 即刻生成可运行代码
在 QMT(迅投量化/国信 QMT)平台中,smart_algo_passorder 函数提供了智能算法交易支持,能够实现如 DMA(Direct Market Access 快捷拆单)、VWAP、TWAP、冰山(ICEBERG)等多种智能算法下单,有效降低大单对市场的冲击成本并提升执行效率。
smart_algo_passorder 的基本调用格式如下:
smart_algo_passorder(
opType,
orderType,
accountid,
orderCode,
prType,
modelprice,
volume,
strategyName,
quickTrade,
userOrderId,
smartAlgoType,
limitOverRate,
minAmountPerOrder,
ContextInfo
)
23 代表股票买入,24 代表股票卖出,27 融资买入,28 融券卖出等。1101 代表单股、单账号、普通、股/手方式下单。'000001.SZ')。5 为最新价,11 为指定价格(模型价),14 为对手价等。prType 为 11 时生效,其他填 -1 或价格)。passorder,此处不可缺省)。0 否,1 是(在最新 Bar/Tick 触发下单)。'DMA'。以下示例展示了如何在盘中触发时,利用 smart_algo_passorder 开启 DMA 快捷拆单买入股票:
#encoding:gbk
def init(ContextInfo):
# 设置资金账号
ContextInfo.accID = '6000000105'
ContextInfo.set_account(ContextInfo.accID)
ContextInfo.set_universe(['000001.SZ'])
def handlebar(ContextInfo):
# 仅在最后一根 Bar(实时最新行情)上判定并执行算法下单
if not ContextInfo.is_last_bar():
return
stock_code = '000001.SZ'
# 使用 DMA 快捷拆单算法买入 50,000 股
# 参数说明:
# opType=23 (股票买入), orderType=1101 (单股股数模式)
# prType=5 (最新价), modelprice=-1, volume=50000
# strategyName='DMA_Strategy', quickTrade=1 (立即下单), userOrderId='dma_001'
# smartAlgoType='DMA', limitOverRate=20 (量比20%), minAmountPerOrder=0
smart_algo_passorder(
23,
1101,
ContextInfo.accID,
stock_code,
5,
-1,
50000,
"DMA_Strategy",
1,
"dma_001",
"DMA",
20,
0,
ContextInfo
)
print(f"[DMA下单] 成功对 {stock_code} 发起 DMA 快捷拆单买入任务!")
passorder 不同,smart_algo_passorder 中的 strategyName 和 userOrderId 不能缺省。init 函数中使用 ContextInfo.set_account() 绑定交易账号,以确保订单任务正常推送与执行。