Пример #1
0
        public void AxKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            if (e.sRQName.Equals("틱데이터차트조회"))
            {
                allSeries.Clear();

                int count = axKHOpenAPI1.GetRepeatCnt(e.sTrCode, e.sRQName);
                count = Math.Min(count, MAX_TICK);
                for (int i = 0; i < count; ++i)
                {
                    long curPrice  = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "현재가")));
                    long openPrice = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "시가")));
                    long highPrice = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "고가")));
                    long lowPrice  = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "저가")));

                    long curVol = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "거래량"));

                    string conclusionTime = (axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "체결시간")).Trim();

                    CustomSeries series = new CustomSeries(conclusionTime, highPrice, lowPrice, openPrice, curPrice, curVol);

                    allSeries.Add(series);
                }
                MA_Calculate();
            }
        }
Пример #2
0
        private void onReceiveKiwoomApiEvent(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            if (e.sRQName == "일봉조회")
            {
                StockDataCollector.isLockApi = true;
                int cnt = kiWoomApi.GetRepeatCnt(e.sTrCode, e.sRQName);
                if (cnt == 0)
                {
                    LogUtil.logConsole(" count zero!! ");
                }
                else
                {
                    String code = getReceiveDataCode(e);
                    List <DailyTradingModel> list = new List <DailyTradingModel>();

                    // if most recent data is inserted then skip logic
                    DailyTradingModel recentModel = makeDailyTradingModel(e, 0, code);
                    if (!checkIsInsertedData(code, recentModel))
                    {
                        DateTime          recentDate = dbController.selectRecentTradingDate(code);
                        DailyTradingModel firstModel = makeDailyTradingModel(e, cnt - 1, code);
                        DailyTradingModel lastModel  = makeDailyTradingModel(e, 0, code);

                        bool isFirstInserted = compareRecentDateAndModelDate(recentDate, firstModel.TradingDate);
                        bool isLastInserted  = compareRecentDateAndModelDate(recentDate, lastModel.TradingDate);

                        for (int idx = 0; idx < cnt; idx++)
                        {
                            DailyTradingModel model = makeDailyTradingModel(e, (cnt - 1) - idx, code);
                            bool isInserted         = compareRecentDateAndModelDate(recentDate, model.TradingDate);
                            if (!isInserted)
                            {
                                list.Add(model);
                            }
                            else if (isFirstInserted && isLastInserted)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        LogUtil.logConsole("SKIP : " + code);
                    }

                    if (list.Count != 0)
                    {
                        dbController.insertDailyBatchData(list);
                        LogUtil.logConsole(" db inserteds ");
                    }
                }
                StockDataCollector.isLockApi = false;
            }
        }
Пример #3
0
        public void AxKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            if (!init)
            {
                return;
            }

            if (e.sRQName.Contains(ConstName.RECEIVE_TR_DATA_MINUTE_CHART))
            {
                string[] strArray = e.sRQName.Split(':');
                string   itemcode = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "종목코드").Replace("A", "").Trim();

                if (strArray.Length == 2)
                {
                    if (strArray[1] != screenNumber)
                    {
                        return;
                    }
                }

                priceList.Clear();
                priceMA_List.Clear();
                priceMA_Envelope_List.Clear();

                int count = axKHOpenAPI1.GetRepeatCnt(e.sTrCode, e.sRQName);
                count = Math.Min(count, MAX_CANDLE);

                for (int i = 0; i < count; ++i)
                {
                    long curPrice  = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "현재가")));
                    long openPrice = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "시가")));
                    long highPrice = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "고가")));
                    long lowPrice  = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "저가")));

                    long   curVol         = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "거래량"));
                    string conclusionTime = (axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "체결시간")).Trim();
                    string format         = "yyyyMMddHHmmss";

                    DateTime concludeTime = DateTime.ParseExact(conclusionTime, format, CultureInfo.InvariantCulture);

                    priceList.Add(curPrice);
                }

                for (int i = 0; i < priceList.Count; ++i)
                {
                    if (i + MA_PERIOD < priceList.Count)
                    {
                        long priceSum = 0;
                        for (int j = 0; j < MA_PERIOD; ++j)
                        {
                            priceSum += (long)priceList[i + j];
                        }
                        double priceAverage = priceSum / MA_PERIOD;
                        priceMA_List.Add((long)priceAverage);
                        priceMA_Envelope_List.Add((long)(priceAverage * (1.0 - MA_PERCENT)));
                    }
                }

                if (afterEventFunction != null && priceList.Count > 0 && priceMA_Envelope_List.Count > 0)
                {
                    if (afterEventFunction.ContainsKey(itemcode))
                    {
                        afterEventFunction[itemcode].Invoke(itemcode, priceList[0], priceMA_Envelope_List[0]);
                    }
                }
            }
        }
