如何使用PositionsProvider获得持仓可用数或可平仓数?
一般而言,获取持仓的可用数首先应该通过PositionsProvider获得该持仓Position对象,在Position的诸多属性中有持仓可用数这一属性。股票中获得持仓可用数方法如下:
示例1:使用PositionsProvider获得股票的持仓可用数
using guosen;
using tsdata.marketdata;
using tsdata.common;
using elsystem;
vars:
PositionsProvider PP(null),
IntrabarPersist int count(0);
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
PP = new PositionsProvider;
PP.Realtime = True;
PP.Load = TRUE;
pp.StateChanged += pp_StateChanged;
end;
Method void pp_StateChanged(Object sender,StateChangedEventArgs args)
vars:int loop;
Begin
if(PP.State = DataState.loaded)then
Begin
For loop = 0 to PP.Count-1
Begin
print(PP[loop].AccountID+","+PP[loop].Symbol+","+
"Avaiable Quantity,"+ numtostr(PP[loop].QuantityAvailable,0));
End;
End;
End;
//打印输出示例
//410038122059,150269.SZ,Avaiable Quantity,500
//410038122059,502048.SH,Avaiable Quantity,600
//410038122059,600004.SH,Avaiable Quantity,500
//410038122059,600023.SH,Avaiable Quantity,14050
//410038122059,600050.SH,Avaiable Quantity,500
//410038122059,601985.SH,Avaiable Quantity,4500
//410038122059,601988.SH,Avaiable Quantity,22000
//410038122059,603589.SH,Avaiable Quantity,500