Beispiel #1
0
 public void Connect()
 {
     lock (locker)
     {
         MdApi.MD_Connect();
     }
 }
        private void button2_Click(object sender, EventArgs e)
        {
            MdApi md  = MdApi.Instance;
            int   ret = md.Init("*****@*****.**", "Chs771005", MDMode.MD_MODE_NULL);

            if (ret != 0)
            {
                //登录失败
                return;
            }
            //List<Instrument> insts = md.GetInstruments("SHSE", 1, 1);
            //insts.AddRange(md.GetInstruments("SZSE", 1, 1));
            List <Tick> tickLists = new List <Tick>();
            //foreach (Instrument inst in insts)
            //{
            //    List<Tick> tickList = md.GetLastNTicks(inst.symbol, 1, "2016-03-26 15:01:00");
            //    tickLists.AddRange(tickList);
            //}
            List <Tick> tickList = md.GetLastNTicks("SHSE.600830", 1, "2018-08-13 15:00:00");

            //List<Tick> tickList = md.GetTicks("SHSE.600830", "2018-08-13 00:00:00", "2018-08-13 15:05:00");
            //List<Tick> tickList = md.GetTicks("SZSE.300334", "2017-05-12 00:00:00", "2017-05-12 15:00:00");
            tickLists.AddRange(tickList);
            DateTime startTimeUTC = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));

            foreach (Tick tick in tickLists)
            {
                tick.strtime = startTimeUTC.AddSeconds(tick.utc_time).ToString();
            }
            ShowData(tickLists.OfType <object>().ToList());
            this.label1.Text = tickLists.Count.ToString();
        }
Beispiel #3
0
 public virtual void Unsubscribe(string inst, string period)
 {
     lock (locker)
     {
         MdApi.MD_Unsubscribe(inst, period);
     }
 }
Beispiel #4
0
 public void Disconnect()
 {
     lock (locker)
     {
         MdApi.MD_Disconnect();
     }
 }
Beispiel #5
0
        public async Task <IActionResult> UploadAndProcess(IFormFile file)
        {
            var content = new List <String>();

            if (file != null && file.Length > 0)
            {
                if (SystemConstants.AcceptedExtensions.Contains(Path.GetExtension(file.FileName).ToUpperInvariant()))
                {
                    using (var Reader = new System.IO.StreamReader(file.OpenReadStream()))
                    {
                        string inputLine = "";
                        while ((inputLine = await Reader.ReadLineAsync()) != null)
                        {
                            content.Add(inputLine);
                        }
                        Reader.Close();
                    }
                    //Upload
                    var res = await MdApi.PostPNLAsync(content);

                    return(PartialView("_PartialPassengerList", res));
                }
                else
                {
                    return(BadRequest(new { Result = false, Message = "please upload txt only" }));
                }
            }
            return(BadRequest(new { Result = false, Message = "Empty file" }));
        }
Beispiel #6
0
 public void SubscribeHistory(string inst, string period, string beginTime, string endTime)
 {
     lock (locker)
     {
         MdApi.MD_SubscribeHistory(inst, period, beginTime, endTime);
     }
 }
Beispiel #7
0
 public void ReqQryQuotation(ref CWtpSymbolField pInstrumentID)
 {
     lock (locker)
     {
         MdApi.ReqQryQuotation(ref pInstrumentID);
     }
 }
Beispiel #8
0
 public void ReqUserLogout(ref CWtpUserLogoutField pReqUserLogoutField)
 {
     lock (locker)
     {
         MdApi.ReqUserLogout(ref pReqUserLogoutField);
     }
 }
Beispiel #9
0
 public void ReqQrySymbol()
 {
     lock (locker)
     {
         MdApi.ReqQrySymbol();
     }
 }
Beispiel #10
0
 public void ReqUserLogin(ref CWtpReqUserLoginField pReqUserLoginField)
 {
     lock (locker)
     {
         MdApi.ReqUserLogin(ref pReqUserLoginField);
     }
 }
Beispiel #11
0
 public void RegisterFront(string pszFrontAddress)
 {
     lock (locker)
     {
         MdApi.RegisterFront(pszFrontAddress);
     }
 }
Beispiel #12
0
 public virtual void UnsubscribeQuote(string inst, string szExchange)
 {
     lock (locker)
     {
         MdApi.MD_UnsubscribeQuote(inst, szExchange);
     }
 }
Beispiel #13
0
 public void ReqUnSubQuotation(ref CWtpSymbolField[] pInstrumentID)
 {
     lock (locker)
     {
         MdApi.ReqUnSubQuotation(pInstrumentID, pInstrumentID.Length);
     }
 }
Beispiel #14
0
 public void Dispose()
 {
     lock (locker)
     {
         MdApi.Release();
         GC.SuppressFinalize(this);
     }
 }