Пример #4
0
        public void AxKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            if (e.sRQName.Contains(ConstName.RECEIVE_TR_DATA_KOSPI_MINUTE_CHART) || e.sRQName.Contains(ConstName.RECEIVE_TR_DATA_TICK_CHART) || e.sRQName.Contains(ConstName.RECEIVE_TR_DATA_MINUTE_CHART))
            {
                if (candleChart.Series == null)
                {
                    return;
                }

                string[] strArray = e.sRQName.Split(':');

                if (strArray.Length == 2)
                {
                    if (strArray[1] != screenNumber)
                    {
                        return;
                    }
                }

                if (e.sRQName.Contains(ConstName.RECEIVE_TR_DATA_KOSPI_MINUTE_CHART) == false)
                {
                    itemcode = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "종목코드").Replace("A", "").Trim();
                    if (chartItemCodeTextBox.Text != itemcode)
                    {
                        return;
                    }
                }

                candleChart.Series["StockCandle"].Points.Clear();
                candleChart.Series["Volume"].Points.Clear();

                candleChart.Series["VWMA"].Points.Clear();
                candleChart.Series["VPCI"].Points.Clear();

                int count = axKHOpenAPI1.GetRepeatCnt(e.sTrCode, e.sRQName);
                count = Math.Min(count, MAX_CANDLE);
                for (int i = 0; i < count; ++i)
                {
                    long curPrice  = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "현재가")));
                    long openPrice = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "시가")));
                    long highPrice = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "고가")));
                    long lowPrice  = Math.Abs(long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "저가")));

                    long curVol = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "거래량"));

                    string conclusionTime = (axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "체결시간")).Trim();

                    string format = "yyyyMMddHHmmss";

                    int index = candleChart.Series["StockCandle"].Points.AddXY(DateTime.ParseExact(conclusionTime, format, CultureInfo.InvariantCulture).ToString("HH:mm:ss"), highPrice);

                    candleChart.Series["StockCandle"].Points[index].YValues[1] = lowPrice;
                    candleChart.Series["StockCandle"].Points[index].YValues[2] = openPrice;
                    candleChart.Series["StockCandle"].Points[index].YValues[3] = curPrice; //종가 == 현재가

                    if (openPrice < curPrice)
                    {
                        candleChart.Series["StockCandle"].Points[index].Color       = Color.Red;
                        candleChart.Series["StockCandle"].Points[index].BorderColor = Color.Red;
                    }
                    else
                    {
                        candleChart.Series["StockCandle"].Points[index].Color       = Color.Blue;
                        candleChart.Series["StockCandle"].Points[index].BorderColor = Color.Blue;
                    }

                    int volume_index = candleChart.Series["Volume"].Points.AddXY(DateTime.ParseExact(conclusionTime, format, CultureInfo.InvariantCulture).ToString("HH:mm:ss"), curVol);

                    candleChart.Series["VWMA"].Points.AddXY(DateTime.ParseExact(conclusionTime, format, CultureInfo.InvariantCulture).ToString("HH:mm:ss"), 0);
                    candleChart.Series["VPCI"].Points.AddXY(DateTime.ParseExact(conclusionTime, format, CultureInfo.InvariantCulture).ToString("HH:mm:ss"), 0);
                }
                MakeMA();
                MakeVWMA();
                MakeVPCI();
            }
        }