예제 #1
0
파일: Program.cs 프로젝트: aoxiang310/CPS
        public void Run()
        {
            api = new CTPMDAdapter();
            api.OnFrontConnected     += new FrontConnected(OnFrontConnected);
            api.OnFrontDisconnected  += new FrontDisconnected(OnFrontDisconnected);
            api.OnHeartBeatWarning   += new HeartBeatWarning(OnHeartBeatWarning);
            api.OnRspError           += new RspError(OnRspError);
            api.OnRspSubMarketData   += new RspSubMarketData(OnRspSubMarketData);
            api.OnRspUnSubMarketData += new RspUnSubMarketData(OnRspUnSubMarketData);
            api.OnRspUserLogin       += new RspUserLogin(OnRspUserLogin);
            api.OnRspUserLogout      += new RspUserLogout(OnRspUserLogout);
            api.OnRtnDepthMarketData += new RtnDepthMarketData(OnRtnDepthMarketData);

            try
            {
                api.RegisterFront(FRONT_ADDR);
                api.Init();
                api.Join(); // 阻塞直到关闭或者CTRL+C
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                api.Release();
            }
        }
예제 #2
0
        public void Init()
        {
            if (FrontAddrs == null || FrontAddrs.Length == 0)
            {
                HandleErrorInternal("前置机地址不能为空!");
                return;
            }

            try
            {
                if (mdApi == null)
                {
                    mdApi = new CTPMDAdapter(".\\md", false);                   // 创建md目录存放流文件,避免与交易流文件冲突
                    mdApi.OnFrontConnected     += new FrontConnected(OnFrontConnected);
                    mdApi.OnFrontDisconnected  += new FrontDisconnected(OnFrontDisconnected);
                    mdApi.OnRspUserLogout      += new RspUserLogout(OnRspUserLogout);
                    mdApi.OnRspUserLogin       += new RspUserLogin(OnRspUserLogin);
                    mdApi.OnRspSubMarketData   += new RspSubMarketData(OnRspSubMarketData);
                    mdApi.OnRspUnSubMarketData += new RspUnSubMarketData(OnRspUnSubMarketData);
                    mdApi.OnRtnDepthMarketData += new RtnDepthMarketData(OnRtnDepthMarketData);
                    mdApi.OnRspError           += new RspError(OnRspError);
                }

                foreach (var addr in FrontAddrs)
                {
                    mdApi.RegisterFront(addr);  // 注册所有的可用地址
                }

                mdApi.Init();
            }
            catch (Exception ex)
            {
                HandleErrorInternal("CTPMD.Start()异常:" + ex.Message + "\n" + ex.StackTrace);
            }
        }
예제 #3
0
 public void Run()
 {
     try
     {
         api.RegisterFront(_accountInfo.QuoteServerAddress);
         api.Init();
         // api.Join();
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
     }
 }