Beispiel #15
0
        public void CTP_RegMD()
        {
            MdApi.CTP_RegOnRtnDepthMarketData_Tick(OnRtnDepthMarketData_Tick_2);
            MdApi.CTP_RegOnRtnDepthMarketData_KLine(OnRtnDepthMarketData_KLine_2);
            MdApi.CTP_RegOnHistory_Tick(OnHistoryTick_2);
            MdApi.CTP_RegOnHistory_KLine(OnHistoryKLine_2);

            MdApi.CTP_RegMDOnConnect(OnConnect_2);
            MdApi.CTP_RegMDOnDisconnect(OnDisconnect_2);
            MdApi.CTP_RegMDOnRspError(OnRspError_2);
        }
Beispiel #16
0
 public void WTP_RegMD()
 {
     MdApi.WTP_RegOnFrontConnected(OnConnect_2);
     MdApi.WTP_RegOnFrontDisconnected(OnDisconnect_2);
     MdApi.WTP_RegOnRspUserLogin(OnRspUserLogin_2);
     MdApi.WTP_RegOnRspUserLogout(OnRspUserLogout_2);
     MdApi.WTP_RegOnRspError(OnRspError_2);
     MdApi.WTP_RegOnRspQrySymbol(OnRspQrySymbol_2);
     MdApi.WTP_RegOnRspQryQuotation(OnRspQryQuotation_2);
     MdApi.WTP_RegOnRtnQuotation(OnRtnQuotation_2);
 }
Beispiel #17
0
 public virtual void UnsubscribeQuote(string inst, string szExchange)
 {
     lock (locker)
     {
         MdApi.MD_UnsubscribeQuote(IntPtrKey, inst, szExchange);
         inst.Split(new char[2] {
             ';', ','
         }).ToList().ForEach(x =>
                             _SubscribedQuotes.Remove(x)
                             );
     }
 }
Beispiel #18
0
 private void Disconnect_MD()
 {
     lock (_lock)
     {
         if (null != Api && IntPtr.Zero != Api)
         {
             MdApi.MD_RegMsgQueue2MdApi(Api, IntPtr.Zero);
             MdApi.MD_ReleaseMdApi(Api);
             Api = IntPtr.Zero;
         }
         IsConnected = false;
     }
 }
Beispiel #19
0
        static void Main(string[] args)
        {
            MdApi.CTP_ReadConfigFile("F:\\CTP-MATLAB\\bin\\ConfigFile.xml");

            MdApi.CTP_RegMDOnConnect(OnConnect);
            MdApi.CTP_RegOnRtnDepthMarketData_Tick(OnRtnDepthMarketData_Tick);
            MdApi.MD_Connect();
            TdApi.TD_Connect();

            while (true)
            {
            }
        }
Beispiel #20
0
 private void Connect_MD()
 {
     lock (_lock)
     {
         if (null == Api || IntPtr.Zero == Api)
         {
             Api = MdApi.MD_CreateMdApi();
             MdApi.CTP_RegOnRtnDepthMarketData(m_pMsgQueue, _fnOnRtnDepthMarketData_Holder);
             MdApi.MD_RegMsgQueue2MdApi(Api, m_pMsgQueue);
             MdApi.MD_Connect(Api, tempPath, string.Join(";", server.MarketData.ToArray()), server.BrokerID, account.InvestorId, account.Password);
         }
     }
 }
Beispiel #21
0
 private void Disconnect_MD()
 {
     lock (_lockMd)
     {
         if (null != m_pMdApi && IntPtr.Zero != m_pMdApi)
         {
             MdApi.MD_RegMsgQueue2MdApi(m_pMdApi, IntPtr.Zero);
             MdApi.MD_ReleaseMdApi(m_pMdApi);
             m_pMdApi = IntPtr.Zero;
         }
         _bMdConnected = false;
     }
 }
Beispiel #22
0
        public override void Disconnect()
        {
            lock (locker)
            {
                if (null != IntPtrKey && IntPtr.Zero != IntPtrKey)
                {
                    MdApi.MD_RegMsgQueue2MdApi(IntPtrKey, IntPtr.Zero);
                    MdApi.MD_ReleaseMdApi(IntPtrKey);
                    IntPtrKey = IntPtr.Zero;
                }

                base.Disconnect();
            }
        }
Beispiel #23
0
        private void button9_Click_1(object sender, EventArgs e)
        {
            MdApi md  = MdApi.Instance;
            int   ret = md.Init("*****@*****.**", "Chs771005", MDMode.MD_MODE_NULL);

            if (ret != 0)
            {
                //登录失败
                return;
            }
            List <StockAdjustFactor> stockAdjs = md.GetStockAdj("SZSE.300044", "2018-01-01", "2018-08-06");

            ShowData(stockAdjs.OfType <object>().ToList());
        }
