返回首页 股票大厅 市场分析 筹码收集 机构报告 个股分析 金融学堂 期指期货 理论图书 席位资金 价值投资 休闲社区 贴图摄影 养生养颜
今日:必涨⑤只黑马股
强烈推荐③只暴涨牛股
9:35将公布③只暴涨股
免费公开③只必涨黑马
庄家拉升3只暴涨牛股
推荐明日③只涨停黑马
看好大飙涨牛股请点击
提前布局3只暴涨金股
今日推荐三只涨停股
重点推荐③只暴涨黑马
今日→推荐②只涨停股
专家推荐③只暴涨牛股
爆既将拉升5只牛股 图
八大机构一致推荐牛股
股票内幕:黑马能涨90%
看:炒股买跑车→图
发新话题
打印

[06-17] VTtrader API 1.0.4 beta3 常用方法说明文档

本主题由 西边 于 2008-11-13 14:06 关闭
水泥股没抓到接下来应该买什么……

[06-17] VTtrader API 1.0.4 beta3 常用方法说明文档

VTtrader API 1.0.4 beta3 常用方法说明文档

//初始化
VT_APIClass api= new VTAPI.VT_APIClass();


//得到服务器列表
string serverList= Api.GetServerList();

//登陆
int loginStatus=Api.Login(string name,string pwd,int serverID);

//退出
int isQuit=Api.Logout();

//卸载
Api.Finalize();
Api=null;

//得到服务器时间
DateTime dt=Api.GetServerTime();

//查看是否已登录
Bool isLogin=Api.LoggedIn;

//账号
Account a1=Api.GetAccountByIndex(0);
Account a2=Api.GetAccountByID(“3318189”);

//货币对
Instrument i1=Api.GetInstrumentByIndex(0);
Instrument i2=Api.GetInstruemntByCurrency(“EUR”,”USD”);

//已开仓信息
Position p1=Api.GetOpenPositionByIndex(0);
Position p2=Api.GetOpenPositionByID(“3318189”);

//已申请挂单
Order o1=Api.GetOrderByIndex(0);
Order o2=Api.GetOrderByID(“3318189”);

//VT系统常量
ConstRecord consts =API.constants;


  //开仓(duration = consts.dur_GTC,如果hedge设置为False,当你为当前已有仓位开一反向单时,系统将自动平仓,而不是下反向单;如果hedge设置为True,你将可以给同一货币对开多个买卖仓位)

public static int Position_Create(Account account, Instrument instrument, short duration, short sellbuy, double amount, bool hedge)
        {
            int TraderRange=0,Rate=0;
            bool Initial=Convert.ToBoolean(api.constants.ord_Initial);
            return api.SendCreateOrder(account.ID, instrument.Index, Convert.ToBoolean(duration), TraderRange, Convert.ToBoolean(sellbuy), Rate, amount, hedge, Initial);
        }

//添加挂单(offset一般为0,limit=limitPips,stop=stopPips)

  public static int Order_Create(Account account, Instrument instrument, short duration, short sellbuy, double amount, bool hedge,int offset,int limit,int stop)
        {
            int TraderRange = 0,StopRange=0;
            bool Initial = Convert.ToBoolean(api.constants.ord_Entry);
            if (sellbuy == api.constants.bs_Sell)
            {
                offset = -offset;
                limit = -limit;
                stop = -limit;
            }

            Instrument tmp = (Instrument)instrument;
            double closeRate, openRate, litmitRate, stopRate;
            openRate = tmp.Ask + tmp.pointSize * offset;
            closeRate = tmp.Bid + tmp.pointSize * offset;

            litmitRate = closeRate + tmp.pointSize * limit;
            stopRate = closeRate - tmp.pointSize * stop;

            return api.SendCreateOrderWithSL(account, instrument, Convert.ToBoolean(duration), TraderRange, Convert.ToBoolean(sellbuy), openRate, amount, Convert.ToBoolean(hedge), Initial, litmitRate, stopRate, StopRange);
        }

//修改限价
public static int Position_Limit_Change(Position position,double rate)
        {
            if (position.LimitOrder == null)
                return api.SendSetLimitForOpenPosition(position.ID, rate);
            else
                return api.SendChangeLimitForOpenPosition(position.ID, rate);
        }

//修改止损
public static int Position_Stop_Change(Position position, double rate)
        {
            if (position.StopOrder == null)
                return api.SendSetStopForOpenPosition(position.ID, rate);
            else
                return api.SendChangeStopForOpenPosition(position.ID, rate);
        }

//移除限价
public static int Position_Limit_Remove(Position position)
        {
            return api.SendRemoveLimitForOpenPosition(position.ID);
        }

//移除止损
public static int Position_Stop_Remove(Position position)
        {
            return api.SendRemoveStopForOpenPosiotion(position.ID);
        }


//VTtrader 事件类(只写出常用事件)
public class cl_event : IVT_APIEvents
    {
        public cl_event() { }

        public void OnNewServerMessage(int msg_index)
        {

            //得到信息
            ServerMessage sm = cl_api.API.ServerMessages.get_Items(msg_index);
            string mlName = Enum.GetName(typeof(MessageLevel), sm.Level);

            //输出信息内容
            Console.WriteLine(string.Concat(sm.Time.ToString("yy-MM-dd hh:mm:ss"), mlName == null ? sm.Level.ToString() : mlName.ToLower(), sm.Text, sm.Sender));

            //根据信息Level选择不同行为
            MessageLevel ml = (MessageLevel)Enum.Parse(typeof(MessageLevel), mlName);
            switch (ml)
            {
                case MessageLevel.ML_CONFIRM:
                    break;
                case MessageLevel.ML_ERROR:
                    break;
            }
        }

        public void OnPositionChange(string id, int action)
        {
            string mtName = Enum.GetName(typeof(MessageType), action);
            if (mtName == null)
                return;
            //设置消息类型
            MessageType mt = (MessageType)Enum.Parse(typeof(MessageType), mtName);
            switch (mt)
            {
                case MessageType.MT_NEW_POSITION:

                    //开仓确认
                    break;
                case MessageType.MT_CLOSE_POSITION:

                    //平仓确认
                    break;
            }
        }

        public void OnConnectionLost()
        {

              //服务器断开连接
        }

        public void OnChangesComplete()
        {

             //更新完成
             //当所有更新完成,从服务器上获取更新,赋值给本地变量
            API.ServerMessages.GetRefreshRate();
        }
    }
抢钱,抢粮,抢地盘!
发新话题