예제 #4
0
        /// <summary>
        /// 点击连接按钮连接前置机
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Connect_Click(object sender, EventArgs e)
        {
            sTDAddress = this.TextBox_TDADDRESS.Text;
            sMDAddress = this.TextBox_MDADDRESS.Text;
            sBrokerID = this.TextBox_BrokerID.Text;
            sUserID = this.TextBox_UserID.Text;
            sPassword = this.TextBox_PassWord.Text;
            sTableName = string.Empty;
            #region 数据库初始化
            //内存数据库打开
            if (this.radioButton_MemDB.Checked && MemDB == null)
            {
                MemDB = new SQLiteBase.SQLiteBase();
            }
            else if (MemDB == null)
            {
                MemDB = new SQLiteBase.SQLiteBase("InstrmentDataBase.db");
            }
            MemDB.OpenDB();
            #endregion
            #region 交易初始化
            CtpMDApi = new CTPMDAdapter("MDAPI", false);
            CtpMDApi.OnFrontConnected += new FrontConnected(sCtpMdApi.OnFrontConnected);
            CtpMDApi.OnFrontDisconnected += new FrontDisconnected(sCtpMdApi.OnFrontDisconnected);
            CtpMDApi.OnHeartBeatWarning += new HeartBeatWarning(sCtpMdApi.OnHeartBeatWarning);
            CtpMDApi.OnRspError += new RspError(sCtpMdApi.OnRspError);
            CtpMDApi.OnRspSubMarketData += new RspSubMarketData(sCtpMdApi.OnRspSubMarketData);
            CtpMDApi.OnRspUnSubMarketData += new RspUnSubMarketData(sCtpMdApi.OnRspUnSubMarketData);
            CtpMDApi.OnRspUserLogin += new RspUserLogin(sCtpMdApi.OnRspUserLogin);
            CtpMDApi.OnRspUserLogout += new RspUserLogout(sCtpMdApi.OnRspUserLogout);
            CtpMDApi.OnRtnDepthMarketData += new RtnDepthMarketData(sCtpMdApi.OnRtnDepthMarketData);
            //注册前置机
            CtpMDApi.RegisterFront(sMDAddress);
            //初始化
            CtpMDApi.Init();
            #endregion 交易初始化
            #region 行情初始化
            CtpTDApi = new CTPTDAdapter("TDAPI");
            CtpTDApi.OnFrontConnected += new FrontConnected(sCtpTdApi.OnFrontConnected);
            CtpTDApi.OnFrontDisconnected += new FrontDisconnected(sCtpTdApi.OnFrontDisconnected);
            CtpTDApi.OnHeartBeatWarning += new HeartBeatWarning(sCtpTdApi.OnHeartBeatWarning);
            CtpTDApi.OnRspError += new RspError(sCtpTdApi.OnRspError);
            CtpTDApi.OnRspUserLogin += new RspUserLogin(sCtpTdApi.OnRspUserLogin);
            CtpTDApi.OnRspOrderAction += new RspOrderAction(sCtpTdApi.OnRspOrderAction);
            CtpTDApi.OnRspOrderInsert += new RspOrderInsert(sCtpTdApi.OnRspOrderInsert);
            CtpTDApi.OnRspQryInstrument += new RspQryInstrument(sCtpTdApi.OnRspQryInstrument);
            CtpTDApi.OnRspQryInvestorPosition += new RspQryInvestorPosition(sCtpTdApi.OnRspQryInvestorPosition);
            CtpTDApi.OnRspQryInvestorPositionDetail += new RspQryInvestorPositionDetail(sCtpTdApi.OnRspQryInvestorPositionDetail);
            CtpTDApi.OnRspQryTradingAccount += new RspQryTradingAccount(sCtpTdApi.OnRspQryTradingAccount);
            CtpTDApi.OnRspSettlementInfoConfirm += new RspSettlementInfoConfirm(sCtpTdApi.OnRspSettlementInfoConfirm);
            CtpTDApi.OnRtnOrder += new RtnOrder(sCtpTdApi.OnRtnOrder);
            CtpTDApi.OnRtnTrade += new RtnTrade(sCtpTdApi.OnRtnTrade);
            //注册流



            switch (comboBox_ResumeType.Text)
            {
                case "断线恢复":
                    CtpTDApi.SubscribePublicTopic(EnumTeResumeType.THOST_TERT_RESUME);					// 注册公有流
                    CtpTDApi.SubscribePrivateTopic(EnumTeResumeType.THOST_TERT_RESUME);					// 注册私有流
                    break;
                case "当天全部":
                    CtpTDApi.SubscribePublicTopic(EnumTeResumeType.THOST_TERT_RESTART);					// 注册公有流
                    CtpTDApi.SubscribePrivateTopic(EnumTeResumeType.THOST_TERT_RESTART);					// 注册私有流
                    break;
                default:
                    CtpTDApi.SubscribePublicTopic(EnumTeResumeType.THOST_TERT_QUICK);					// 注册公有流
                    CtpTDApi.SubscribePrivateTopic(EnumTeResumeType.THOST_TERT_QUICK);					// 注册私有流
                    break;

            }

            //注册前置机
            CtpTDApi.RegisterFront(sTDAddress);
            //初始化
            CtpTDApi.Init();
            #endregion 行情初始化
        }