建议:打开了允许主力连续合约下单交易时,Code对应返回主力合约编码:
现在的情况是:勾选了“下单设置”下的“允许主力连续合约下单交易”,使用VBA后台交易,可以开单,但是查询持仓情况时,因为这时的品种代码是IF00(以股指为例),结果查不到持仓,应该是自动返回当前的主力合约编码,比如,今天的,应该返回IF05。
或者:增加一个VBA函数,通过这个函数可以返回连续合约的对应主力合约编码。
后面检查一下代码
我增加了一段代码,用于获取主力合约
这样就可以了,但是如果金字塔能直接处理这个问题就更好了。
Sub GetContractCode(sMarketCode) '根据市场编码取得主力合约编码
If sMarketCode="" then
sMarketCode="ZJ"
End if
contractvolume = 0
n = marketdata.GetReportCount(sMarketCode)
For j = 0 To n - 1
Set report1 = marketdata.GetReportDataByIndex(sMarketCode, j)
suffixlabel = Right(report1.Label, 2)
If suffixlabel = "00" Then
contractvolume = 0
End If
If suffixlabel >= "01" And suffixlabel <= "12" Then
If report1.volume > contractvolume Then
contractlabel = report1.Label
contractvolume = report1.volume
End If
End If
Next
If Contractlabel<>"" and Right(Contractlabel,2)<>"00" then
VBA_Code=Contractlabel '这就是我要的品种代码。
End if
End Sub