以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://www.weistock.com/bbs/index.asp)
--  高级功能研发区  (http://www.weistock.com/bbs/list.asp?boardid=5)
----  [求助]关于VBS代码如何实现金字塔程序化  (http://www.weistock.com/bbs/dispbbs.asp?boardid=5&id=144924)

--  作者:michaelyjy
--  发布时间:2016/12/19 13:53:23
--  [求助]关于VBS代码如何实现金字塔程序化
以下是VBA的HELP文件范例,请问利用以下代码如何实现账户的程序化交易?还需要哪些步骤的操作?(打开交易账号等)

Sub TLStart()
\'注册CF09和CF11品种
  call marketdata.RegReportNotify("CF09","ZQ")
  call marketdata.RegReportNotify("CF11","ZQ")
End Sub

Sub MARKETDATA_ReportNotify()
  \'得到这两个品种的行情报价
  Set Report1 = marketdata.GetReportData("CF09","ZQ")
  Set Report2 = marketdata.GetReportData("CF11","ZQ")
\'得到品种的持仓量等信息
  dim BuyHoding1
  dim BuyHlding2
  dim BuyTodayHoding1
  dim BuyTodayHoding2
  dim SellHoding1
  dim SellHoding2
  dim SellTodayHoding1
  dim SellTodayHoding2
  dim BuyCost
  dim SellCost
  dim PNL
  Dim UseMargin
  \'取指定持仓品种信息
  call Order.HoldingInfoByCode2("CF09","ZQ",BuyHoding1,BuyCost,BuyTodayHoding1,SellHoding1,SellCost,SellTodayHoding1,PNL,UseMargin)
  call Order.HoldingInfoByCode2("CF11","ZQ",BuyHoding2,BuyCost,BuyTodayHoding2,SellHoding2,SellCost,SellTodayHoding2,PNL,UseMargin)
 
  \'当差价出现大于1800时进行套利开仓
  \'假设是09买 11卖
  Diff = Report1.SellPrice1 - Report2.BuyPrice1 \'分别取卖价和买价计算差价 
  if Diff > 1800 and BuyHoding1 = 0 then
  call Order.Buy(0,1,Report1.SellPrice1,0,"CF09","ZQ","",0)
  call Order.BuyShort(0,1,Report2.BuyPrice1,0,"CF11","ZQ","",0)
  end if
  \'当差价小于1000时进行套利平仓
  Diff = Report1.BuyPrice1 - Report2.SellPrice1
  if diff < 1000 and BuyHoding1 > 0 then
  call Order.Sell(0,1,Report1.BuyPrice1,0,"CF09","ZQ","",0)
  call Order.Sellshort(0,1,Report2.SellPrice1,0,"CF11","ZQ","",0)
  end if
End Sub

--  作者:王锋
--  发布时间:2016/12/19 13:57:08
--  

不清楚你的需求到底是什么?

本身这个代码就是可以直接交易的,您是不知道怎么运行这段代码?


--  作者:michaelyjy
--  发布时间:2016/12/19 14:13:26
--  
对的。不知道详细的步骤。
是需要先登录账号,然后运行宏TLStart,还是?

--  作者:王锋
--  发布时间:2016/12/19 14:41:21
--  

肯定要先登录交易帐号的呀,不然怎么交易哦


--  作者:michaelyjy
--  发布时间:2016/12/19 14:55:30
--  
那请问登录账户之后 应该怎么操作?我直接点执行宏TLStart什么反应都没有
--  作者:yukizzc
--  发布时间:2016/12/19 16:49:28
--  

建议加上一些msgout输出,看戏是不是条件不满足导致的。

没有反应不是说代码不执行,而是可能某个条件没满足