如何使用OrdersProvider查询历史委托?
通过设置OrdersProvider的属性可以获得不同时期的订单列表集合。默认不设置OrdersProvider的日期起止时间的话,其查询的是当日的委托集合信息。若是要查询历史订单信息的话,需要指定账户ID以及起始日期。
示例1:使用OrdersProvider查询历史委托
using guosen;
using elsystem;
using elsystem.collections;
using tsdata.common;
vars:
OrdersProvider OP(null),
DateTime dt(null),
string accountid("");
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
accountid = "410038122059";//Account ID需为绑定的ID
dt = DateTime.Now;
dt.AddWeeks(-1);//设置dt为一周前
OP = new OrdersProvider;
OP.From = dt;
OP.Accounts += accountid;
OP.To = DateTime.Now; //截止日期
OP.Realtime = TRUE;
OP.StateChanged += OP_StateChanged;
OP.Load = TRUE;
end;
Method void OP_StateChanged(elsystem.Object sender,tsdata.common.StateChangedEventArgs args)
vars:int loop;
Begin
if(OP.State = DataState.Loaded)then
Begin
for loop = 0 to OP.Count-1
Begin
print(OrderToString(OP[loop]));
End;
End;
End;
//Join the properties of order object to a string
Method string OrderToString(Order ord)
vars:string str,Vector vec_tmp,int loop,string sep,string sepChar;
Begin
str = "";
sep = ",";
sepChar = "=";
vec_tmp = new Vector;
vec_tmp.Push_back("account" + sepChar + ord.AccountID);
vec_tmp.Push_back("action" + sepChar + ord.Action.ToString().ToLower());
vec_tmp.Push_back("duration" + sepChar + ord.Duration.ToString().ToLower());
vec_tmp.Push_back("enteredquantity" + sepChar + ord.EnteredQuantity.ToString().ToLower());
vec_tmp.Push_back("enteredtime" + sepChar + ord.EnteredTime.ToString().ToLower());
vec_tmp.Push_back("filledquantity" + sepChar + ord.FilledQuantity.ToString().ToLower());
vec_tmp.Push_back("filledtime" + sepChar + ord.FilledTime.ToString().ToLower());
vec_tmp.Push_back("limitprice" + sepChar + ord.LimitPrice.ToString().ToLower());
vec_tmp.Push_back("orderid" + sepChar + ord.OrderID.ToString().ToLower());
vec_tmp.Push_back("state" + sepChar + ord.State.ToString().ToLower());
vec_tmp.Push_back("statedetail" + sepChar + ord.StateDetail.ToString().ToLower());
vec_tmp.Push_back("limitprice" + sepChar + ord.LimitPrice.ToString().ToLower());
vec_tmp.Push_back("symbol" + sepChar + ord.Symbol.ToString().ToLower());
vec_tmp.Push_back("type" + sepChar + ord.Type.ToString().ToLower());
vec_tmp.Push_back("limitprice" + sepChar + ord.LimitPrice.ToString().ToLower());
Try
vec_tmp.Push_back("ordername" + sepChar + ord.ExtendedProperties["OrderName"].ToString());
catch(elsystem.Exception ex)
vec_tmp.Push_back("ordername" + sepChar + "NULL");
End;
for loop = 0 to vec_tmp.Count-1
Begin
str = str + vec_tmp[loop].ToString()+",";
End;
Return str;
End;
//打印语句输出栏结果示例:
//account=410038122059,action=buy,duration=gfd,enteredquantity=500,enteredtime=2016/11/30 14:57:46,filledquantity=500,filledtime=2016/11/30 14:57:46,limitprice=14.08,orderid=0-_410-0381-2205-9_20-1611-30_1-0396-3386,state=filled,statedetail=filled,limitprice=14.08,symbol=000919.sz,type=limit,limitprice=14.08,ordername=,
//account=410038122059,action=buy,duration=gfd,enteredquantity=500,enteredtime=2016/11/30 14:58:00,filledquantity=500,filledtime=2016/11/30 14:58:00,limitprice=14.08,orderid=0-_410-0381-2205-9_20-1611-30_1-0396-0382,state=filled,statedetail=filled,limitprice=14.08,symbol=000919.sz,type=limit,limitprice=14.08,ordername=,