Beispiel #24
0
        private void button7_Click(object sender, EventArgs e)
        {
            MdApi md  = MdApi.Instance;
            int   ret = md.Init("*****@*****.**", "Chs771005", MDMode.MD_MODE_NULL);

            if (ret != 0)
            {
                //登录失败
                return;
            }
            List <MarketIndex> marketindex = md.GetLastNMarketIndex("SHSE.600004", 3);

            ShowData(marketindex.OfType <object>().ToList());
        }
Beispiel #25
0
        public override void Connect()
        {
            lock (locker)
            {
                base.Connect();

                IntPtrKey = MdApi.MD_CreateMdApi();
                MdApi.MD_RegMsgQueue2MdApi(IntPtrKey, _MsgQueue.Queue);

                MdApi.MD_Connect(IntPtrKey, _TempPath,
                                 _Front.MarketDataAddress, _Front.BrokerId,
                                 _Account.InvestorId, _Account.Password);
            }
        }
Beispiel #26
0
        private void button4_Click(object sender, EventArgs e)
        {
            MdApi md  = MdApi.Instance;
            int   ret = md.Init("*****@*****.**", "Chs771005", MDMode.MD_MODE_NULL);

            if (ret != 0)
            {
                //登录失败
                return;
            }
            List <Instrument> insts = md.GetInstruments("SHSE", 1, 0);

            ShowData(insts.OfType <object>().ToList());
            this.label1.Text = insts.Count.ToString();
        }
Beispiel #27
0
 public virtual void SubscribeQuote(string inst, string szExchange)
 {
     lock (locker)
     {
         MdApi.MD_SubscribeQuote(IntPtrKey, inst, szExchange);
         inst.Split(new char[2] {
             ';', ','
         }).ToList().ForEach(x =>
         {
             if (!string.IsNullOrWhiteSpace(x))
             {
                 _SubscribedQuotes.Add(x);
             }
         });
     }
 }
Beispiel #28
0
        public async Task <IActionResult> AddRecord(PassengerRecord record)
        {
            if (string.IsNullOrEmpty(record.Key) || string.IsNullOrEmpty(record.LastName))
            {
                return(BadRequest(new { Result = false, Message = "Key & last name must not empty" }));
            }

            if (record.Key.Length != 6)
            {
                return(BadRequest(new { Result = false, Message = "key length must be 6 letters" }));
            }


            var res = await MdApi.AddRecord(record);

            return(PartialView("_PartialPassengerList", res));
        }
Beispiel #29
0
        //建立行情
        private void Connect_MD()
        {
            lock (_lockMd)
            {
                if (_bWantMdConnect &&
                    (null == m_pMdApi || IntPtr.Zero == m_pMdApi))
                {
                    m_pMdApi = MdApi.MD_CreateMdApi();
                    MdApi.XSpeed_RegOnMarketData(m_pMsgQueue, _fnOnMarketData_Holder);
                    MdApi.MD_RegMsgQueue2MdApi(m_pMdApi, m_pMsgQueue);
                    MdApi.MD_Connect(m_pMdApi, string.Join(";", server.MarketData.ToArray()), account.InvestorId, account.Password, 0);

                    //向单例对象中注入操作用句柄
                    XSpeedAPI.GetInstance().__RegMdApi(m_pMdApi);
                }
            }
        }
Beispiel #30
0
        //建立行情
        private void Connect_MD()
        {
            lock (_lockMd)
            {
                if (_bWantMdConnect &&
                    (null == m_pMdApi || IntPtr.Zero == m_pMdApi))
                {
                    m_pMdApi = MdApi.MD_CreateMdApi();
                    MdApi.CTP_RegOnRtnDepthMarketData(m_pMsgQueue, _fnOnRtnDepthMarketData_Holder);
                    MdApi.MD_RegMsgQueue2MdApi(m_pMdApi, m_pMsgQueue);
                    MdApi.MD_Connect(m_pMdApi, _newTempPath, string.Join(";", server.MarketData.ToArray()), server.BrokerID, account.InvestorId, account.Password);

                    //向单例对象中注入操作用句柄
                    CTPAPI.GetInstance().__RegMdApi(m_pMdApi);
                }
            }
        }
Beispiel #31
0
        /// <summary>
        /// 初始化 MD 对象
        /// </summary>
        public static void initMd()
        {
            if (isInit)
            {
                return;
            }

            //本例子演示如何用行情API提取数据
            md = MdApi.Instance;

            int ret = md.Init("18221685724", "yjb_1983");

            if (ret != 0)
            {
                isInit = false;
                //登录失败
                return;
            }
            else
            {
                isInit = true;
            }
        }