private void axKHOpenAPI1_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { int count = axKHOpenAPI1.GetRepeatCnt(e.sTrCode, e.sRQName); double[] rawData = new double[count]; for (int i = 0; i < count; i++) { rawData[i] = double.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "현재가")); } for (int i = 0; i < rawData.Length; i++) { s1.Points.AddXY(i + 1, rawData[i]); } double[] sampleData = sampling(rawData, 15); for (int i = 0; i < sampleData.Length; i++) { s2.Points.AddXY(i + 1, sampleData[i]); } double[] paaData = PAA(rawData, 15); for (int i = 0; i < paaData.Length; i++) { s3.Points.AddXY(i + 1, paaData[i]); } }
public void onReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sRQName == "종목정보요청") { long stockPrice = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "현재가").Trim().Replace("-", "")); string stockName = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "종목명").Trim(); long upDown = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "전일대비").Trim()); long volume = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "거래량").Trim()); string upDownRate = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "등락율").Trim(); stockPriceTxt.Text = String.Format("{0:#,###}", stockPrice); stockNameTxt.Text = stockName; stockUpDownTxt.Text = String.Format("{0:#,###}", upDown); stockVolumeTxt.Text = String.Format("{0:#,###}", volume); if (upDown == 0) { stockUpDownTxt.Text = "0"; } if (volume == 0) { stockVolumeTxt.Text = "0"; } stockUpDownRateTxt.Text = upDownRate + "%"; } }
public void onReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sRQName == "계좌평가잔고내역요청") { long totalPurchase = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "총매입금액")); long totalEstimate = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "총평가금액")); long totalProfitLoss = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "총평가손익금액")); double totalProfitRate = double.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "총수익률(%)")); } else if (e.sRQName == "예수금상세현황요청") { // pass } else if (e.sRQName == "실시간미체결요청") { // pass } else if (e.sRQName == "주식분봉차트조회") { // pass } else if (e.sRQName == "업종일봉차트조회") { // pass } }
private void AxKHOpenAPI_OnReceiveTrData1(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sRQName == "주식일봉차트조회") { string text = null; for (int nLoop = 0; nLoop < 10; nLoop++) { text += (DateTime.Today.AddDays(nLoop * -1).ToString()) + " : "; text += axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, nLoop, "현재가").Trim() + "/"; text += axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, nLoop, "시가").Trim() + "/"; text += axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, nLoop, "고가").Trim() + "/"; text += axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, nLoop, "저가").Trim(); text += Environment.NewLine; } Program.writeFileOnCurrDir("주식일봉차트조회", text); } if (e.sRQName == "주식분봉차트조회") { string text = null; for (int nLoop = 0; nLoop < 10; nLoop++) { text += (DateTime.Today.AddDays(nLoop * -1).ToString()) + " : "; text += axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, nLoop, "현재가").Trim() + "/"; text += axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, nLoop, "시가").Trim() + "/"; text += axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, nLoop, "고가").Trim() + "/"; text += axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, nLoop, "저가").Trim(); text += Environment.NewLine; } Program.writeFileOnCurrDir("주식분봉차트조회", text); } }
// watcing 주식 데이터 가지고 오는 공용 함수 public override void receive(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent apiEvent) { int count = this.getRowCount(apiEvent); for (int i = 0; i < count; i++) { try { string codeStr = this.getData("종목코드", apiEvent, i).Trim(); int code = 0; if (Int32.TryParse(codeStr, out code) == false) { continue; } string name = this.getData("종목명", apiEvent, i); if (this.isForbiddenStock(name)) { continue; } StockData stockData = new StockData(code, name, this.infoLevel()); StockManager.getInstance.addStockData(stockData); } catch (AccessViolationException execption) { Logger.getInstance.print(Log.에러, "[receive:{0}] {1}\n{2}\n{3}", this.ToString(), execption.Message, execption.StackTrace, execption.InnerException); return; } } }
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(); } }
public override void receive(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent apiEvent) { try { StockData stockData = StockManager.getInstance.stockData(stockCode_); if (stockData == null) { return; } lock (stockData.dataLock_) { stockData.clearPrice(priceType_); int count = this.getRowCount(apiEvent); for (int i = 0; i < count; i++) { string dateTime = this.dateTime(i, sender, apiEvent); int price = int.Parse(this.getData("현재가", apiEvent, i)); int startPrice = int.Parse(this.getData("시가", apiEvent, i)); int highPrice = int.Parse(this.getData("고가", apiEvent, i)); int lowPrice = int.Parse(this.getData("저가", apiEvent, i)); PriceData priceData = new PriceData(dateTime, price, startPrice, highPrice, lowPrice); stockData.updatePrice(priceType_, i, priceData); } } stockData.calculatePrice(priceType_); } catch (AccessViolationException execption) { Logger.getInstance.print(Log.에러, "[receive:{0}] {1}\n{2}\n{3}", this.ToString(), execption.Message, execption.StackTrace, execption.InnerException); } }
// 일반 주문 public void axKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent apiEvent) { try { string key = apiEvent.sRQName + apiEvent.sScrNo; StockStatement statement = this.getStockStatement(key); if (statement != null) { statement.receive(sender, apiEvent); } else { TradingStatement stat = this.getTradingStatement(apiEvent.sScrNo); if (stat != null) { stat.receive(sender, apiEvent); } else { Logger.getInstance.print(Log.StockAPI콜백, "[이 주문표 데이터가 삭제되었음. {0}", key); } } } catch (AccessViolationException execption) { Logger.getInstance.print(Log.에러, "[주문 콜백 에러] {0}\n{1}\n{2}", execption.Message, execption.StackTrace, execption.InnerException); } this.runNextOrderFlag(); }
public void runReceiveTrData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (IgnoreReceiveTrData(e.sTrCode) == false) { ReceiveTrData rt = getReceiveTrData(e.sTrCode); rt.ReceivedData(axKHOpenAPI, e); } }
private void AxKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sRQName == "계좌평가현황요청") { String a = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "예수금"); Console.WriteLine(a); } }
protected override string dateTime(int index, object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent apiEvent) { string date = this.getData("체결시간", apiEvent, index); string dd = date.Substring(date.Length - 8, 2); string min = date.Substring(date.Length - 6, 6); string dateTime = string.Format("{0}d {1}m#{2}", dd, min, index); return(dateTime); }
private void trBasicInformation(AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sScrNo.Equals(SCREEN_NO_SEARCH_RESULT)) { long currentPrice = long.Parse(Regex.Replace(kiwoomApi.GetCommData(e.sTrCode, e.sRQName, 0, "현재가").Trim(), @"[^0-9]", "")); Console.WriteLine("현재가 : " + currentPrice); numericUpDown2.Value = currentPrice; } }
private void trAccountEvaluationStatus(AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { // D+2추정예수금만 사용 string amount = kiwoomApi.GetCommData(e.sTrCode, e.sRQName, 0, "D+2추정예수금"); Console.WriteLine("D+2추정예수금 : (" + amount + ")"); availableAmount = string.IsNullOrEmpty(amount)?int.Parse(labelEstimatedBalance.Text, System.Globalization.NumberStyles.AllowThousands) :int.Parse(amount); log(LogMode.SYSTEM, "주문가능금액 : " + availableAmount); }
protected override string dateTime(int index, object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent apiEvent) { string date = this.getData("일자", apiEvent, index); string mm = date.Substring(date.Length - 4, 2); string dd = date.Substring(date.Length - 2, 2); string dateTime = string.Format("{0}m {1}d#{2}", mm, dd, index); return(dateTime); }
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; } }
// TR코드 요청 결과 (콜백함수) void OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { // TR코드 요청 결과 (RQ Name으로 구별) if (e.sRQName == "주식호가") { priceListBox.Items.Clear(); volumeListBox.Items.Clear(); for (int i = 10; i > 1; i--) { int 차선호가 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매도" + i + "차선호가")); priceListBox.Items.Add(차선호가); if (i == 6) { int 차선잔량 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매도" + i + "우선잔량")); volumeListBox.Items.Add(차선잔량); } else { int 차선잔량 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매도" + i + "차선잔량")); volumeListBox.Items.Add(차선잔량); } } int 매도최우선호가 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매도최우선호가")); priceListBox.Items.Add(매도최우선호가); int 매도최우선잔량 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매도최우선잔량")); volumeListBox.Items.Add(매도최우선잔량); int 매수최우선호가 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매수최우선호가")); priceListBox.Items.Add(매수최우선호가); int 매수최우선잔량 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매수최우선잔량")); for (int i = 2; i < 11; i++) { if (i == 6) { int 호가 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매수" + i + "우선호가")); priceListBox.Items.Add(호가); int 잔량 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매수" + i + "우선잔량")); volumeListBox.Items.Add(잔량); } else { int 호가 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매수" + i + "차선호가")); priceListBox.Items.Add(호가); int 잔량 = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "매수" + i + "차선잔량")); volumeListBox.Items.Add(잔량); } } //MessageBox.Show("매도최우선호가: " + 매도최우선호가 + " ,매수최우선호가: " + 매수최우선호가); } }
protected int getRowCount(AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent apiEvent) { try { int count = StockEngine.getInstance.khOpenApi().GetRepeatCnt(apiEvent.sTrCode, apiEvent.sRQName); return(count); } catch (AccessViolationException execption) { Logger.getInstance.print(Log.에러, "[getRowCount:{0}] {1}\n{2}\n{3}", apiEvent.sRQName, execption.Message, execption.StackTrace, execption.InnerException); } return(0); }
protected string getData(string columName, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent apiEvent, int index) { try { string data = StockEngine.getInstance.khOpenApi().CommGetData(apiEvent.sTrCode, "", apiEvent.sRQName, index, columName).Trim(); return(data); } catch (AccessViolationException execption) { Logger.getInstance.print(Log.에러, "[getData:{0}] {1}\n{2}\n{3}", apiEvent.sRQName, execption.Message, execption.StackTrace, execption.InnerException); } return(""); }
private void OnReceiveTrDataPlus(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sRQName == "주식기본정보") { text_name.Text += axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "종목명").ToString().TrimStart(' '); text_changeratio.Text = axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "등락율").ToString().TrimStart(' '); text_traderatio.Text = axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "거래량").ToString().TrimStart(' '); text_value.Text = axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "시가").ToString().TrimStart(' '); text_high.Text = axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "고가").ToString().TrimStart(' '); text_low.Text = axKHOpenAPI1.CommGetData(e.sTrCode, "", e.sRQName, 0, "저가").ToString().TrimStart(' '); } }
private void kiwoomApi_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { Console.WriteLine("RQName : " + e.sRQName); try { this.GetType().GetMethod(e.sRQName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic).Invoke(this, new object[] { e }); } catch (NullReferenceException ex) { Console.WriteLine("[ERROR] " + ex.Message); } }
private void M_axKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { int cCount = m_axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRecordName); for (int i = 0; i < cCount; i++) { string sName = m_axKHOpenAPI.GetCommData(e.sTrCode, e.sRecordName, i, "종목명"); sName = sName.Trim(); string sPrice = m_axKHOpenAPI.GetCommData(e.sTrCode, e.sRecordName, i, "현재가"); sPrice = sPrice.Trim(); log.Debug("[" + i.ToString("00") + "] name=" + sName + ", price=" + sPrice); } }
private void M_axKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (OnReceiveTrData == null) { return; } int cCount = m_axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRecordName); ReceiveTrDataInfo info = new ReceiveTrDataInfo(e.sScrNo, e.sRQName, e.sTrCode, e.sRecordName, e.sPrevNext, cCount); OnReceiveTrData(this, info); }
public void 실시간미체결요청응답처리(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { log.Info("실시간미체결요청응답처리 start"); int rowCount = OpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName); for (int i = 0; i < rowCount; i++) { string stockCode = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "종목코드").Trim(); if (stockCode.StartsWith("A")) { stockCode = stockCode.Substring(1); } else if (stockCode.StartsWith("*A")) { stockCode = stockCode.Substring(2); } string sQty = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "주문수량").Trim(); int qty = int.Parse(sQty); string sPrice = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "주문가격").Trim(); int price = int.Parse(sPrice); string orderNo = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "주문번호").Trim(); string orderStatus = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "주문상태").Trim(); log.Info("orderNo:" + orderNo + " orderStatus:" + orderStatus + " stockCode:" + stockCode + " sQty:" + sQty + " sPrice:" + sPrice); List <StockOrder> orderList = dacStock.tbl_stock_order_주문조회(inqDate, stockCode, "매도", "요청중"); // 주문번호가 없는 매도요청건들 주문번호 업데이트 for (int j = 0; j < orderList.Count; j++) { if (string.IsNullOrWhiteSpace(orderList[j].orderNo)) { int orderQty = int.Parse(orderList[j].Qty); int orderPrice = int.Parse(orderList[j].Price); if (qty == orderQty && price == orderPrice) { log.Info("주문번호업데이트 orderSeq: " + orderList[j].Seq + " orderNo:" + orderNo); dacStock.주문정보업데이트(orderList[j].Seq, "", orderNo); } } } } log.Info("실시간미체결요청응답처리 end"); }
// open API tr데이터 수신 이벤트 private void axKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { axKHOpenAPI.SetRealRemove("ALL", "ALL"); ShowTrMsg("수신 시작"); Logger(Log.조회, "====TR 수신 시작===="); Logger(Log.조회, "화면번호 :{0} | RQName :{1} | TRCode :{2} | 레코드명 :{3} | 연속조회 유무 :{4}", e.sScrNo, e.sRQName, e.sTrCode, e.sRecordName, e.sPrevNext); string todayFull = System.DateTime.Now.ToString("yyyyMMddHHmm"); string today = todayFull.Substring(0, 8); string nowHhmm = todayFull.Substring(8); //DateTime ydate = DateTime.Now - TimeSpan.FromDays(1); // OPT10085 : 계좌수익률요청 if ("OPT10085".Equals(e.sTrCode)) { // 매도할 잔고 종목 조회할 때 if ((Constants.RET_ACCT_ITEM).Equals(e.sScrNo.Substring(0, 4))) { int nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName); ArrayList rslt = new ArrayList(); for (int i = 0; i < nCnt; i++) { string item = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim(); string tranDay = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim(); string amt = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "보유수량").Trim(); string price = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim(); string buyPrice = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입가").Trim(); string buyTot = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입금액").Trim(); Dictionary <string, string> row = new Dictionary <string, string>(); row.Add("item", item); row.Add("tranDay", tranDay); row.Add("amt", amt); row.Add("price", price); row.Add("buyPrice", buyPrice); row.Add("buyTot", buyTot); rslt.Add(row); } _sell.RetAcctItem_Callback(rslt, today); } } Logger(Log.조회, "====TR 수신 끝===="); ShowTrMsg("수신 끝"); }
private void axKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { string code = axKHOpenAPI.GetCommData(e.sTrCode, "", 0, "").Trim(); //OPT10001 : 주식기본정보 if (e.sRQName == "주식기본정보") { lbox_prevalue.Items.Clear(); int nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName); Logger(Log.조회, "종목명 : {0}", axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "종목명").Trim()); Logger(Log.조회, "현재가 : {0}", Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "현재가").Trim())); Logger(Log.조회, "PER : {0}", axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "PER").Trim()); } //OPT10081 : 주식일봉차트조회 if (e.sRQName == "주식일봉차트조회") { int nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName); for (int i = 0; i < nCnt; i++) { Logger(Log.조회, "{0} | 현재가:{1:N0} | 시가:{2:N0} | 고가:{3:N0} | 저가:{4:N0} ", axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim(), Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim()), Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가").Trim()), Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "고가").Trim()), Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "저가").Trim())); } } //OPT10086 : 일별주가요청 if (e.sRQName == "일별주가요청") { int nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName); for (int i = 0; i < nCnt; i++) { Logger(Log.최근, "{0} | 시가:{1:N0} | 고가:{2:N0} | 저가:{3:N0}| 종가:{4:N0}", axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "날짜").Trim(), Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가").Trim()), Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "고가").Trim()), Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "저가").Trim()), Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종가").Trim())); li.Add(Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가").Trim())); li2.Add(i); } } }
private DailyTradingModel makeDailyTradingModel(AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e, int index, String code) { String name = getStockNameByCode(code); int startPrice = int.Parse(getReceiveDataByName(e, index, "시가")); int endPrice = int.Parse(getReceiveDataByName(e, index, "현재가")); int highPrice = int.Parse(getReceiveDataByName(e, index, "고가")); int lowPrice = int.Parse(getReceiveDataByName(e, index, "저가")); int volume = int.Parse(getReceiveDataByName(e, index, "거래량")); int tradingValue = int.Parse(getReceiveDataByName(e, index, "거래대금")); DateTime tradingDate = DateUtil.convertStringToDateTime(getReceiveDataByName(e, index, "일자")); DateTime createdDate = DateUtil.convertStringToDateTime(DateTime.Now.ToShortDateString()); DateTime modifiedDate = DateUtil.convertStringToDateTime(DateTime.Now.ToShortDateString()); return(new DailyTradingModel(code, name, startPrice, endPrice, highPrice, lowPrice, volume, tradingValue, tradingDate, createdDate, modifiedDate)); }
public void onReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sRQName == "주식기본정보") { int nCnt = axKHOpenAPI1.GetRepeatCnt(e.sTrCode, e.sRQName); listBox_info.Items.Add("종목코드\t\t\t" + axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "종목코드")); listBox_info.Items.Add("종목명\t" + axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "종목명")); listBox_info.Items.Add("거래량\t\t\t" + axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "거래량")); listBox_info.Items.Add("시가\t\t\t" + axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "시가")); listBox_info.Items.Add("고가\t\t\t" + axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "고가")); listBox_info.Items.Add("저가\t\t\t" + axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "저가")); listBox_info.Items.Add("현재가\t\t\t" + axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "현재가")); listBox_info.Items.Add("등락율\t\t\t" + axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "등락율")); } }
public void onReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sRQName == "계좌평가잔고내역요청") { long estimatedDepositedAssets = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "추정예탁자산")); long totalPurchase = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "총매입금액")); long totalEstimate = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "총평가금액")); long totalProfitLoss = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "총평가손익금액")); double totalProfitRate = double.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "총수익률(%)")); lblEstimatedDepositedAssets.Text = String.Format("{0:#,##0}", estimatedDepositedAssets); lblTotalPurchase.Text = String.Format("{0:#,##0}", totalPurchase); lblTotalEstimate.Text = String.Format("{0:#,##0}", totalEstimate); lblTotalProfit.Text = String.Format("{0:#,##0}", totalProfitLoss); lblTotalProfitRate.Text = String.Format("{0:f2}", totalProfitRate); btnBalanceCheck.Enabled = true; } else if (e.sRQName == "종목정보요청") { long stockPrice = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "현재가").Trim().Replace("-", "")); string stockName = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "종목명").Trim(); long upDown = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "전일대비").Trim()); long volume = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "거래량").Trim()); string upDownRate = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "등락율").Trim(); lblStockPrice.Text = String.Format("{0:#,##0}", stockPrice); lblStockName.Text = stockName; lblStockUpDown.Text = String.Format("{0:#,##0}", upDown); lblStockVolume.Text = String.Format("{0:#,##0}", volume); if (upDown > 0) { lblStockUpDown.ForeColor = Color.Red; lblStockUpDownRate.ForeColor = Color.Red; } else if (upDown < 0) { lblStockUpDown.ForeColor = Color.Blue; lblStockUpDownRate.ForeColor = Color.Blue; } else { lblStockUpDown.ForeColor = Color.Black; lblStockUpDownRate.ForeColor = Color.Black; } lblStockUpDownRate.Text = upDownRate + "%"; } }
public void onReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { if (e.sRQName == "종목정보요청") { string stockPrice = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "현재가"); priceNumericUpDown.Value = long.Parse(stockPrice.Replace("-", "")); } else if (e.sRQName == "계좌평가현황요청") { int count = axKHOpenAPI1.GetRepeatCnt(e.sTrCode, e.sRQName); stockBalanceList = new List <stockBalance>(); for (int i = 0; i < count; i++) { string stockCode = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "종목코드").TrimStart('0'); string stockName = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "종목명").Trim(); long number = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "보유수량")); long buyingMoney = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "매입금액")); long currentPrice = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "현재가").Replace("-", "")); long estimatedProfit = long.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "손익금액")); double estimatedProfitRate = double.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "손익율")); stockBalanceList.Add(new stockBalance(stockCode, stockName, number, String.Format("{0:#,###}", buyingMoney), String.Format("{0:#,###}", currentPrice), estimatedProfit, String.Format("{0:f2}", estimatedProfitRate))); } outstandingDataGridView.DataSource = stockBalanceList; } else if (e.sRQName == "실시간미체결요청") { int count = axKHOpenAPI1.GetRepeatCnt(e.sTrCode, e.sRQName); outstandingList = new List <outstanding>(); for (int i = 0; i < count; i++) { string orderCode = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "주문번호")).ToString(); string stockCode = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "종목코드").Trim(); string stockName = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "종목명").Trim(); int orderNumber = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "주문수량")); int orderPrice = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "주문가격")); int outstandingNumber = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "미체결수량")); int currentPrice = int.Parse(axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "현재가").Replace("-", "")); string orderGubun = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "주문구분").Trim(); string orderTime = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, i, "시간").Trim(); outstandingList.Add(new outstanding(orderCode, stockCode, stockName, orderNumber, String.Format("{0:#,###}", orderPrice), String.Format("{0:#,###}", currentPrice), outstandingNumber, orderGubun, orderTime)); } outstandingDataGridView.DataSource = outstandingList; } }
public void 당일거래량상위응답처리(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) { int rowCount = OpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName); string 장운영구분 = e.sScrNo; log.Info("당일거래량상위응답처리[" + e.sRQName + "] start e.sPrevNext:" + e.sPrevNext); for (int i = 0; i < rowCount; i++) { string 종목코드 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "종목코드").Trim(); string 종목명 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "종목명").Trim(); string 현재가 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "현재가").Trim(); 현재가 = 현재가.Replace("-", "").Replace("+", ""); string 전일대비기호 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "전일대비기호").Trim(); string 전일대비 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "전일대비").Trim(); string 등락률 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "등락률").Trim(); string 거래량 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "거래량").Trim(); string 전일비 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "전일비").Trim(); string 거래회전율 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "거래회전율").Trim(); string 거래금액 = OpenAPI.GetCommData(e.sTrCode, e.sRQName, i, "거래금액").Trim(); log.Info("종목코드:" + 종목코드 + " 종목명:" + 종목명 + " 현재가:" + 현재가 + " 전일대비기호:" + 전일대비기호 + " 전일대비:" + 전일대비 + " 등락률:" + 등락률 + " 거래량:" + 거래량 + " 전일비:" + 전일비 + " 거래회전율:" + 거래회전율 + " 거래금액:" + 거래금액 + " 장운영구분:" + 장운영구분); dacStock.당일장후시간외_거래량거래대금순조회(inqDate, 종목코드, 종목명, 현재가, 전일대비기호, 전일대비 , 등락률, 거래량, 전일비, 거래회전율, 거래금액, "당일거래량순조회".Equals(e.sRQName) ? "1" : "3", 장운영구분); } log.Info("당일거래량상위응답처리[" + e.sRQName + "] end"); if ("2".Equals(e.sPrevNext)) { 당일거래량상위요청("당일거래량순조회".Equals(e.sRQName) ? "1":"3", 장운영구분, e.sPrevNext); } else { //거래량 거래대금순 모두 조회했다고 가정 if ("3".Equals(장운영구분) && "당일거래량순조회".Equals(e.sRQName)) { log.Info("거래대상설정완료 : " + 장운영구분); dacStock.당일거래대상설정(inqDate, DateTime.Now.AddDays(1).ToString("yyyyMMdd"), 장운영구분); System.Windows.Forms.Application.Exit(); } } }