欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件高级功能研发区 → 编写了一个套利的vba程序框架模板,感兴趣的朋友可以在此基础上做进一步开发

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有27276人关注过本帖树形打印复制链接

主题:编写了一个套利的vba程序框架模板,感兴趣的朋友可以在此基础上做进一步开发

帅哥哟,离线,有人找我吗?
abqqe
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:10 积分:53 威望:0 精华:0 注册:2011/7/12 10:47:57
  发帖心情 Post By:2011/7/14 9:49:17 [显示全部帖子]

有没有 “品种市场“ 所代表的交易所的代码吗? 如上图 ZQ 是代表郑州吧? 还是有别的意义?

 回到顶部
帅哥哟,离线,有人找我吗?
abqqe
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:10 积分:53 威望:0 精华:0 注册:2011/7/12 10:47:57
  发帖心情 Post By:2011/7/28 10:57:16 [显示全部帖子]

楼主的VBA 的代码很长,有很多我都看不明白。希望能注释一下。 dim kongjian k dim count count=0 dim pingcang pingcang="" '全局变量 dim exce1 dim report1ComboBox1 dim report2ComboBox1 report1ComboBox1=taoli_report1ComboBox.value report2ComboBox1=taoli_report2ComboBox.value dim report1 dim report2 set report1=nothing set report2=nothing Sub MARKETDATA_ReportNotify(ReportData) '显示自定义的最新价格 display if not report1 is nothing and not report2 is nothing then taoli_Label1.caption=Report1.newprice taoli_Label2.caption=Report2.newprice taoli_chajia.caption= Report1.newprice-Report2.newprice end if '如果有订单为成交,则撤销,以免影响批量下单的进度 if not report1 is nothing and not report2 is nothing then num1=0 '使用于ctp平仓功能变量 num2=0 '使用于ib平仓功能变量 ctp=Order.StockType(report1.Label,report1.marketName) if ctp=1 then num1=Order.OrderInfoByCode2(report1.Label,report1.marketName, OrderID1, ConSign, Filled, R1, Action, OrderType, LmtPrice, Account, Kaiping) num2=Order.OrderInfoByCode2(report2.Label,report2.marketName, OrderID2, ConSign, Filled, R2, Action, OrderType, LmtPrice, Account, Kaiping) elseif ctp=0 then num1=Order.OrderInfoByCode(report1.Label,report1.marketName, OrderID1, ConSign, Filled, R1, Action, OrderType, LmtPrice, Account, Kaiping) num2=Order.OrderInfoByCode(report2.Label,report2.marketName, OrderID2, ConSign, Filled, R2, Action, OrderType, LmtPrice, Account, Kaiping) end if if num1=1 or num2=1 then 'application.MsgOut count&" 检测撤单中 "&OrderID1 count=count+1 if count=5 then num11=0 num12=0 ctp=Order.StockType(report1.Label,report1.marketName) if ctp=1 then num11=Order.OrderInfoByCode2(report1.Label,report1.marketName, OrderID3, ConSign, Filled, R1, Action, OrderType, LmtPrice, Account, Kaiping) num12=Order.OrderInfoByCode2(report2.Label,report2.marketName, OrderID4, ConSign, Filled, R2, Action, OrderType, LmtPrice, Account, Kaiping) elseif ctp=0 then num11=Order.OrderInfoByCode(report1.Label,report1.marketName, OrderID3, ConSign, Filled, R1, Action, OrderType, LmtPrice, Account, Kaiping) num12=Order.OrderInfoByCode(report2.Label,report2.marketName, OrderID4, ConSign, Filled, R2, Action, OrderType, LmtPrice, Account, Kaiping) end if if num11=1 and OrderID1=OrderID3 then call Order.CancelOrder(OrderID3) 'application.MsgOut time()&" "&report1.Label&" "&OrderId1&" 111 chedan"&OrderID3 end if if num12=1 and OrderID2=OrderID4 then call Order.CancelOrder(OrderID4) 'application.MsgOut time()&" "&report2.Label&" "&OrderId2&" 222 chedan"&OrderID4 end if k执行" and not report1 is nothing and taoli_term1price<>"" and taoli_term1num<>"" and taoli_term1cleanprice<>"" then '第一条件的执行 diffbuy1=0 diffsell1=0 BuyHoding1=0 SellHoding1=0 chicang=0 ctp=Order.StockType(report1.Label,report1.marketName) if ctp=1 then call Order.HoldingInfoByCode2(report1.Label,report1.marketName,BuyHoding1,BuyCost,BuyTodayHoding1,SellHoding1,SellCost,SellTodayHoding1,PNL,UseMargin) elseif ctp=0 then call Order.HoldingInfoByCode(report1.Label,report1.marketName, Hold, MktPrice, AvgPrice, MktValue, AgeCost, PNL) if hold>0 then BuyHoding1=Hold end if if hold<0 then sellhoding1="-hold" end="end" if="if" end="end" if="if" diffbuy1="taoli_term1num.value-BuyHoding1 " diffsell1="taoli_term1num.value-SellHoding1 " diff="Report1.newprice-Report2.newprice-taoli_term1price " if="if" instr(taoli_term1ComboBox.value,"大于") <> 0 and diff>0 and k then '下列语句在满足条件1 大于实际差价情况下,只对品种1来判断操作,品种2的操作时事件触发 if instr(report1ComboBox1,"买入") <> 0 and diffbuy1>0 then call Order.Buy(0,1,Report1.SellPrice1,0,Report1.label,Report1.marketname,"",0) k卖出") <> 0 and diffsell1>0 then call Order.BuyShort(0,1,Report1.BuyPrice1,0,Report1.label,Report1.marketname,"",0) k小于") <> 0 and diff<0 and="and" k="k" then '下列语句在满足条件1 大于实际差价情况下,只对品种1来判断操作,品种2的操作时事件触发 if="if" instr(report1ComboBox1,"买入") <> 0 and diffbuy1>0 then call Order.Buy(0,1,Report1.SellPrice1,0,Report1.label,Report1.marketname,"",0) k卖出") <> 0 and diffsell1>0 then call Order.BuyShort(0,1,Report1.BuyPrice1,0,Report1.label,Report1.marketname,"",0) k大于") <> 0 and diff>0 and k and chicang=1 then if BuyHodingclean1>0 then call Order.Sell(0,1,Report1.BuyPrice1,0,report1.Label,report1.marketName,"",0) k",0) k小于") <> 0 and diff<0 and="and" k="k" and="and" chicang="1" then if="if" buyhodingclean1="BuyHodingclean1" >0 then call Order.Sell(0,1,Report1.BuyPrice1,0,report1.Label,report1.marketName,"",0) k",0) k执行" then chicang=0 Buyhoding=0 Sellhoding=0 if not report1 is nothing and not report2 is nothing then ctp=Order.StockType(report1.Label,report1.marketName) if ctp=1 then chicang=Order.HoldingInfoByCode2(report1.Label,report1.marketName,BuyHoding,BuyCost,BuyTodayHoding1,SellHoding,SellCost,SellTodayHoding1,PNL,UseMargin) elseif ctp=0 then Hold=0 chicang=Order.HoldingInfoByCode(report1.Label,report1.marketName, Hold, MktPrice, AvgPrice, MktValue, AgeCost, PNL) if hold>0 then Buyhoding=Hold end if if hold<0 then sellhoding="-hold " end="end" if="if" if="if" hold="0" then buyhoding="Hold " sellhoding="hold " end="end" if end="end" if="if" if="if" buyhoding="Buyhoding" >0 and k and chicang=1 then call Order.Sell(0,1,Report1.BuyPrice1,0,report1.Label,report1.marketName,"",0) kzhixing" and chicang=1 then call Order.Sellshort(0,1,Report1.SellPrice1,0,report1.Label,report1.marketName,"",0) k" end if end if end if end sub '当成交量出现变化时发生的事件处理 Sub ORDER_OrderStatusEx(OrderID,Status,Filled,Remaining,Price,Code,Market,OrderType,Aspect,Kaiping) 'application.MsgOut time()&code&" aspect "&Aspect&" kaiping "&Kaiping&" Status "&Status&Filled if code=UCase(taoli_report1) and status="Filled" then if kaiping=0 and aspect=0 then '品种2开空 taoli_ts.AddItem time()&" 条件 买入 "&Filled&"手 "&Report1.StockName&"价格为"&Report1.SellPrice1 call Order.BuyShort(0,Filled,Report2.BuyPrice1,0,Report2.label,Report2.marketname,"",0) elseif kaiping=0 and aspect=1 then '品种2开多 taoli_ts.AddItem time()&" 条件 卖出 "&Filled&"手 "&Report1.StockName&"价格为"&Report1.BuyPrice1 call Order.Buy(0,Filled,Report2.SellPrice1,0,Report2.label,Report2.marketname,"",0) elseif (kaiping=1 or kaiping=3) and aspect=0 then '品种2平多 taoli_ts.AddItem time()&" 自动平仓 "&Filled&"手 "&Report1.StockName&"价格为"&Report1.BuyPrice1 call Order.Sell(0,Filled,Report2.BuyPrice1,0,report2.Label,report2.marketName,"",0) elseif (kaiping=1 or kaiping=3) and aspect=1 then '品种2平空 taoli_ts.AddItem time()&" 自动平仓 "&Filled&"手 "&Report1.StockName&"价格为"&Report1.BuyPrice1 call Order.Sellshort(0,Filled,Report2.SellPrice1,0,report2.Label,report2.marketName,"",0) end if elseif code=UCase(taoli_report2) and status="Filled" then if kaiping=0 and aspect=0 then taoli_ts.AddItem time()&" 自动 买入 "&Filled&"手 "&Report2.StockName&"价格为"&Report2.BuyPrice1 elseif kaiping=0 and aspect=1 then taoli_ts.AddItem time()&" 自动 卖出 "&Filled&"手 "&Report2.StockName&"价格为"&Report2.SellPrice1 elseif (kaiping=1 or kaiping=3) and aspect=0 then taoli_ts.AddItem time()&" 自动平仓 "&Filled&"手 "&Report2.StockName&"价格为"&Report2.BuyPrice1 elseif (kaiping=1 or kaiping=3) and aspect=1 then taoli_ts.AddItem time()&" 自动平仓 "&Filled&"手 "&Report2.StockName&"价格为"&Report2.SellPrice1 end if k elseif status="Cancelled" and code=UCase(taoli_report2) then ctp=Order.StockType(report1.Label,report1.marketName) if taoli_checkbox1.value and ctp=1 then 'application.MsgOut "report2 追加 aspect "&Aspect&" kaiping "&Kaiping&" Status "&Status if kaiping=0 and aspect=0 then call Order.Buy(0,Remaining,Report2.SellPrice1,0,Report2.label,Report2.marketname,"",0) elseif kaiping=0 and aspect=1 then call Order.BuyShort(0,Remaining,Report2.BuyPrice1,0,Report2.label,Report2.marketname,"",0) elseif (kaiping=1 or kaiping=2) and aspect=0 then 'application.MsgOut "撤销品种2 后追加平空" call Order.Sellshort(0,Remaining,Report2.SellPrice1,0,report2.Label,report2.marketName,"",0) elseif (kaiping=1 or kaiping=2) and aspect=1 then ' application.MsgOut "撤销品种2 后追加平多" call Order.Sell(0,Remaining,Report2.BuyPrice1,0,report2.Label,report2.marketName,"",0) end if elseif not(taoli_checkbox1.value) and ctp=1 then k elseif taoli_checkbox1.value and ctp=0 then if aspect=0 then '品种2开空 call Order.Buy(0,Remaining,Report2.SellPrice1,0,Report2.label,Report2.marketname,"",0) elseif aspect=1 then '品种2开多 call Order.BuyShort(0,Remaining,Report2.BuyPrice1,0,Report2.label,Report2.marketname,"",0) end if elseif not(taoli_checkbox1.value) and ctp=0 then k end if elseif status="Cancelled" and code=UCase(taoli_report1) then k 'application.MsgOut Aspect&" report1撤销 "&Kaiping elseif status="Inactive" and code=UCase(taoli_report1) then k end if End Sub '强制平仓 Sub taoli_clearButton_Click() exce1="" pingcang="执行" k End Sub '调试按钮 Sub taoli_CommandButton1_Click() application.ClearMsg taoli_ts.clear End Sub '下面两个过程是生成操作提示 sub display() Set report1 = marketdata.GetReportData(taoli_report1.text,taoli_report1market) Set report2 = marketdata.GetReportData(taoli_report2.text,taoli_report2market) if taoli_term1price<>"" and taoli_term1num<>"" and taoli_term1cleanprice<>"" then if not report1 is nothing and not report2 is nothing then dim s s="条件设定成立 当差价"&taoli_term1ComboBox.value&taoli_term1price.text&"时,将进行:"&vbCrLf&" " s=s&report1ComboBox1&taoli_term1num.text&"手 "&report1.stockname&" " s=s&report2ComboBox1&taoli_term1num.text&"手 "&report2.stockname if exce1="执行" then taoli_display1.caption=s&" 正在执行" else taoli_display1.caption=s&" 未执行" end if else taoli_display1.caption="条件1设立不足" exce1="" end if end if end sub Sub taoli_executebutton1_Click() '各个填入控件的约束 Set report1 = marketdata.GetReportData(taoli_report1.text,taoli_report1market) if report1 is nothing then msgbox "品种1代码或市场错误" exit sub else 'Application.MsgOut Report1.stockname&" "&Report1.NewPrice end if Set report2 = marketdata.GetReportData(taoli_report2.text,taoli_report2market) if report2 is nothing then msgbox "品种2代码或市场错误" exit sub else 'Application.MsgOut Report2.stockname&" "&Report2.NewPrice end if if taoli_term1price.text="" or not(IsNumeric(taoli_term1price.text)) then msgbox "条件开仓差价未填或不是数字" exit sub end if if taoli_term1num.text="" or not(IsNumeric(taoli_term1num.text)) or CInt(taoli_term1num.text)<0 then if CInt(taoli_term1num.text)<0 then msgbox "条件数量应大于0" exit sub end if msgbox "条件数量未填或不是数字" exit sub end if if taoli_term1cleanprice.text="" or not(IsNumeric(taoli_term1cleanprice.text)) then msgbox "条件平仓差价未填或不是数字" exit sub end if taoli_report1market.enabled=false taoli_report2market.enabled=false report1combobox1="taoli_report1ComboBox.value " report2combobox1="taoli_report2ComboBox.value " exce1="执行" k pingcang="" End Sub Sub taoli_test_Click() Set report1 = marketdata.GetReportData(taoli_report1.text,taoli_report1market) if report1 is nothing then msgbox "品种1代码或市场错误" exit sub else 'Application.MsgOut Report1.stockname&" "&Report1.NewPrice end if Set report2 = marketdata.GetReportData(taoli_report2.text,taoli_report2market) if report2 is nothing then msgbox "品种2代码或市场错误" exit sub else 'call marketdata.RegReportNotify(report2.Label,report2.marketName) ' Application.MsgOut Report2.stockname&" "&Report2.NewPrice end if call marketdata.RegReportNotify(report1.Label,report1.marketName) End Sub Sub taoli_report1_Change() if not report1 is nothing then call marketdata.UnRegReportNotify(report1.Label,report1.marketName) taoli_report1market.enabled=true set report1="nothing " end if End Sub Sub taoli_report2_Change() if not report2 is nothing then call marketdata.UnRegReportNotify(report2.Label,report2.marketName) taoli_report2market.enabled=true set report2="nothing " end if End Sub

 回到顶部