如何测试委托发送需要的时间或测试下单耗时?

EasyLanguage 中的DateTime可以精确到秒,但是往往委托从发出到返回成交信息耗时不超过1秒,故而无法用DateTime记录系统时间的方式测试发单耗时(从订单发出到收到成交汇报)。但是EasyLanguage提供额外的一种方法StopWatch (可以记录从watch start之后经过的时间,精确至毫秒)测试发单耗时。

示例1:使用StopWatch 测试发单耗时

using guosen;
using elsystem;
using tsdata.common;
using tsdata.marketdata;

vars:
    guosen.OrderTicket otk1(null),
    guosen.Order ord(null), 
    StopWatch swatch(null),
    string accID("410038122059");

method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args ) 
begin
    swatch = new StopWatch;
    otk1 = new guosen.OrderTicket;  
    otk1.Symbol = "000002.SZ";
    otk1.Quantity = 100;
    otk1.Account = accID;
    otk1.Action = OrderAction.Buy;
    otk1.SymbolType = tsdata.common.SecurityType.Stock;
    otk1.Type = tsdata.trading.OrderType.Limit;
    otk1.Duration="GFD";
    otk1.LimitPrice = 26.28;
    ord = otk1.Send();
    swatch.Start(); //订单发送后开始计时
    ord.Updated += ord_Updated;
end;

Method void ord_Updated(elsystem.Object sender,guosen.OrderUpdatedEventArgs args)
Begin
    print(DateTime.Now.ToString()+ "," +args.OrderID.ToString()+","+args.State.ToString()+",
        ElapsedMilliseconds: ",swatch.ElapsedMilliseconds ," ms");
    if(args.State = OrderState.Filled)then
    Begin
        swatch.Stop();
    End;
End;
//打印语句输出栏结果示例:
//2016/12/1 9:59:18,,sending,ElapsedMilliseconds:   21.00 ms
//2016/12/1 9:59:18,0-_410-0381-2205-9_20-1612-01_1-0397-9313,received,ElapsedMilliseconds:   60.00 ms
//2016/12/1 9:59:18,0-_410-0381-2205-9_20-1612-01_1-0397-9313,filled,ElapsedMilliseconds:  191.00 ms
Copyright © 1998-2018 国信证券股份有限公司 版权所有发布时间: 2018-05-14 14:58:15

results matching ""

    No results matching ""