以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  高级功能研发区  (http://weistock.com/bbs/list.asp?boardid=5)
----  这个VB程序怎么一键平不了所有仓呢  (http://weistock.com/bbs/dispbbs.asp?boardid=5&id=49608)

--  作者:chinagaox
--  发布时间:2013/3/13 9:42:18
--  这个VB程序怎么一键平不了所有仓呢

function YiJianPinCangAll(sAccount)
 dim i
 dim BuyHold
 dim BuyCost
 dim SellHold
 dim SellCost
 dim CurCode
 dim CurMarket
\' msgbox "当前持仓数:"&Order.Holding2(sAccount)
 
 while ( Order.Holding2(Account))
  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 & "手"
        call Sell(1,abs(BuyHolding),0,0,Code,Market,sAccount,0) \'平多


       end if
          if SellHold>0 then
            HoldStr=HoldStr & "  空单:-" & SellHold & "手"
          call  SellShort(1,abs(SellHolding),0,0,Code,Market,sAccount,0)

          end if 
    HoldStr=HoldStr & " ,"
   Next
   HoldStr=Left(HoldStr,len(HoldStr)-1) \'去掉了尾部,号
  End If
 \' GetHoldStr=HoldStr
wend
 DayClose_Label_ZhangHuJieGuo.Caption= "当前品种"&HoldStr &"平仓后,当前持仓数:"&Order.Holding2(sAccount)
   
End function


--  作者:admin
--  发布时间:2013/3/13 9:47:49
--  
具体你遇到了什么情况
--  作者:chinagaox
--  发布时间:2013/3/13 10:03:50
--  

一个品种都平不了仓

 


--  作者:chinagaox
--  发布时间:2013/3/13 10:04:01
--  

好象没反应一样

 


--  作者:admin
--  发布时间:2013/3/13 10:09:41
--  
在程序中加入Application.msgout函数,调试看看
--  作者:rushtaotao
--  发布时间:2013/3/13 10:13:23
--  
你这个标题上面写的是一键平仓,但function也是去调用的,没有按钮事件

其次给出完整平所有仓代码

获取指定者账户的所有持仓合约,保存到一个字符串中。

此例需要解决的问题:首先要获取账户的总持仓数,需要用到Holding2属性,然后要逐一循环取出每一个持仓合约的持仓量,需要用到HoldingInfo2方法。

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

本代码使用函数方式,传递一个账户号码,就可以获取该账户的持仓信息,调用方法是:hold=GetHoldStr("88888888")。


--  作者:chinagaox
--  发布时间:2013/3/13 10:31:30
--  

我就是按照上面的代码做的,就是多加了一个平仓语句,能读出帐户信息,但平不了仓,我是用按扭调用这个函数的

if BuyHold>0 then
         HoldStr=HoldStr & "  多单:+" & BuyHold & "手"
        call Sell(1,abs(BuyHolding),0,0,Code,Market,sAccount,0) \'平多           平不了


       end if
          if SellHold>0 then
            HoldStr=HoldStr & "  空单:-" & SellHold & "手"
          call  SellShort(1,abs(SellHolding),0,0,Code,Market,sAccount,0)\'平空      平不了

          end if 

 


--  作者:chinagaox
--  发布时间:2013/3/13 10:43:32
--  
我是正式标准版用户,模拟资金帐号,用VB开仓没问题,上面的平仓就平不了。
--  作者:rushtaotao
--  发布时间:2013/3/13 11:19:09
--  
查一下每个参数 很有可能是参数传递问题
--  作者:admin
--  发布时间:2013/3/13 12:12:18
--  

function YiJianPinCangAll(sAccount)
 dim i
 dim BuyHold
 dim BuyCost
 dim SellHold
 dim SellCost
 dim CurCode
 dim CurMarket
\' msgbox "当前持仓数:"&Order.Holding2(sAccount)

Application.MsgOut "111111"
 
 while ( Order.Holding2(Account))
  On Error resume Next
  HoldStr=""
 HoldingCount=Order.Holding2(sAccount)

Application.MsgOut "222222"
  If HoldingCount>0 then
   For i=0 to HoldingCount-1

    Application.MsgOut "33333"
    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 & "手"
        call Sell(1,abs(BuyHolding),0,0,Code,Market,sAccount,0) \'平多

        Application.MsgOut "444444"
       end if
          if SellHold>0 then
            HoldStr=HoldStr & "  空单:-" & SellHold & "手"
          call  SellShort(1,abs(SellHolding),0,0,Code,Market,sAccount,0)

          Application.MsgOut "55555"

          end if 
    HoldStr=HoldStr & " ,"
   Next
   HoldStr=Left(HoldStr,len(HoldStr)-1) \'去掉了尾部,号
  End If
 \' GetHoldStr=HoldStr
wend
 DayClose_Label_ZhangHuJieGuo.Caption= "当前品种"&HoldStr &"平仓后,当前持仓数:"&Order.Holding2(sAccount)
  Application.MsgOut "666666"
End function

 

将上述加上调试日志的代码运行后,把运行结果贴过来