如何读取文本文件txt并发送委托?

使用保留字(Reserve Word)不能直接获得涨停价或跌停价。 国信TradeStation提供QuotesProvider在EasyLanguage中获取代码的涨停价和跌停价。 具体用法见示例。

示例1:读取文本文件txt并发送委托

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

vars:string accID("410038122059");//根据情况修改Account ID
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
vars:int loop;
begin
    ReadFile("D:\orders.txt");
end;



//从path读取股票代码列表,文件格式为每行: 股票代码,数量,BuyOrSell,LimitPrice,并下单
Method void ReadFile(string path)
vars:StreamReader sr,string line,vector vec,bool isEnd;
Begin
    isEnd = false;
    vec = new Vector;
    Try
        sr = StreamReader.Create(path); //创建读入流
        while(true)
        Begin
            line = sr.ReadLine(); //读取一行
            vec.Clear();
            if(line.Trim().Equals(""))then
            Begin
                print("Read to end.");//读取的文本为空字符串
                break;
            End
            Else
            Begin
                vec = line.split(",");
                if(vec.Count = 5)then
                Begin
                    sendOrder(vec);
                End;
            End;
        End;
    catch(elsystem.Exception ex)
        print("File read exception. Not found or locked.");
    End;
End;

//第一个参数是代码,第二个参数是数量,第三个参数是买卖方向,第四个参数是委托类型,第五个参数是委托价格
Method void sendOrder(Vector vec)
vars:OrderTicket otk1;
Begin
    otk1 = new OrderTicket;
    otk1.Symbol = vec[0].ToString(); //代码
    otk1.Quantity = strtonum(vec[1].ToString()); //数量
    otk1.BypassClientValidation = True;//跳过本地验证
    otk1.Account = accID; 
    if(vec[2].ToString().toLower().Equals("buy"))then
    Begin
        otk1.Action = OrderAction.Buy;
    End
    Else
    Begin
        otk1.Action = OrderAction.Sell;
    End;
    otk1.SymbolType = tsdata.common.SecurityType.Stock; //代码类型
    if(vec[3].ToString().toLower().Equals("market"))then
    Begin
        otk1.Type = tsdata.trading.OrderType.Market;//市价单
    End
    else
    Begin
        otk1.Type = tsdata.trading.OrderType.Limit;//限价单
    End;
    otk1.LimitPrice = strtonum(vec[4].ToString());
    otk1.Duration="AUT";//自动选择期限
    otk1.ExtendedProperties.SetItem("OrderName", "customOrderIDxxxxxxxx");//自定义的OrderName
    otk1.Send();//发送委托
End;

"D:\orders.txt" 文件格式如下:

600023.SH,200,buy,market,0 600023.SH,200,buy,limit,5.6

Copyright © 1998-2018 国信证券股份有限公司 版权所有发布时间: 2018-05-14 14:58:15

results matching ""

    No results matching ""