Пример #1
0
        private void OnReceiveRealDataEventHandler(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealDataEvent e)
        {
            //Console.WriteLine("[DEBUG] OnReceiveRealData - e.sRealKey : " + e.sRealKey + ", e.sRealType : " + e.sRealType + ", e.sRealData : " + e.sRealData);
            // 보유 종목에 있을 경우 값 업데이트
            string market = openApi.GetCommRealData(e.sRealKey, 290).Trim();

            if (market.Equals("2")) // 장 중
            {
                Holding holding = holdings.SingleOrDefault(item => item.StockNo.Contains(e.sRealKey));
                if (holding != null)
                {
                    long currentPrice = long.Parse(Regex.Replace(openApi.GetCommRealData(e.sRealKey, 10).Trim(), @"[^0-9]", ""));
                    holding.CurrentPrice = String.Format("{0:#,###0}", currentPrice);
                }

                ConditionStock conditionStock = conditionStocks.SingleOrDefault(item => item.StockNo.Contains(e.sRealKey));
                if (conditionStock != null)
                {
                    long currentPrice = long.Parse(Regex.Replace(openApi.GetCommRealData(e.sRealKey, 10).Trim(), @"[^0-9]", ""));
                    conditionStock.CurrentPrice = String.Format("{0:#,###0}", currentPrice);

                    float fluctuationRate = float.Parse(openApi.GetCommRealData(e.sRealKey, 12).Trim());
                    conditionStock.FluctuationRate = String.Format("{0:f2}", fluctuationRate);

                    // 주문 목록에 없고, 보유종목에 없으면 매수
                    // 주문이 들어가기 전에 한번 더 요청이 오면? 안되겠군..
                    // 조건 검색에 편입되는 순간 확인하고..큐에 넣고 큐를 뒤져야하나?
                    // 편입, 이탈이 반복되는 경우는 어떻게 하지?
                    if (holding != null)
                    {
                    }
                }
            }
        }
Пример #2
0
    private void API_OnReceiveRealData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealDataEvent e)
    {
        string itemCode = e.sRealKey.Trim();


        if (e.sRealType == ConstName.RECEIVE_REAL_DATA_CONCLUSION)         //주식이 체결될 때 마다 실시간 데이터를 받음
        {
            string price     = axKHOpenAPI1.GetCommRealData(itemCode, 10); //현재가
            string lowPrice  = axKHOpenAPI1.GetCommRealData(itemCode, 18); //저가
            string openPrice = axKHOpenAPI1.GetCommRealData(itemCode, 16); //시가

            long c_lPrice = Math.Abs(long.Parse(price));
        }
    }
Пример #3
0
        public void axKHOpenAPI_OnReceiveRealData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealDataEvent e)
        {
            string itemCode = e.sRealKey.Trim();

            if (e.sRealType.Contains(ConstName.RECEIVE_REAL_DATA_HOGA) || e.sRealType.Contains(ConstName.RECEIVE_REAL_DATA_USUN_HOGA))
            {
                StockWithBiddingEntity newObj = new StockWithBiddingEntity();
                newObj.Code = itemCode;

                int maxAmount = 0;
                for (int i = 0; i < 10; i++)
                {
                    string sellhoga = axKHOpenAPI.GetCommRealData(e.sRealType, 50 - i).Trim().Replace("+", "");
                    string sellqnt  = axKHOpenAPI.GetCommRealData(e.sRealType, 70 - i).Trim();
                    //잔량대비 = axKHOpenAPI1.GetCommRealData(e.sRealType, 90 - i).Trim(),
                    if (!string.IsNullOrEmpty(sellhoga))
                    {
                        newObj.SetSellHoga(i, long.Parse(sellhoga));
                    }
                    if (!string.IsNullOrEmpty(sellqnt))
                    {
                        newObj.SetSellQnt(i, long.Parse(sellqnt));
                    }


                    string buyhoga = axKHOpenAPI.GetCommRealData(e.sRealType, 51 + i).Trim().Replace("+", "");
                    string buyqnt  = axKHOpenAPI.GetCommRealData(e.sRealType, 71 + i).Trim();
                    if (!string.IsNullOrEmpty(buyhoga))
                    {
                        newObj.SetBuyHoga(i, long.Parse(buyhoga));
                    }
                    if (!string.IsNullOrEmpty(buyqnt))
                    {
                        newObj.SetBuyQnt(i, long.Parse(buyqnt));
                    }
                    //    잔량대비 = axKHOpenAPI1.GetCommRealData(e.sRealType, 91 + i).Trim(),

                    //int sellAmount = int.Parse(axKHOpenAPI.GetCommRealData(e.sRealType, 70 - i).Trim());
                    //int buyAmount = int.Parse(axKHOpenAPI.GetCommRealData(e.sRealType, 71 + i).Trim());

                    //if (maxAmount < sellAmount)
                    //    maxAmount = sellAmount;
                    //if (maxAmount < buyAmount)
                    //    maxAmount = buyAmount;
                }

                StockWithBiddingManager.GetInstance().SetItem(newObj);
            }
        }
