如何使用Marketdepthprovider获得盘口实时行情?
如何Marketdepthprovider可以获得代码的盘口实时买卖量价数据。 具体用法见示例。
示例1:使用Marketdepthprovider获得盘口实时行情
using tsdata.marketdata;
using guosen;
using elsystem;
using elsystem.windows.forms;
vars:MarketDepthProvider MDP(null);
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
MDP = new MarketDepthProvider;
MDP.Symbol = "000981.SZ";
MDP.Realtime = TRUE;
MDP.MaximumLevelCount = 10;
MDP.Updated += MDP_Updated;
MDP.Load = TRUE;
end;
Method void MDP_Updated(elsystem.Object sender,MarketDepthUpdatedEventArgs args)
vars:int x;
Begin
print(MergeStr());
End;
//merge the string
Method string MergeStr()
vars:string str,int loop;
Begin
str = numtostr(date+19000000,0)+","+numtostr(time,0); //convert to natural date
print(MDP.AskLevels.Count," ",MDP.BidLevels.Count);
For loop = 0 to MDP.AskLevels.Count-1
Begin
str = str + "," + AskP(loop) + "," + AskS(loop);
End;
For loop = 0 to MDP.BidLevels.Count-1
Begin
str = str + "," + BidP(loop) + "," + BidS(loop);
End;
Return str;
End;
//Ask price to string
Method string AskP(int level)
vars:string nu;
Begin
nu = "";
try
nu = numtostr(MDP.Asks[level].Price,2);
catch(elsystem.Exception ex)
End;
return nu;
End;
//Ask Size to string
Method string AskS(int level)
vars:string nu;
Begin
nu = "";
try
nu = numtostr(MDP.Asks[level].Size,2);
catch(elsystem.Exception ex)
End;
return nu;
End;
//Bid price to string
Method string BidP(int level)
vars:string nu;
Begin
nu = "";
try
nu = numtostr(MDP.Bids[level].Price,2);
catch(elsystem.Exception ex)
End;
return nu;
End;
//Bid size to string
Method string BidS(int level)
vars:string nu;
Begin
nu = "";
try
nu = numtostr(MDP.Bids[level].Size,2);
catch(elsystem.Exception ex)
End;
return nu;
End;