如何实时获得账号资金信息?
EasyLanguage 提供AccountsProvider用来获得实时的账户信息。
示例1:使用AccountsProvider获得资金账户信息
using guosen;
using tsdata.marketdata;
using elsystem.collections;
vars:AccountsProvider AP(null);
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
AP = new AccountsProvider;
AP.Realtime = True;
AP.Load = true;
AP.StateChanged += AP_StateChanged;
end;
Method void AP_StateChanged(elsystem.Object sender,tsdata.common.StateChangedEventArgs args)
vars: int loop;
Begin
For loop= 0 to AP.Count-1
Begin
print(AcctToString(AP[0]));
End;
End;
Method string AcctToString(Account Act)
vars:string str,Vector vec_tmp,int loop,string sepChar;
Begin
sepChar = "=";
str = "";
vec_tmp = new Vector;
vec_tmp.Push_back("资金账号" + sepChar + Act.AccountID);
vec_tmp.Push_back("类型" + sepChar + Act.Type.ToString());
vec_tmp.Push_back("总资产" + sepChar + numtostr(Act.RTAccountNetWorth,2));
vec_tmp.Push_back("账户余额" + sepChar + numtostr(Act.RTCashBalance,2));
vec_tmp.Push_back("可用资金 " + sepChar + numtostr(Act.RTDayTradingBuyingPower,2));
vec_tmp.Push_back("持仓市值" + sepChar + numtostr(Act.RTPositionsMarketValue,2));
vec_tmp.Push_back("浮动盈亏" + sepChar + numtostr(Act.RTUnrealizedPL ,2));
for loop = 0 to vec_tmp.Count-1
Begin
str = str + vec_tmp[loop].ToString()+",";
End;
Return str;
End;
//打印语句输出栏结果示例:HighLimit: 100900 LowLimit:100900
//资金账号=410009982318,类型=margin,总资产=100000164.80,账户余额=100000000.00,可用资金 =100000164.80,持仓市值=0.00,浮动盈亏=0.00,
//资金账号=410009982318,类型=margin,总资产=100000164.80,账户余额=100000000.00,可用资金 =100000164.80,持仓市值=0.00,浮动盈亏=0.00,