如何使用OrderTicket在指标和策略中下单?
使用guosen.OrderTicket可以发送委托单,一般而言,必须要指定必要的字段属性,否则会导致OrderTicket发送失败,而且不同品种的委托要求的必填字段和属性设置不尽相同。下面以最常使用的股票市价单和股票限价单为例。
示例1:使用OrderTicket发送股票市价单
using guosen;
using elsystem;
using tsdata.common;
using tsdata.marketdata;
using elsystem.collections;
vars:
guosen.OrderTicket otk1(null),
guosen.Order ord(null),
string accID("410038122059");//根据情况修改Account ID
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
otk1 = new guosen.OrderTicket;
otk1.Symbol = "000002.SZ";
otk1.Quantity = 100;
otk1.BypassClientValidation = True;//跳过本地验证
otk1.Account = accID;
otk1.Action = OrderAction.Buy;
otk1.SymbolType = tsdata.common.SecurityType.Stock;
otk1.Type = tsdata.trading.OrderType.Market;//市价单
otk1.Duration="AUT";//自动选择期限
otk1.ExtendedProperties.SetItem("OrderName", "customOrderIDxxxxxxxx");//自定义的OrderName
ord = otk1.Send();//发送委托
end;
示例2:使用OrderTicket发送股票限价单
using guosen;
using elsystem;
using tsdata.common;
using tsdata.marketdata;
using elsystem.collections;
vars:
guosen.OrderTicket otk1(null),
guosen.Order ord(null),
string accID("410038122059");//根据情况修改Account ID
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
otk1 = new guosen.OrderTicket;
otk1.Symbol = "601988.SH";
otk1.Quantity = 100;
otk1.BypassClientValidation = True;//跳过本地验证
otk1.Account = accID;
otk1.Action = OrderAction.Buy;
otk1.SymbolType = tsdata.common.SecurityType.Stock;
otk1.Type = tsdata.trading.OrderType.Limit;//限价单
otk1.LimitPrice = 3.51;//限价
otk1.Duration="AUT";//自动选择期限
otk1.ExtendedProperties.SetItem("OrderName", "customOrderIDxxxxxxxx");//自定义的OrderName
ord = otk1.Send();//发送委托
end;