以文本方式查看主题

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

--  作者:michaelyjy
--  发布时间:2016/12/21 13:53:03
--  [求助]求助代码
在论坛上看到一个函数的例子,不知道on error resume next语句起什么作用,前面的变量定义还有可能出错吗?

function GetHoldStr(sAccount)
 dim i
 dim BuyHold
 dim BuyCost
 dim SellHold
 dim SellCost
 dim CurCode
 dim CurMarket
 
  On Error resume Next
  HoldStr=""
 HoldingCount=Order.Holding2(sAccount)
  If HoldingCount>0 then
   For i=0 to HoldingCount-1
    Call Order.HoldingInfo2(i,BuyHolding,BuyCost,BuyTodayHolding,SellHolding,SellCost,SellTodayHolding,PNL,UseMargin,Code,Market,sAccount)
    CurCode=Code
    CurMarket=Market
    BuyHold=BuyHolding
    SellHold=SellHolding
    HoldStr=HoldStr & CurCode
    if BuyHold>0 then
      HoldStr=HoldStr & ":+" & BuyHold
    end if
    if SellHold>0 then 
      HoldStr=HoldStr & ":-" & SellHold 
    end if  
    HoldStr=HoldStr & ","
   Next
   HoldStr=Left(HoldStr,len(HoldStr)-1)
  End If 

  GetHoldStr=HoldStr
End function


--  作者:michaelyjy
--  发布时间:2016/12/21 13:59:59
--  
另外,前面的变量定义是否可以省略?
--  作者:michaelyjy
--  发布时间:2016/12/21 15:24:38
--  
另外,请问orderstatusex2事件是自带返回time变量么?


Sub ORDER_OrderStatusEx2(OrderID, Status, Filled, Remaining, Price, Code, Market, OrderType, Aspect, Kaiping,Account, AccountType)

 \'账户类型 0 IB 1 CTP 2 金仕达 3其他

Dim sStatus       \'成交状态 

If AccountType=0 then

sAccType="0.IB"

ElseIf AccountType=1 then

sAccType="1.CTP"

ElseIf AccountType=2 then

sAccType="2.金士达"

End if 

 

If AccountType=0 then

sStatus="FILLED"

ElseIf AccountType=1 then

sStatus="TRADEING"

lseIf AccountType=2 then

sStatus="FILLED"

End if

 

If UCase(Status)="FILLED" then  \'只跟踪成交的单 

if Aspect=0 and Kaiping=0 then \'买入

Call Document.SetExtString("Order-Buy-time",time)     \'成交时间

Call Document.SetExtData("Order-B-Price",Price)   \'成交价格

Call Document.SetExtData("Order-B-Vol",Filled)   \'成交手数

Call Document.SetExtData("Order-B-OrderID",OrderID)  \'成交单号

end if

      End if 
    End Sub  


--  作者:王锋
--  发布时间:2016/12/21 17:56:52
--  

变量不能省略

time是VBA的函数,取自你计算机的本地时间


--  作者:michaelyjy
--  发布时间:2016/12/22 8:18:11
--  
不知道on error resume next语句起什么作用,前面的变量定义还有可能出错吗?
--  作者:yukizzc
--  发布时间:2016/12/22 9:41:04
--  

https://zhidao.baidu.com/question/204610833.html

建议先百度下,自己运行看看效果


--  作者:michaelyjy
--  发布时间:2016/12/22 10:31:08
--  
谢谢