Пример #4
0
        internal override void OnReceiveRealData(_DKHOpenAPIEvents_OnReceiveRealDataEvent e)
        {
            var index = 0;
            var sb    = new StringBuilder(API.GetCommRealData(e.sRealKey, Fid[index]));

            for (index = 0; index < 0x30; index++)
            {
                sb.Append(';').Append(API.GetCommRealData(e.sRealKey, Fid[index + 3]));
            }

            if (sb.Length > 0x1F)
            {
                Server.WriteLine(string.Concat(e.sRealType, '|', e.sRealKey, '|', sb));
            }
        }
Пример #5
0
        /// <summary>
        ///[25]설명 실시간데이터를 반환한다.
        ///입력값
        ///strRealType – 실시간 구분
        ///nFid – 실시간 아이템
        ///반환값 수신 데이터
        ///비고 Ex) 현재가출력 - openApi.GetCommRealData(“주식시세”, 10);/// <summary>
        ///
        ///참고)실시간 현재가는 주식시세, 주식체결 등 다른 실시간타입(RealType)으로도 수신가능
        /// </summary>
        public String GetCommRealData(String strRealType, int nFid)
        {
            String ret = axKHOpenAPI.GetCommRealData(strRealType, nFid);

            FileLog.PrintF("GetCommRealData(" + strRealType + "," + nFid + "):" + ret);
            return(ret);
        }
Пример #6
0
        private void OnReceiveRealData(object sender, _DKHOpenAPIEvents_OnReceiveRealDataEvent e)
        {
            sb = new StringBuilder(512);

            foreach (int fid in Array.Find(catalog, o => o.ToString().Contains(e.sRealType)))
            {
                sb.Append(axAPI.GetCommRealData(e.sRealKey, fid)).Append(',');
            }

            if (e.sRealType.Equals(sRealType[0]))
            {
                SendTick?.Invoke(this, new TickEvent(sb));
                SendDay?.Invoke(this, new DayEvent(sb));

                return;
            }
            if (e.sRealType.Equals(sRealType[1]) && int.Parse(sb.ToString().Substring(0, 6)) > 153459)
            {
                string[] fg = sb.ToString().Split(',');

                if (fg[52].Contains("-"))
                {
                    fg[52] = fg[52].Substring(1);
                }

                double price = double.Parse(fg[52]);

                SendTick?.Invoke(this, new TickEvent(false, fg[0], price, 0));
                SendDay?.Invoke(this, new DayEvent(false, price));

                return;
            }
            if (e.sRealType.Equals(sRealType[2]))
            {
                string[] tg = sb.ToString().Split(',');

                if (tg[0].Equals("e") && Deadline == false)
                {
                    Deadline = true;

                    Request();

                    SendExit?.Invoke(this, new ForceQuit(0));
                }
                return;
            }
            sb = null;
        }
Пример #7
0
        private void AxKHOpenAPI_OnReceiveRealData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealDataEvent e)
        {
            if (e.sRealType == "주식체결")
            {
                double conclusionVolume = double.Parse(axKHOpenAPI.GetCommRealData(e.sRealType, 15));

                if (exceptList.Contains(conclusionVolume))
                {
                    return;
                }

                int    conclusionTime = Int32.Parse(axKHOpenAPI.GetCommRealData(e.sRealType, 20));
                double curPrice       = double.Parse(axKHOpenAPI.GetCommRealData(e.sRealType, 10));
                if (curPrice < 0)
                {
                    curPrice *= -1;
                }
                int    gapPrice            = Int32.Parse(axKHOpenAPI.GetCommRealData(e.sRealType, 11));
                double gapPercentage       = double.Parse(axKHOpenAPI.GetCommRealData(e.sRealType, 12));
                double allConclusionVolume = double.Parse(axKHOpenAPI.GetCommRealData(e.sRealType, 13));

                int hour    = conclusionTime / 10000;
                int minutes = conclusionTime / 100 % 100;
                int second  = conclusionTime % 100;

                int realTime = hour * 3600 + minutes * 60 + second;

                if (allConclusionVolume >= VOLUME_UP_BUY || allConclusionVolume <= VOLUME_UP_SELL)
                {
                    ThreadPool.QueueUserWorkItem(StockItemElementMgr.GetInstance().ThreadPoolCallBack, new TradeData(e.sRealKey, curPrice, realTime, conclusionVolume));
                }

                if (myStockItem.myStockItemDic.ContainsKey(e.sRealKey))
                {
                    myStockItem.myStockItemDic[e.sRealKey].curPrice      = curPrice;
                    myStockItem.myStockItemDic[e.sRealKey].curVolume     = conclusionVolume;
                    myStockItem.myStockItemDic[e.sRealKey].gapPercentage = gapPercentage;
                    myStockItem.myStockItemDic[e.sRealKey].gapPrice      = gapPrice;
                }
                else
                {
                    SavedStockItem savedStockItme = new SavedStockItem(e.sRealKey.Trim().Replace("A", ""), axKHOpenAPI.GetMasterCodeName(e.sRealKey), gapPercentage, gapPrice, curPrice, conclusionVolume);
                    myStockItem.myStockItemDic.Add(e.sRealKey, savedStockItme);
                }

                OnReceiveRealDataHandler?.Invoke(this, new StockEventArgs(myStockItem));
            }
        }