예제 #1
0
        bool ORDER_ACTION_SENT = false; //是否发送了报单

        public void Run()
        {
            api = new CTPTraderAdapter();
            api.OnFrontConnected           += new FrontConnected(OnFrontConnected);
            api.OnFrontDisconnected        += new FrontDisconnected(OnFrontDisconnected);
            api.OnHeartBeatWarning         += new HeartBeatWarning(OnHeartBeatWarning);
            api.OnRspError                 += new RspError(OnRspError);
            api.OnRspUserLogin             += new RspUserLogin(OnRspUserLogin);
            api.OnRspOrderAction           += new RspOrderAction(OnRspOrderAction);
            api.OnRspOrderInsert           += new RspOrderInsert(OnRspOrderInsert);
            api.OnRspQryInstrument         += new RspQryInstrument(OnRspQryInstrument);
            api.OnRspQryInvestorPosition   += new RspQryInvestorPosition(OnRspQryInvestorPosition);
            api.OnRspQryTradingAccount     += new RspQryTradingAccount(OnRspQryTradingAccount);
            api.OnRspSettlementInfoConfirm += new RspSettlementInfoConfirm(OnRspSettlementInfoConfirm);
            api.OnRtnOrder                 += new RtnOrder(OnRtnOrder);
            api.OnRtnTrade                 += new RtnTrade(OnRtnTrade);

            api.SubscribePublicTopic(EnumTeResumeType.THOST_TERT_RESTART);                                      // 注册公有流
            api.SubscribePrivateTopic(EnumTeResumeType.THOST_TERT_RESTART);                                     // 注册私有流

            try
            {
                api.RegisterFront(FRONT_ADDR);
                api.Init();
                api.Join(); // 阻塞直到关闭或者CTRL+C
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                api.Release();
            }
        }
예제 #2
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            api.SubscribePublicTopic(EnumTeResumeType.THOST_TERT_RESTART);
            api.SubscribePrivateTopic(EnumTeResumeType.THOST_TERT_RESTART);

            api.RegisterFront(FRONT_ADDR);
            api.Init();
        }
예제 #3
0
        public void Init()
        {
            if (FrontAddrs == null || FrontAddrs.Length == 0)
            {
                HandleErrorInternal("CTP交易输入前置机地址不能为空!");
                return;
            }

            if (trader == null)
            {
                trader = new CTPTraderAdapter(".\\trade");
            }                                               // 创建trade目录存放流文件,避免与行情流文件冲突

            // 回调函数
            trader.OnFrontConnected           += new FrontConnected(OnFrontConnected);
            trader.OnFrontDisconnected        += new FrontDisconnected(OnFrontDisconnected);
            trader.OnHeartBeatWarning         += new HeartBeatWarning(OnHeartBeatWarning);
            trader.OnRspError                 += new RspError(OnRspError);
            trader.OnRspUserLogin             += new RspUserLogin(OnRspUserLogin);
            trader.OnRspOrderAction           += new RspOrderAction(OnRspOrderAction);
            trader.OnRspOrderInsert           += new RspOrderInsert(OnRspOrderInsert);
            trader.OnErrRtnOrderInsert        += new ErrRtnOrderInsert(OnErrRtnOrderInsert);
            trader.OnErrRtnOrderAction        += new ErrRtnOrderAction(OnErrRtnOrderAction);
            trader.OnRspQryInstrument         += new RspQryInstrument(OnRspQryInstrument);
            trader.OnRspQryInvestorPosition   += new RspQryInvestorPosition(OnRspQryInvestorPosition);
            trader.OnRspQryTradingAccount     += new RspQryTradingAccount(OnRspQryTradingAccount);
            trader.OnRspSettlementInfoConfirm += new RspSettlementInfoConfirm(OnRspSettlementInfoConfirm);
            trader.OnRtnOrder                 += new RtnOrder(OnRtnOrder);
            trader.OnRtnTrade                 += new RtnTrade(OnRtnTrade);


            // 订阅私有流
            trader.SubscribePrivateTopic(EnumTeResumeType.THOST_TERT_RESUME);
            // 订阅公共流
            trader.SubscribePublicTopic(EnumTeResumeType.THOST_TERT_RESUME);

            try
            {
                foreach (var frontAddr in FrontAddrs)
                {
                    trader.RegisterFront(frontAddr);
                }

                trader.Init();
            }
            catch (Exception ex)
            {
                HandleErrorInternal("CTP连接前置机发生错误:" + ex.Message);
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: aoxiang310/CPS
        bool ORDER_ACTION_SENT = false; //是否发送了报单

        public void Run()
        {
            api = new CTPTraderAdapter();
            api.OnFrontConnected           += new FrontConnected(OnFrontConnected);
            api.OnFrontDisconnected        += new FrontDisconnected(OnFrontDisconnected);
            api.OnHeartBeatWarning         += new HeartBeatWarning(OnHeartBeatWarning);
            api.OnRspError                 += new RspError(OnRspError);
            api.OnRspUserLogin             += new RspUserLogin(OnRspUserLogin);
            api.OnRspOrderAction           += new RspOrderAction(OnRspOrderAction);
            api.OnRspOrderInsert           += new RspOrderInsert(OnRspOrderInsert);
            api.OnRspQryInstrument         += new RspQryInstrument(OnRspQryInstrument);
            api.OnRspQryInvestorPosition   += new RspQryInvestorPosition(OnRspQryInvestorPosition);
            api.OnRspQryTradingAccount     += new RspQryTradingAccount(OnRspQryTradingAccount);
            api.OnRspSettlementInfoConfirm += new RspSettlementInfoConfirm(OnRspSettlementInfoConfirm);
            api.OnRtnOrder                 += new RtnOrder(OnRtnOrder);
            api.OnRtnTrade                 += new RtnTrade(OnRtnTrade);



            api.SubscribePublicTopic(EnumTeResumeType.THOST_TERT_QUICK);                                        // 注册公有流
            api.SubscribePrivateTopic(EnumTeResumeType.THOST_TERT_QUICK);                                       // 注册私有流

            try
            {
                api.RegisterFront(FRONT_ADDR);
                //ThostFtdcUserPasswordUpdateField req = new ThostFtdcUserPasswordUpdateField();
                //req.BrokerID = BROKER_ID;
                //req.UserID = INVESTOR_ID;
                //req.OldPassword = PASSWORD;
                //req.NewPassword = "******";
                //int iResult = api.ReqUserPasswordUpdate(req, iRequestID);
                //Console.WriteLine("--->>> 修改密码: " + ((iResult == 0) ? "修改成功" : "修改失败"));

                api.Init();
                api.Join(); // 阻塞直到关闭或者CTRL+C

                //修改密码
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                api.Release();
            }
        }