Exemplo n.º 1
0
        //----------------------------------------------------------- Event  -----------------------------------------------------------

        //---------------------------------------------- 키움 OpenApi TR 요청 결과 처리부 ----------------------------------------------
        private void trAccountBalance(AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            long totalValuationAmount = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, 0, "총평가손익금액"));
            long estimatedBalance     = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, 0, "추정예탁자산"));

            this.AccountBalanceEvent(totalValuationAmount, estimatedBalance);

            int cnt = openApi.GetRepeatCnt(e.sTrCode, e.sRQName);

            this.holdings.Clear();

            for (int i = 0; i < cnt; i++)
            {
                string stockNo       = openApi.GetCommData(e.sTrCode, e.sRQName, i, "종목번호").Trim().Replace("A", "");
                string stockName     = openApi.GetCommData(e.sTrCode, e.sRQName, i, "종목명").Trim();
                long   currentPrice  = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "현재가").Trim());
                int    qty           = int.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "보유수량").Trim());
                long   buyPrice      = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "매입가").Trim());
                long   totalBuyPrice = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "매입금액").Trim());
                long   profit        = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "평가손익").Trim());
                float  profitRate    = float.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "수익률(%)").Trim());

                this.holdings.Add(new Holding(stockNo, stockName, currentPrice, qty, buyPrice, totalBuyPrice, profit, profitRate, loginInfo.getServerGubun));
            }

            if (this.holdings.Count > 0)
            {
                string codeList = string.Join(";", holdings.Select(item => item.StockNo));

                // 실시간 시세 요청
                requestRealtimeQuote(SCREEN_NO_ACCOUNT_INFO, codeList, REALTIME_NEW);
            }
        }
Exemplo n.º 2
0
        private void OnReceiveTrDataEventHandler(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);
            }
        }
Exemplo n.º 3
0
        private void axKHOpenAPI1_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            logger.Debug("axKHOpenAPI1_OnReceiveTrData");
            if (e.sRQName.Contains("주식기본정보요청_"))
            {
                Opt10001VO opt10001VO = getOpt10001VO(e.sTrCode, e.sRQName);
                logger.Debug(e.sTrCode);
                logger.Debug(e.sRQName);

                string conditionName = e.sRQName.Split('_')[2];

                db.saveItemInfo(opt10001VO, conditionName);
                googleSheet.updateCodeListToGoogleSheet(opt10001VO, conditionName);
            }
        }
Exemplo n.º 4
0
        private void axKHOpenAPI1_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            logger.Debug("axKHOpenAPI1_OnReceiveTrData");

            int repCnt = this.axKHOpenAPI1.GetRepeatCnt(e.sTrCode, e.sRQName);



            if (e.sRQName.Contains("계좌평가잔고내역"))
            {
                //TODO. repCnt 로 루프를 돌려서 전체 종목을 받아오기
                string 종목번호 = axKHOpenAPI1.GetCommData(e.sTrCode, e.sRQName, 0, "종목번호").Trim();
                logger.Debug(종목번호);
            }
        }
Exemplo n.º 5
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPW00003");
            try {
                StringBuilder sbAll = new StringBuilder();
                StringBuilder sb    = new StringBuilder();


                String 조회일자 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                /*추정예탁자산*/
                sb.Append("{0}|{1}|{2}");
                String tmp  = sb.ToString();
                String 계좌번호 = "XXXXXXXXXX";
                //int nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);
                String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
                String keyStockCode       = String.Format(keyStockCodeLayout
                                                          , e.sRQName
                                                          , e.sTrCode
                                                          , e.sScrNo
                                                          );
                계좌번호 = AppLib.getClass1Instance().getStockCode(keyStockCode);
                String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|accountNum:{3}";
                String key       = String.Format(keyLayout
                                                 , e.sRQName
                                                 , e.sTrCode
                                                 , e.sScrNo
                                                 , 계좌번호
                                                 );
                //            int nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);  이거 무조건 0이다.
                String 추정예탁자산 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "추정예탁자산").Trim();//[0]
                String tmp1   = String.Format(tmp
                                              , 조회일자
                                              , 계좌번호
                                              , 추정예탁자산
                                              );
                sbAll.AppendLine(tmp1);
                String ret = sbAll.ToString();
                FileLog.PrintF("ReceivedData OPW00003 ret=>" + ret);
                ScreenNumber.getClass1Instance().DisconnectRealData(e.sScrNo);
                //this.SetRealRemove(axKHOpenAPI, "ALL", "ALL");
                AppLib.getClass1Instance().removeStockCodeDictionary(keyStockCode);
                AppLib.getClass1Instance().removeSpellDictionary(key);
                Send(key, ret, "OPW00003");
            } catch (Exception ex)
            {
                FileLog.PrintF("[ALERT-ReceivedData-OPW00003]Exception ex=" + ex.Message);
            }
        }
Exemplo n.º 6
0
 /* TR데이터 받는곳 */
 private void OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
 {
     if (e.sRQName == "계좌잔고평가내역")
     {
         // ㅁㅁㅁ.Parse는 00000000  <- 이러한 값을 제거해줌
         int 예수금 = int.Parse(키움API.GetCommData(e.sTrCode, e.sRQName, 0, "추정예탁자산"));
         Get_Deposit.Text = String.Format("{0:#,##0}", 예수금); // 돈 쉼표(,) 표시
     }
     else if (e.sRQName == "코스피_요청")
     {
         코스피요청_처리(키움API.GetRepeatCnt(e.sTrCode, e.sRecordName), e);
     }
     else if (e.sRQName == "코스닥_요청")
     {
         //코스닥요청_처리(키움API.GetRepeatCnt(e.sTrCode, e.sRecordName), e);
     }
 }
Exemplo n.º 7
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPT10014");
            try
            {
                /*
                 * sScrNo – 화면번호
                 * sRQName – 사용자구분 명
                 * sTrCode – Tran 명
                 * sRecordName – Record 명
                 * sPreNext – 연속조회 유무
                 */
                List <TB_OPT10014> lst    = new List <TB_OPT10014>();
                String             종목코드   = "XXXX";
                int    nCnt               = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);
                String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
                String keyStockCode       = String.Format(keyStockCodeLayout
                                                          , e.sRQName
                                                          , e.sTrCode
                                                          , e.sScrNo
                                                          );
                종목코드 = AppLib.getClass1Instance().getStockCode(keyStockCode);

                String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|stockCode:{3}";
                String key       = String.Format(keyLayout
                                                 , e.sRQName
                                                 , e.sTrCode
                                                 , e.sScrNo
                                                 , 종목코드
                                                 );

                spell = AppLib.getClass1Instance().getSpell(key).ShallowCopy();
                String startDate     = spell.startDate;
                String lastStockDate = "";
                int    startDate일자   = 0;
                int.TryParse(startDate, out startDate일자);

                if (nCnt > 0)
                {
                    for (int i = 0; i < nCnt; i++)
                    {
                        int 일자 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim());//[0]

                        if (startDate != null)
                        {
                            if (!(일자 >= startDate일자))
                            {
                                //입력받은 20200301 을 정수로 바꾼 strartDAte일자
                                //데이터로 받을 "일자" 가 이것보다 큰것만 가져온다.
                                //명령을 넣을때 실제로 시작일자는 ui상에서 종료일자가 들어간다.\
                                // api는 시작일자를 기준으로 내림차순으로 하기 때문이다.
                                //내림차순으로 받은거에서 끊는 역할을 해준다.
                                break;
                            }
                        }

                        /*OPT10015 일별 상세하고 중복
                         * int 종가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종가").Trim());//[1]
                         * int 전일대비기호 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비기호").Trim());//[2]
                         * int 전일대비 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비").Trim());//[3]
                         * float 등락율 = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "등락율").Trim());//[4]
                         * int 거래량 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래량").Trim());//[5]
                         */
                        int   공매도량    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "공매도량").Trim());    //[6]
                        float 매매비중    = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매매비중").Trim());    //[7]
                        int   공매도거래대금 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "공매도거래대금").Trim()); //[8]
                        int   공매도평균가  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "공매도평균가").Trim());  //[9]



                        TB_OPT10014 tmp = new TB_OPT10014();
                        tmp.stock_cd                  = 종목코드;
                        tmp.stock_dt                  = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim();
                        tmp.short_selling_qty         = 공매도량;
                        tmp.trade_rt                  = 매매비중;
                        tmp.short_selling_trade_amt   = 공매도거래대금;
                        tmp.short_selling_average_amt = 공매도평균가;
                        tmp.prev_next                 = e.sPrevNext;

                        lst.Add(tmp);
                    }
                }
                else
                {
                    종목코드 = "00000";
                }


                if (lst.Count() > 0)
                {
                    DailyData dd = new DailyData();
                    dd.insertOpt10014(lst);
                }

                int prevNext = 0;
                int.TryParse(e.sPrevNext, out prevNext);
                //ScreenNumber.getClass1Instance().DisconnectRealData(e.sScrNo);
                //ScreenNumber.getClass1Instance().SetRealRemove("ALL", "ALL");
                //래치를 호출해서 잠김을 제거한다.--래치 일단 제거 호출하는데도 제거 했다. 1초에 5번 호출 규칙만 적용해보자.
                AppLib.getClass1Instance().setOpt10081(spell.sTrCode);
                //2020년03월29일 확인 내용
                //nprevNext가 0이면 종료고 2이면 진행으로 알고 있었다.
                //그런데 어느시점이 지나가면 그게 아닌것 같다.
                //이걸 확인하려면 디비에 이걸 넣어야한다.
                //2012년까지 정상동작하고 이전데이터는 무조건 prev_next를 0을 리턴한다.
                //이건 수동으로 봐야겠다. 끝.

                if (startDate.Equals("ZERO") || (startDate.Length == 8 && startDate.CompareTo(lastStockDate) >= 0) || prevNext == 0)
                //ZERO면 한번만 호출이다. 또는 시작일과 마지막 리턴일이 같다면 종료되어야한다.
                {
                    AppLib.getClass1Instance().removeSpellDictionary(spell.key);
                    int    position = spell.key.LastIndexOf("|");
                    String key1     = spell.key.Substring(0, position);
                    //래치를 호출해서 잠김을 제거한다.--래치 일단 제거 호출하는데도 제거 했다. 1초에 5번 호출 규칙만 적용해보자.
                }
                else if (prevNext > 0)
                {
                    //putReceivedQueueAndsetNextSpell(key, prevNext, lastStockDate);
                    OpenApi.Spell.SpellOpt tmp = spell.ShallowCopy();
                    tmp.nPrevNext     = prevNext;
                    tmp.lastStockDate = lastStockDate;
                    AppLib.getClass1Instance().removeSpellDictionary(key);
                    AppLib.getClass1Instance().AddSpellDictionary(key, tmp);
                    AppLib.getClass1Instance().EnqueueByOrderQueue(tmp);  //주문을 다시 넣는다.
                }
            }
            catch (Exception ex)
            {
                FileLog.PrintF("[ALERT-ReceivedData-OPT10014]Exception ex=" + ex.Message);
            }
        }
Exemplo n.º 8
0
        public void axKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            if (e.sRQName.Contains(ConstName.RECEIVE_TR_DATA_HOGA))
            {
                StockWithBiddingEntity newObj = new StockWithBiddingEntity();

                string[] rqNameArray = e.sRQName.Split(':');
                if (rqNameArray.Length == 3)
                {
                    string itemCode = rqNameArray[1];
                    newObj.Code = itemCode;
                }
                for (int i = 0; i < 10; i++)
                {
                    if (i == 9)
                    {
                        Console.WriteLine("매도 최우선호가 / 잔량 ");
                        string firstSellHoga = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매도최우선호가").Trim().Replace("+", "");
                        string firstSellQnt  = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매도최우선잔량").Trim();
                        if (!string.IsNullOrEmpty(firstSellHoga))
                        {
                            newObj.SetSellHoga(i, long.Parse(firstSellHoga));
                        }
                        if (!string.IsNullOrEmpty(firstSellQnt))
                        {
                            newObj.SetSellQnt(i, long.Parse(firstSellQnt));
                        }
                    }
                    else
                    {
                        Console.WriteLine("매도" + (10 - i) + "차선호가 /잔량");
                        string hoga = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매도" + (10 - i) + "차선호가").Trim().Replace("+", ""));
                        string qnt  = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매도" + (10 - i) + "차선잔량").Trim());

                        if (!string.IsNullOrEmpty(hoga))
                        {
                            newObj.SetSellHoga(i, long.Parse(hoga));
                        }
                        if (!string.IsNullOrEmpty(qnt))
                        {
                            newObj.SetSellQnt(i, long.Parse(qnt));
                        }
                    }
                }
                for (int i = 0; i < 10; i++)
                {
                    if (i == 0)
                    {
                        Console.WriteLine("매수 최우선호가 / 잔량 ");
                        string firstBuyHoga = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매수최우선호가").Trim().Replace("+", ""));
                        string firstBuyQnt  = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매수최우선잔량").Trim());
                        if (!string.IsNullOrEmpty(firstBuyHoga))
                        {
                            newObj.SetBuyHoga(i, long.Parse(firstBuyHoga));
                        }
                        if (!string.IsNullOrEmpty(firstBuyQnt))
                        {
                            newObj.SetBuyQnt(i, long.Parse(firstBuyQnt));
                        }
                    }
                    else
                    {
                        Console.WriteLine("매수" + (i + 1) + "차선호가 / 잔량");
                        string hoga = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매수" + (i + 1) + "차선호가").Trim().Replace("+", ""));
                        string qnt  = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매수" + (i + 1) + "차선잔량").Trim());
                        if (!string.IsNullOrEmpty(hoga))
                        {
                            newObj.SetBuyHoga(i, long.Parse(hoga));
                        }
                        if (!string.IsNullOrEmpty(qnt))
                        {
                            newObj.SetBuyQnt(i, long.Parse(qnt));
                        }
                    }
                }
                StockWithBiddingManager.GetInstance().SetItem(newObj);
            }
        }
Exemplo n.º 9
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPT10059");
            try
            {
                /*
                 * sScrNo – 화면번호
                 * sRQName – 사용자구분 명
                 * sTrCode – Tran 명
                 * sRecordName – Record 명
                 * sPreNext – 연속조회 유무
                 */
                StringBuilder sbAll = new StringBuilder();
                StringBuilder sb    = new StringBuilder();
                //sb.Append("일자:{0}|종목코드:{1}|현재가:{2}|거래량:{3}|거래대금:{4}|시가:{5}|고가:{6}|저가:{7}");
                //sb.Append("stock_date:{0}|current_price:{1}|current_price:{2}|trade_quantity:{3}|trade_price:{4}|start_price:{5}|high_price:{6}|low_price:{7}");

                /*일자 ,현재가,대비기호,전일대비,등락율,누적거래대금,개인투자자,외국인투자자,기관계,금융투자,보험,투신,기타금융,은행,연기금등,사모펀드,국가,기타법인,내외국인,종목코드,매매구분,금액수량구분*/
                sb.Append("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}|{16}|{17}|{18}|{19}|{20}|{21}");
                String tmp  = sb.ToString();
                String 종목코드 = "XXXX";
                int    nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);

                String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
                String keyStockCode       = String.Format(keyStockCodeLayout
                                                          , e.sRQName
                                                          , e.sTrCode
                                                          , e.sScrNo
                                                          );
                종목코드 = AppLib.getClass1Instance().getStockCode(keyStockCode);

                String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|stockCode:{3}";
                String key       = String.Format(keyLayout
                                                 , e.sRQName
                                                 , e.sTrCode
                                                 , e.sScrNo
                                                 , 종목코드
                                                 );

                spell = AppLib.getClass1Instance().getSpell(key);
                String startDate = spell.startDate;

                String lastStockDate = "";
                int    startDate일자   = 0;
                if (!int.TryParse(startDate, out startDate일자))
                {
                    startDate일자 = 0;
                }

                if (nCnt > 0)
                {
                    for (int i = 0; i < nCnt; i++)
                    {
                        int   일자   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim());  //[0]
                        int   현재가  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim()); //[1]
                        float 대비기호 = 0;                                                                               //[2]

                        if (!float.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대비기호").Trim(), out 대비기호))
                        {
                        }

                        int 전일대비 = 0;//[3]
                        if (!Int32.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비").Trim(), out 전일대비))
                        {
                            전일대비 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비").Trim().Replace("--", "-"));
                        }
                        float 등락율 = 0;//[4]

                        if (!float.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "등락율").Trim(), out 등락율))
                        {
                            등락율 = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "등락율").Trim());
                        }

                        int 누적거래대금 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "누적거래대금").Trim()); //[5
                        int 개인투자자  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "개인투자자").Trim());  //[6]
                        int 외국인투자자 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "외국인투자자").Trim()); //[7]
                        int 기관계    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기관계").Trim());    //[8]
                        int 금융투자   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "금융투자").Trim());   //[9]
                        int 보험     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "보험").Trim());     //[10]
                        int 투신     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "투신").Trim());     //[11]
                        int 기타금융   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기타금융").Trim());   //[12]
                        int 은행     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "은행").Trim());     //[13]
                        int 연기금등   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "연기금등").Trim());   //[14]
                        int 사모펀드   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "사모펀드").Trim());   //[15]
                        int 국가     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "국가").Trim());     //[16]
                        int 기타법인   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기타법인").Trim());   //[17]
                        int 내외국인   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "내외국인").Trim());   //[18]

                        String tmp1 = String.Format(tmp,
                                                    일자,
                                                    현재가,
                                                    대비기호,
                                                    전일대비,
                                                    등락율,
                                                    누적거래대금,
                                                    개인투자자,
                                                    외국인투자자,
                                                    기관계,
                                                    금융투자,
                                                    보험,
                                                    투신,
                                                    기타금융,
                                                    은행,
                                                    연기금등,
                                                    사모펀드,
                                                    국가,
                                                    기타법인,
                                                    내외국인,
                                                    종목코드,
                                                    spell.buyOrSell,
                                                    spell.priceOrAmount
                                                    );
                        lastStockDate = 일자.ToString();
                        if (startDate != null)
                        {
                            if (startDate.Equals("ZERO") || startDate.Equals("TWO"))
                            {
                                sbAll.AppendLine(tmp1);
                            }
                            else
                            {
                                if (일자 >= startDate일자)
                                {
                                    sbAll.AppendLine(tmp1);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            sbAll.AppendLine(tmp1);
                        }
                    }
                }
                else
                {
                    종목코드 = "00000";
                }

                int prevNext = 0;
                if (!int.TryParse(e.sPrevNext, out prevNext))
                {
                    prevNext = 0;
                }

                ScreenNumber.getClass1Instance().DisconnectRealData(e.sScrNo);
                ScreenNumber.getClass1Instance().SetRealRemove("ALL", "ALL");

                putReceivedQueueAndsetNextSpell(key, sbAll.ToString(), prevNext, lastStockDate);
            }
            catch (Exception ex)
            {
                FileLog.PrintF("[ALERT-ReceivedData-OPT10059]Exception ex=" + ex.Message);
            }
        }
Exemplo n.º 10
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPT10014");
            try
            {
                /*
                 * sScrNo – 화면번호
                 * sRQName – 사용자구분 명
                 * sTrCode – Tran 명
                 * sRecordName – Record 명
                 * sPreNext – 연속조회 유무
                 */
                StringBuilder sbAll = new StringBuilder();
                StringBuilder sb    = new StringBuilder();

                /*일자,종목코드 ,종가,전일대비기호,전일대비,등락율,거래량,공매도량,매매비중,공매도거래대금,공매도평균가*/
                sb.Append("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}");
                String tmp  = sb.ToString();
                String 종목코드 = "XXXX";
                int    nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);
                String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
                String keyStockCode       = String.Format(keyStockCodeLayout
                                                          , e.sRQName
                                                          , e.sTrCode
                                                          , e.sScrNo
                                                          );
                종목코드 = AppLib.getClass1Instance().getStockCode(keyStockCode);

                String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|stockCode:{3}";
                String key       = String.Format(keyLayout
                                                 , e.sRQName
                                                 , e.sTrCode
                                                 , e.sScrNo
                                                 , 종목코드
                                                 );

                spell = AppLib.getClass1Instance().getSpell(key).ShallowCopy();
                String startDate     = spell.startDate;
                String lastStockDate = "";
                int    startDate일자   = 0;
                if (!int.TryParse(startDate, out startDate일자))
                {
                    startDate일자 = 0;
                }

                if (nCnt > 0)
                {
                    for (int i = 0; i < nCnt; i++)
                    {
                        int   일자      = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim());      //[0]
                        int   종가      = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종가").Trim());      //[1]
                        int   전일대비기호  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비기호").Trim());  //[2]
                        int   전일대비    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비").Trim());    //[3]
                        float 등락율     = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "등락율").Trim());     //[4]
                        int   거래량     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래량").Trim());     //[5]
                        int   공매도량    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "공매도량").Trim());    //[6]
                        float 매매비중    = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매매비중").Trim());    //[7]
                        int   공매도거래대금 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "공매도거래대금").Trim()); //[8]
                        int   공매도평균가  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "공매도평균가").Trim());  //[9]

                        String tmp1 = String.Format(tmp,
                                                    일자,
                                                    종목코드,
                                                    종가,
                                                    전일대비기호,
                                                    전일대비,
                                                    등락율,
                                                    거래량,
                                                    공매도량,
                                                    매매비중,
                                                    공매도거래대금,
                                                    공매도평균가
                                                    );
                        lastStockDate = 일자.ToString();
                        if (startDate != null)
                        {
                            if (startDate.Equals("ZERO") || startDate.Equals("TWO"))
                            {
                                sbAll.AppendLine(tmp1);
                            }
                            else
                            {
                                if (일자 >= startDate일자)
                                {
                                    sbAll.AppendLine(tmp1);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            sbAll.AppendLine(tmp1);
                        }
                    }
                }
                else
                {
                    종목코드 = "00000";
                }

                int prevNext = 0;
                if (!int.TryParse(e.sPrevNext, out prevNext))
                {
                    prevNext = 0;
                }
                ScreenNumber.getClass1Instance().DisconnectRealData(e.sScrNo);
                ScreenNumber.getClass1Instance().SetRealRemove("ALL", "ALL");
                putReceivedQueueAndsetNextSpell(key, sbAll.ToString(), prevNext, lastStockDate);
            }
            catch (Exception ex)
            {
                FileLog.PrintF("[ALERT-ReceivedData-OPT10014]Exception ex=" + ex.Message);
            }
        }
Exemplo n.º 11
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            /*
             * sScrNo – 화면번호
             * sRQName – 사용자구분 명
             * sTrCode – Tran 명
             * sRecordName – Record 명
             * sPreNext – 연속조회 유무
             */
            FileLog.PrintF("ReceivedData OPT10080");
            try
            {
                StringBuilder sbAll = new StringBuilder();
                StringBuilder sb    = new StringBuilder();
                //sb.Append("일자:{0}|종목코드:{1}|현재가:{2}|거래량:{3}|거래대금:{4}|시가:{5}|고가:{6}|저가:{7}");
                //sb.Append("stock_date:{0}|stock_code:{1}|current_price:{2}|trade_quantity:{3}|trade_price:{4}|start_price:{5}|high_price:{6}|low_price:{7}");
                sb.Append("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}");
                String tmp  = sb.ToString();
                String 종목코드 = "XXXX";
                int    nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);

                String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
                String keyStockCode       = String.Format(keyStockCodeLayout
                                                          , e.sRQName
                                                          , e.sTrCode
                                                          , e.sScrNo
                                                          );
                종목코드 = AppLib.getClass1Instance().getStockCode(keyStockCode);

                String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|stockCode:{3}";
                String key       = String.Format(keyLayout
                                                 , e.sRQName
                                                 , e.sTrCode
                                                 , e.sScrNo
                                                 , 종목코드
                                                 );

                spell = AppLib.getClass1Instance().getSpell(key).ShallowCopy();
                String startDate     = spell.startDate;
                String lastStockDate = "";
                long   startDate일자   = 0;
                //시분초를 더함
                if (!long.TryParse(startDate + "000000", out startDate일자))
                {
                    startDate일자 = 0;
                }

                if (nCnt > 0)
                {
                    String 종목코드1 = "";
                    for (int i = 0; i < nCnt; i++)
                    {
                        if (i == 0)
                        {
                            종목코드1 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim();           //[0] 싱글 -첫번째에만 나타남
                        }

                        int    현재가    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim()); //[1]
                        int    거래량    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래량").Trim()); //[2]
                        String 체결시간   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결시간").Trim();             //[3]
                        int    시가     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가").Trim());  //[4]
                        int    고가     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "고가").Trim());  //[5]
                        int    저가     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "저가").Trim());  //[6]
                        int    수정주가구분 = 0;
                        if (axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정주가구분") != null && !axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정주가구분").ToString().Trim().Equals(""))
                        {
                            수정주가구분 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정주가구분").Trim());    //[7]
                        }
                        float 수정비율 = 0;
                        if (axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정비율") != null && !axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정비율").ToString().Trim().Equals(""))
                        {
                            수정비율 = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정비율").Trim());            //[8]
                        }
                        int 대업종구분 = 0;
                        if (axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대업종구분") != null && !axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대업종구분").ToString().Trim().Equals(""))
                        {
                            대업종구분 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대업종구분").Trim());        //[9]
                        }
                        int 소업종구분 = 0;
                        if (axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "소업종구분") != null && !axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "소업종구분").ToString().Trim().Equals(""))
                        {
                            소업종구분 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "소업종구분").Trim());        //[10]
                        }
                        int 종목정보 = 0;
                        if (axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목정보") != null && !axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목정보").ToString().Trim().Equals(""))
                        {
                            종목정보 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목정보").Trim());            //[11]
                        }
                        int 수정주가이벤트 = 0;
                        if (axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정주가이벤트") != null && !axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정주가이벤트").ToString().Trim().Equals(""))
                        {
                            수정주가이벤트 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정주가이벤트").Trim());//[12]
                        }
                        int 전일종가 = 0;
                        if (axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일종가") != null && !axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일종가").ToString().Trim().Equals(""))
                        {
                            전일종가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일종가").Trim());            //[13]
                        }

                        String tmp1 = String.Format(tmp
                                                    , 종목코드1
                                                    , 현재가
                                                    , 거래량
                                                    , 체결시간
                                                    , 시가
                                                    , 고가
                                                    , 저가
                                                    , 수정주가구분
                                                    , 수정비율
                                                    , 대업종구분
                                                    , 소업종구분
                                                    , 종목정보
                                                    , 수정주가이벤트
                                                    , 전일종가
                                                    );
                        //String str일자 = 체결시간.Substring(0, 8);
                        long 일자 = long.Parse(체결시간);
                        lastStockDate = 체결시간;

                        if (startDate != null)
                        {
                            if (startDate.Equals("ZERO") || startDate.Equals("TWO"))
                            {
                                sbAll.AppendLine(tmp1);
                            }
                            else
                            {
                                if (일자 >= startDate일자)
                                {
                                    sbAll.AppendLine(tmp1);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            sbAll.AppendLine(tmp1);
                        }
                    }
                }
                else
                {
                    종목코드 = "00000";
                }

                int prevNext = 0;
                if (!int.TryParse(e.sPrevNext, out prevNext))
                {
                    prevNext = 0;
                }

                ScreenNumber.getClass1Instance().DisconnectRealData(e.sScrNo);
                ScreenNumber.getClass1Instance().SetRealRemove("ALL", "ALL");
                putReceivedQueueAndsetNextSpell(key, prevNext, lastStockDate);
            }
            catch (Exception ex)
            {
                FileLog.PrintF("[ALERT-ReceivedData-OPT10080]Exception ex=" + ex.Message);
            }
        }
Exemplo n.º 12
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            /*
             * sScrNo – 화면번호
             * sRQName – 사용자구분 명
             * sTrCode – Tran 명
             * sRecordName – Record 명
             * sPreNext – 연속조회 유무
             */

            String stockDate = DateTime.Today.ToString("yyyyMMdd");


            StringBuilder sbAll   = new StringBuilder();
            StringBuilder sb      = new StringBuilder();
            String        계좌명     = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "계좌명").Trim();                   //account_name
            String        지점명     = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "지점명").Trim();                   //place_name
            int           예수금     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "예수금").Trim());      //deposit
            int           D2추정예수금 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "D+2추정예수금").Trim()); //twodays_after_deposit
            int           가잔고평가액  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "유가잔고평가액").Trim());  //stock_evaluation,
            int           예탁자산평가액 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "예탁자산평가액").Trim());  //:stock_balance_evaluation,
            int           총매입금액   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "총매입금액").Trim());    //:total_amount_of_purchase,
            int           추정예탁자산  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "추정예탁자산").Trim());   //:estimation_deposit
            int           매도담보대출금 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "매도담보대출금").Trim());  //stock_collacteral_loan,
            int           당일투자원금  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "당일투자원금").Trim());   //:today_investment_money,
            int           당월투자원금  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "당월투자원금").Trim());   //:this_month_investment_money,
            int           누적투자원금  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "누적투자원금").Trim());   //:accumulative_investment_money,
            int           당일투자손익  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "당일투자손익").Trim());   //:today_profit_and_loss,
            int           당월투자손익  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "당월투자손익").Trim());   //:today_profit_and_loss,
            int           누적투자손익  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "누적투자손익").Trim());   //:today_profit_and_loss,
            int           당일손익율   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "당일손익율").Trim());    //:today_profit_and_loss_rate
            int           당월손익율   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "당월손익율").Trim());    //:this_month_profit_and_loss_rate
            int           누적손익율   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "누적손익율").Trim());    //:accumulative_profit_and_loss_rate
            int           출력건수    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "출력건수").Trim());     //:accumulative_profit_and_loss_rate

            sb.Append("날짜:{0}|계좌명:{1}|지점명:{2}|예수금:{3}|D+2추정예수금:{4}|유가잔고평가액:{5}|예탁자산평가액:{6}|총매입금액:{7}|추정예탁자산:{8}");
            sb.Append("|매도담보대출금:{9}|당일투자원금:{10}|당월투자원금:{11}|누적투자원금:{12}|당일투자손익:{13}|당월투자손익:{14}|누적투자손익:{15}");
            sb.Append("|당일손익율:{16}|당월손익율:{17}|누적손익율:{18}|출력건수:{19}");
            String tmp  = sb.ToString();
            String tmp1 = String.Format(tmp
                                        , stockDate
                                        , 계좌명
                                        , 지점명
                                        , 예수금
                                        , D2추정예수금
                                        , 가잔고평가액
                                        , 예탁자산평가액
                                        , 총매입금액
                                        , 추정예탁자산
                                        , 매도담보대출금
                                        , 당일투자원금
                                        , 당월투자원금
                                        , 누적투자원금
                                        , 당일투자손익
                                        , 당월투자손익
                                        , 누적투자손익
                                        , 당일손익율
                                        , 당월손익율
                                        , 누적손익율
                                        , 출력건수
                                        );

            sbAll.AppendLine(tmp1);

            int nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);

            for (int i = 1; i < nCnt; i++)
            {
                String 계좌명1     = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "계좌명").Trim();
                String 지점명1     = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "지점명").Trim();
                int    예수금1     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "예수금").Trim());
                int    D2추정예수금1 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "D+2추정예수금").Trim());
                int    가잔고평가액1  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "유가잔고평가액").Trim());
                int    예탁자산평가액1 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "예탁자산평가액").Trim());
                int    총매입금액1   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "총매입금액").Trim());
                int    추정예탁자산1  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "추정예탁자산").Trim());
                int    매도담보대출금1 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도담보대출금").Trim());
                int    당일투자원금1  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일투자원금").Trim());
                int    당월투자원금1  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당월투자원금").Trim());
                int    누적투자원금1  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "누적투자원금").Trim());
                int    당일투자손익1  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일투자손익").Trim());
                int    당월투자손익1  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당월투자손익").Trim());
                int    누적투자손익1  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "누적투자손익").Trim());
                int    당일손익율1   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일손익율").Trim());
                int    당월손익율1   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, 0, "당월손익율").Trim());
                int    누적손익율1   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "누적손익율").Trim());
                int    출력건수1    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "출력건수").Trim());

                tmp1 = String.Format(tmp
                                     , stockDate
                                     , 계좌명1
                                     , 지점명1
                                     , 예수금1
                                     , D2추정예수금1
                                     , 가잔고평가액1
                                     , 예탁자산평가액1
                                     , 총매입금액1
                                     , 추정예탁자산1
                                     , 매도담보대출금1
                                     , 당일투자원금1
                                     , 당월투자원금1
                                     , 누적투자원금1
                                     , 당일투자손익1
                                     , 당월투자손익1
                                     , 누적투자손익1
                                     , 당일손익율1
                                     , 당월손익율1
                                     , 누적손익율1
                                     , 출력건수1
                                     );
                sbAll.AppendLine(tmp1);
            }

            path = System.IO.Path.GetDirectoryName(path);
            path = path + "\\OPW00004_" + stockDate + ".log";
            System.IO.StreamWriter file = new System.IO.StreamWriter(path, false);
            file.Write(sbAll.ToString());
            file.Close();
        }
Exemplo n.º 13
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPT10059");
            try
            {
                /*
                 * sScrNo – 화면번호
                 * sRQName – 사용자구분 명
                 * sTrCode – Tran 명
                 * sRecordName – Record 명
                 * sPreNext – 연속조회 유무
                 */
                List <TB_OPT10059> lst  = new List <TB_OPT10059>();
                String             종목코드 = "XXXX";
                int nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);

                String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
                String keyStockCode       = String.Format(keyStockCodeLayout
                                                          , e.sRQName
                                                          , e.sTrCode
                                                          , e.sScrNo
                                                          );
                종목코드 = AppLib.getClass1Instance().getStockCode(keyStockCode);

                String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|stockCode:{3}";
                String key       = String.Format(keyLayout
                                                 , e.sRQName
                                                 , e.sTrCode
                                                 , e.sScrNo
                                                 , 종목코드
                                                 );

                spell = AppLib.getClass1Instance().getSpell(key);
                String startDate = spell.startDate;

                String lastStockDate = "";
                int    startDate일자   = 0;
                if (!int.TryParse(startDate, out startDate일자))
                {
                    startDate일자 = 0;
                }

                if (nCnt > 0)
                {
                    for (int i = 0; i < nCnt; i++)
                    {
                        int 일자 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim());//[0]
                        lastStockDate = 일자.ToString();
                        if (startDate != null)
                        {
                            if (!(일자 >= startDate일자))
                            {
                                //입력받은 20200301 을 정수로 바꾼 strartDAte일자
                                //데이터로 받을 "일자" 가 이것보다 큰것만 가져온다.
                                //명령을 넣을때 실제로 시작일자는 ui상에서 종료일자가 들어간다.\
                                // api는 시작일자를 기준으로 내림차순으로 하기 때문이다.
                                //내림차순으로 받은거에서 끊는 역할을 해준다.
                                break;
                            }
                        }

                        int 개인투자자  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "개인투자자").Trim());  //[6]
                        int 외국인투자자 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "외국인투자자").Trim()); //[7]
                        int 기관계    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기관계").Trim());    //[8]
                        int 금융투자   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "금융투자").Trim());   //[9]
                        int 보험     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "보험").Trim());     //[10]
                        int 투신     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "투신").Trim());     //[11]
                        int 기타금융   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기타금융").Trim());   //[12]
                        int 은행     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "은행").Trim());     //[13]
                        int 연기금등   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "연기금등").Trim());   //[14]
                        int 사모펀드   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "사모펀드").Trim());   //[15]
                        int 국가     = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "국가").Trim());     //[16]
                        int 기타법인   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기타법인").Trim());   //[17]
                        int 내외국인   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "내외국인").Trim());   //[18]


                        TB_OPT10059 tmp = new TB_OPT10059();
                        tmp.stock_cd             = 종목코드;
                        tmp.stock_dt             = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim();
                        tmp.buy_sell             = spell.buyOrSell;
                        tmp.amt_amount           = spell.priceOrAmount;
                        tmp.domestic_investor    = 개인투자자;
                        tmp.foreign_investor     = 외국인투자자;
                        tmp.institution          = 기관계;
                        tmp.financial_investment = 금융투자;
                        tmp.insurance            = 보험;
                        tmp.investment_trust     = 투신;
                        tmp.etc_financial        = 기타금융;
                        tmp.bank                        = 은행;
                        tmp.pension_fund                = 연기금등;
                        tmp.private_equity_fund         = 사모펀드;
                        tmp.nation                      = 국가;
                        tmp.etc_corporation             = 기타법인;
                        tmp.foregin_investment_in_korea = 내외국인;
                        tmp.prev_next                   = e.sPrevNext;
                        lst.Add(tmp);
                    }
                }
                else
                {
                    종목코드 = "00000";
                }

                if (lst.Count() > 0)
                {
                    DailyData dd = new DailyData();
                    dd.insertOpt10059(lst);
                }

                int prevNext = 0;
                int.TryParse(e.sPrevNext, out prevNext);
                //ScreenNumber.getClass1Instance().DisconnectRealData(e.sScrNo);
                //ScreenNumber.getClass1Instance().SetRealRemove("ALL", "ALL");
                //래치를 호출해서 잠김을 제거한다.--래치 일단 제거 호출하는데도 제거 했다. 1초에 5번 호출 규칙만 적용해보자.
                AppLib.getClass1Instance().setOpt10081(spell.sTrCode);
                //2020년03월29일 확인 내용
                //nprevNext가 0이면 종료고 2이면 진행으로 알고 있었다.
                //그런데 어느시점이 지나가면 그게 아닌것 같다.
                //이걸 확인하려면 디비에 이걸 넣어야한다.
                //2012년까지 정상동작하고 이전데이터는 무조건 prev_next를 0을 리턴한다.
                //이건 수동으로 봐야겠다. 끝.

                if (startDate.Equals("ZERO") || (startDate.Length == 8 && startDate.CompareTo(lastStockDate) >= 0) || prevNext == 0)
                //ZERO면 한번만 호출이다. 또는 시작일과 마지막 리턴일이 같다면 종료되어야한다.
                {
                    AppLib.getClass1Instance().removeSpellDictionary(spell.key);
                    int    position = spell.key.LastIndexOf("|");
                    String key1     = spell.key.Substring(0, position);
                    //래치를 호출해서 잠김을 제거한다.--래치 일단 제거 호출하는데도 제거 했다. 1초에 5번 호출 규칙만 적용해보자.
                }
                else if (prevNext > 0)
                {
                    //putReceivedQueueAndsetNextSpell(key, prevNext, lastStockDate);
                    OpenApi.Spell.SpellOpt tmp = spell.ShallowCopy();
                    tmp.nPrevNext     = prevNext;
                    tmp.lastStockDate = lastStockDate;
                    AppLib.getClass1Instance().removeSpellDictionary(key);
                    AppLib.getClass1Instance().AddSpellDictionary(key, tmp);
                    AppLib.getClass1Instance().EnqueueByOrderQueue(tmp);  //주문을 다시 넣는다.
                }
            }
            catch (Exception ex)
            {
                FileLog.PrintF("[ALERT-ReceivedData-OPT10059]Exception ex=" + ex.Message);
            }
        }
Exemplo n.º 14
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPTKWFID");
            //try {

            /*
             * sScrNo – 화면번호
             * sRQName – 사용자구분 명
             * sTrCode – Tran 명
             * sRecordName – Record 명
             * sPreNext – 연속조회 유무
             */
            String 종목코드 = "XXXX";
            int    nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);
            String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
            String keyStockCode       = String.Format(keyStockCodeLayout
                                                      , e.sRQName
                                                      , e.sTrCode
                                                      , e.sScrNo
                                                      );

            종목코드 = AppLib.getClass1Instance().getStockCode(keyStockCode);

            String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|stockCode:{3}";
            String key       = String.Format(keyLayout
                                             , e.sRQName
                                             , e.sTrCode
                                             , e.sScrNo
                                             , 종목코드
                                             );

            spell = AppLib.getClass1Instance().getSpell(key).ShallowCopy();

            List <TB_OPTKWFID> lst = new List <TB_OPTKWFID>();


            if (nCnt > 0)
            {
                for (int i = 0; i < nCnt; i++)
                {
                    /*
                     * FileLog.PrintF("OPTKWFID ReceivedData 종목코드 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim());//[1]
                     * FileLog.PrintF("OPTKWFID ReceivedData 종목명 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목명").Trim());//[2]
                     * FileLog.PrintF("OPTKWFID ReceivedData 현재가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim());//[3]
                     * FileLog.PrintF("OPTKWFID ReceivedData 기준가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기준가").Trim());//[4]
                     * FileLog.PrintF("OPTKWFID ReceivedData 전일대비 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비").Trim());//[5]
                     * FileLog.PrintF("OPTKWFID ReceivedData 전일대비기호 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비기호").Trim());//[6]
                     * FileLog.PrintF("OPTKWFID ReceivedData 등락율 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "등락율").Trim());//[7]
                     * FileLog.PrintF("OPTKWFID ReceivedData 거래량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래량").Trim());//[8]
                     * FileLog.PrintF("OPTKWFID ReceivedData 거래대금 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래대금").Trim());//[9]
                     * FileLog.PrintF("OPTKWFID ReceivedData 체결량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결량").Trim());//[10]
                     * FileLog.PrintF("OPTKWFID ReceivedData 체결강도 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결강도").Trim());//[11]
                     * FileLog.PrintF("OPTKWFID ReceivedData 전일거래량대비 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일거래량대비").Trim());//[12]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매도호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도호가").Trim());//[13]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매수호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수호가").Trim());//[14]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매도1차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도1차호가").Trim());//[15]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매도2차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도2차호가").Trim());//[16]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매도3차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도3차호가").Trim());//[17]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매도4차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도4차호가").Trim());//[18]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매도5차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도5차호가").Trim());//[19]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매수1차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수1차호가").Trim());//[20]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매수2차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수2차호가").Trim());//[21]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매수3차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수3차호가").Trim());//[22]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매수4차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수4차호가").Trim());//[23]
                     * FileLog.PrintF("OPTKWFID ReceivedData 매수5차호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수5차호가").Trim());//[24]
                     * FileLog.PrintF("OPTKWFID ReceivedData 상한가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "상한가").Trim());//[25]
                     * FileLog.PrintF("OPTKWFID ReceivedData 하한가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "하한가").Trim());//[26]
                     * FileLog.PrintF("OPTKWFID ReceivedData 시가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가").Trim());//[27]
                     * FileLog.PrintF("OPTKWFID ReceivedData 고가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "고가").Trim());//[28]
                     * FileLog.PrintF("OPTKWFID ReceivedData 저가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "저가").Trim());//[29]
                     * FileLog.PrintF("OPTKWFID ReceivedData 종가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종가").Trim());//[30]
                     * FileLog.PrintF("OPTKWFID ReceivedData 체결시간 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결시간").Trim());//[31]
                     * FileLog.PrintF("OPTKWFID ReceivedData 예상체결가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "예상체결가").Trim());//[32]
                     * FileLog.PrintF("OPTKWFID ReceivedData 예상체결량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "예상체결량").Trim());//[33]
                     * FileLog.PrintF("OPTKWFID ReceivedData 자본금 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "자본금").Trim());//[34]
                     * FileLog.PrintF("OPTKWFID ReceivedData 액면가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "액면가").Trim());//[35]
                     * FileLog.PrintF("OPTKWFID ReceivedData 시가총액 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가총액").Trim());//[36]
                     * FileLog.PrintF("OPTKWFID ReceivedData 주식수 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주식수").Trim());//[37]
                     * FileLog.PrintF("OPTKWFID ReceivedData 호가시간 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "호가시간").Trim());//[38]
                     * FileLog.PrintF("OPTKWFID ReceivedData 일자 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim());//[39]
                     * FileLog.PrintF("OPTKWFID ReceivedData 우선매도잔량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "우선매도잔량").Trim());//[40]
                     * FileLog.PrintF("OPTKWFID ReceivedData 우선매수잔량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "우선매수잔량").Trim());//[41]
                     * FileLog.PrintF("OPTKWFID ReceivedData 우선매도건수 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "우선매도건수").Trim());//[42]
                     * FileLog.PrintF("OPTKWFID ReceivedData 우선매수건수 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "우선매수건수").Trim());//[43]
                     * FileLog.PrintF("OPTKWFID ReceivedData 총매도잔량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "총매도잔량").Trim());//[44]
                     * FileLog.PrintF("OPTKWFID ReceivedData 총매수잔량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "총매수잔량").Trim());//[45]
                     * FileLog.PrintF("OPTKWFID ReceivedData 총매도건수 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "총매도건수").Trim());//[46]
                     * FileLog.PrintF("OPTKWFID ReceivedData 총매수건수 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "총매수건수").Trim());//[47]
                     * FileLog.PrintF("OPTKWFID ReceivedData 패리티 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "패리티").Trim());//[48]
                     * FileLog.PrintF("OPTKWFID ReceivedData 기어링 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기어링").Trim());//[49]
                     * FileLog.PrintF("OPTKWFID ReceivedData 손익분기 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "손익분기").Trim());//[50]
                     * FileLog.PrintF("OPTKWFID ReceivedData ELW행사가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "ELW행사가").Trim());//[51]
                     * FileLog.PrintF("OPTKWFID ReceivedData 전환비율 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전환비율").Trim());//[52]
                     * FileLog.PrintF("OPTKWFID ReceivedData ELW만기일 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "ELW만기일").Trim());//[53]
                     * FileLog.PrintF("OPTKWFID ReceivedData 미결제약정 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "미결제약정").Trim());//[54]
                     * FileLog.PrintF("OPTKWFID ReceivedData 미결제전일대비 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "미결제전일대비").Trim());//[55]
                     * FileLog.PrintF("OPTKWFID ReceivedData 이론가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "이론가").Trim());//[56]
                     * FileLog.PrintF("OPTKWFID ReceivedData 내재변동성 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "내재변동성").Trim());//[57]
                     * FileLog.PrintF("OPTKWFID ReceivedData 델타 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "델타").Trim());//[58]
                     * FileLog.PrintF("OPTKWFID ReceivedData 감마 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "감마").Trim());//[59]
                     * FileLog.PrintF("OPTKWFID ReceivedData 세타 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "세타").Trim());//[60]
                     * FileLog.PrintF("OPTKWFID ReceivedData 베가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "베가").Trim());//[61]
                     * FileLog.PrintF("OPTKWFID ReceivedData 로 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "로").Trim());//[62]
                     */


                    /*
                     *[2020-04-18 00:45:39]OPTKWFID ReceivedData 종목코드 =>000390
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 종목명 =>삼화페인트
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 현재가 =>+5110
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 기준가 =>5040
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 전일대비 =>+70
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 전일대비기호 =>2
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 등락율 =>+1.39
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 거래량 =>50291
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 거래대금 =>256
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 체결량 =>+1
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 체결강도 =>108.71
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 전일거래량대비 =>+283.20
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매도호가 =>+5120
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매수호가 =>+5110
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매도1차호가 =>+5120
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매도2차호가 =>+5130
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매도3차호가 =>+5140
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매도4차호가 =>+5150
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매도5차호가 =>+5160
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매수1차호가 =>+5110
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매수2차호가 =>+5100
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매수3차호가 =>+5090
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매수4차호가 =>+5080
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 매수5차호가 =>+5070
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 상한가 =>+6550
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 하한가 =>-3530
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 시가 =>5040
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 고가 =>+5170
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 저가 =>5040
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 종가 =>+5110
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 체결시간 =>155926
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 예상체결가 =>+5110
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 예상체결량 =>334
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 자본금 =>132
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 액면가 =>500
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 시가총액 =>1351
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 주식수 =>26439
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 호가시간 =>160000
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 일자 =>20200417
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 우선매도잔량 =>270
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 우선매수잔량 =>117
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 우선매도건수 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 우선매수건수 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 총매도잔량 =>7991
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 총매수잔량 =>12270
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 총매도건수 =>-1000
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 총매수건수 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 패리티 =>0.00
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 기어링 =>0.00
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 손익분기 =>0.00
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData ELW행사가 =>0
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 전환비율 =>0.0000
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData ELW만기일 =>00000000
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 미결제약정 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 미결제전일대비 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 이론가 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 내재변동성 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 델타 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 감마 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 세타 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 베가 =>
                     * [2020-04-18 00:45:39]OPTKWFID ReceivedData 로 =>
                     */



                    TB_OPTKWFID tb_optkwfid = new TB_OPTKWFID();

                    tb_optkwfid.stock_cd = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim(); //[0]
                    tb_optkwfid.stock_nm = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목명").Trim();  //[1]

                    int 현재가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim(), out 현재가);
                    tb_optkwfid.curr_amt = 현재가;

                    int 기준가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기준가").Trim(), out 기준가);
                    tb_optkwfid.yesterday_amt = 기준가;

                    int 전일대비 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비").Trim(), out 전일대비);
                    tb_optkwfid.contrast_yesterday = 전일대비;

                    int 전일대비기호 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비기호").Trim(), out 전일대비기호);
                    tb_optkwfid.contrast_yesterday_symbol = 전일대비기호;

                    float 등락율 = 0;
                    float.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "등락율").Trim(), out 등락율);
                    tb_optkwfid.fluctuation_rt = 등락율;

                    int 거래량 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래량").Trim(), out 거래량);
                    tb_optkwfid.trade_qty = 거래량;

                    int 거래대금 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래대금").Trim(), out 거래대금);
                    tb_optkwfid.trade_amt = 거래대금;

                    int 체결량 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결량").Trim(), out 체결량);
                    tb_optkwfid.contract_qty = 체결량;

                    float 체결강도 = 0;
                    float.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결강도").Trim(), out 체결강도);
                    tb_optkwfid.contract_strength = 체결강도;

                    float 전일거래량대비 = 0;
                    float.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일거래량대비").Trim(), out 전일거래량대비);
                    tb_optkwfid.yesterday_contrast_trade_rt = 전일거래량대비;

                    int 매도호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도호가").Trim(), out 매도호가);
                    tb_optkwfid.offered_amt = 매도호가;

                    int 매수호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수호가").Trim(), out 매수호가);
                    tb_optkwfid.bid_amt = 매수호가;

                    int 매도1차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도1차호가").Trim(), out 매도1차호가);
                    tb_optkwfid.offered_amt_one = 매도1차호가;

                    int 매도2차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도2차호가").Trim(), out 매도2차호가);
                    tb_optkwfid.offered_amt_two = 매도2차호가;

                    int 매도3차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도3차호가").Trim(), out 매도3차호가);
                    tb_optkwfid.offered_amt_three = 매도3차호가;

                    int 매도4차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도4차호가").Trim(), out 매도4차호가);
                    tb_optkwfid.offered_amt_four = 매도4차호가;

                    int 매도5차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도5차호가").Trim(), out 매도5차호가);
                    tb_optkwfid.offered_amt_five = 매도5차호가;

                    int 매수1차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수1차호가").Trim(), out 매수1차호가);
                    tb_optkwfid.bid_amt_one = 매수1차호가;

                    int 매수2차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수2차호가").Trim(), out 매수2차호가);
                    tb_optkwfid.bid_amt_two = 매수2차호가;

                    int 매수3차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수3차호가").Trim(), out 매수3차호가);
                    tb_optkwfid.bid_amt_three = 매수3차호가;

                    int 매수4차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수4차호가").Trim(), out 매수4차호가);
                    tb_optkwfid.bid_amt_four = 매수4차호가;

                    int 매수5차호가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수5차호가").Trim(), out 매수5차호가);
                    tb_optkwfid.bid_amt_five = 매수5차호가;


                    int 상한가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "상한가").Trim(), out 상한가);
                    tb_optkwfid.upper_amt_lmt = 상한가;

                    int 하한가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "하한가").Trim(), out 하한가);
                    tb_optkwfid.lower_amt_lmt = 하한가;

                    int 시작가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시작가").Trim(), out 시작가);
                    tb_optkwfid.start_amt = 시작가;

                    int 고가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "고가").Trim(), out 고가);
                    tb_optkwfid.high_amt = 고가;

                    int 저가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "저가").Trim(), out 저가);
                    tb_optkwfid.low_amt = 저가;

                    int 종가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종가").Trim(), out 종가);
                    tb_optkwfid.clsg_amt = 종가;

                    tb_optkwfid.contract_time = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결시간").Trim();//[1]

                    int 예상체결가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "예상체결가").Trim(), out 예상체결가);
                    tb_optkwfid.expectation_contract_amt = 예상체결가;


                    int 예상체결수량 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "예상체결수량").Trim(), out 예상체결수량);
                    tb_optkwfid.expectation_contract_qty = 예상체결수량;

                    int 자본금 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "자본금").Trim(), out 자본금);
                    tb_optkwfid.capital_amt = 자본금;

                    int 액면가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "액면가").Trim(), out 액면가);
                    tb_optkwfid.face_amt = 액면가;

                    int 시가총액 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가총액").Trim(), out 시가총액);
                    tb_optkwfid.total_mrkt_amt = 시가총액;

                    int 상장주식수 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "상장주식수").Trim(), out 상장주식수);
                    tb_optkwfid.stock_cnt = 상장주식수;

                    tb_optkwfid.hoga_time = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "호가시간").Trim(); //[1]
                    tb_optkwfid.stock_dt  = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim();   //[1]

                    int 우선매도잔량 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "우선매도잔량").Trim(), out 우선매도잔량);
                    tb_optkwfid.fst_offered_balance = 우선매도잔량;

                    int 우선매수잔량 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "우선매수잔량").Trim(), out 우선매수잔량);
                    tb_optkwfid.fst_bid_balance = 우선매수잔량;

                    int 우선매도건수 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "우선매도건수").Trim(), out 우선매도건수);
                    tb_optkwfid.fst_offered_qty = 우선매도건수;

                    int 우선매수건수 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "우선매수건수").Trim(), out 우선매수건수);
                    tb_optkwfid.fst_bid_qty = 우선매수건수;

                    int 총매도잔량 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "총매도잔량").Trim(), out 총매도잔량);
                    tb_optkwfid.tot_offered_balance = 총매도잔량;

                    int 총매수잔량 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "총매수잔량").Trim(), out 총매수잔량);
                    tb_optkwfid.tot_bid_balance = 총매수잔량;

                    int 총매도건수 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "총매도건수").Trim(), out 총매도건수);
                    tb_optkwfid.tot_offered_qty = 총매도건수;

                    int 총매수건수 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "총매수건수").Trim(), out 총매수건수);
                    tb_optkwfid.tot_bid_qty = 총매수건수;

                    float 패리티 = 0;
                    float.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "패리티").Trim(), out 패리티);
                    tb_optkwfid.parity_rt = 패리티;

                    float 기어링 = 0;
                    float.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기어링").Trim(), out 기어링);
                    tb_optkwfid.gearing = 기어링;

                    float 손익분기 = 0;
                    float.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "손익분기").Trim(), out 손익분기);
                    tb_optkwfid.break_even_point = 기어링;

                    int ELW행사가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "ELW행사가").Trim(), out ELW행사가);
                    tb_optkwfid.elw_strike_amt = ELW행사가;

                    float 전환비율 = 0;
                    float.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전환비율").Trim(), out 전환비율);
                    tb_optkwfid.conversion_rt = 전환비율;

                    tb_optkwfid.elw_expiry_dt = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "ELW만기일").Trim();//[1]

                    int 미결제약정 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "미결제약정").Trim(), out 미결제약정);
                    tb_optkwfid.open_interest = 미결제약정;

                    int 미결제전일대비 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "미결제전일대비").Trim(), out 미결제전일대비);
                    tb_optkwfid.contrast_open_interest = 미결제전일대비;


                    int 이론가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "이론가").Trim(), out 이론가);
                    tb_optkwfid.theorist_amt = 이론가;

                    int 내재변동성 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "내재변동성").Trim(), out 내재변동성);
                    tb_optkwfid.implied_volatility = 내재변동성;

                    int 델타 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "델타").Trim(), out 델타);
                    tb_optkwfid.delta = 델타;

                    int 감마 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "감마").Trim(), out 감마);
                    tb_optkwfid.gamma = 감마;


                    int 세타 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "세타").Trim(), out 세타);
                    tb_optkwfid.theta = 세타;

                    int 베가 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "베가").Trim(), out 베가);
                    tb_optkwfid.vega = 베가;

                    int 로 = 0;
                    int.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "로").Trim(), out 로);
                    tb_optkwfid.lo = 로;

                    //(8025-8089)/8089*100
                    //24005=23775+160+70
                    //24005-24575=-570
                    //24805
                    lst.Add(tb_optkwfid);
                }
            }

            //이것은 연속적이지 않기 때문에 바로 제거 한다.
            AppLib.getClass1Instance().removeSpellDictionary(spell.key);
            int    position = spell.key.LastIndexOf("|");
            String key1     = spell.key.Substring(0, position);

            AppLib.getClass1Instance().removeStockCodeDictionary(key1);
            //래치를 호출해서 잠김을 제거한다.--래치 일단 제거 호출하는데도 제거 했다. 1초에 5번 호출 규칙만 적용해보자.
            AppLib.getClass1Instance().setOpt10081(spell.sTrCode);

            DailyData dd = new DailyData();

            dd.insertOptkwfid(lst);
        }
Exemplo n.º 15
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPT10085");
            //try {

            /*
             * sScrNo – 화면번호
             * sRQName – 사용자구분 명
             * sTrCode – Tran 명
             * sRecordName – Record 명
             * sPreNext – 연속조회 유무
             */
            String 계좌번호 = "XXXXXXXXXX";
            int    nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);
            String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
            String keyStockCode       = String.Format(keyStockCodeLayout
                                                      , e.sRQName
                                                      , e.sTrCode
                                                      , e.sScrNo
                                                      );

            계좌번호 = AppLib.getClass1Instance().getStockCode(keyStockCode);

            String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|accountNum:{3}";
            String key       = String.Format(keyLayout
                                             , e.sRQName
                                             , e.sTrCode
                                             , e.sScrNo
                                             , 계좌번호
                                             );

            spell = AppLib.getClass1Instance().getSpell(key).ShallowCopy();

            List <TB_OPT10085> opt10085_DataList = new List <TB_OPT10085>();


            if (nCnt > 0)
            {
                for (int i = 0; i < nCnt; i++)
                {
                    FileLog.PrintF("OPT10085 ReceivedData 구매일자 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim());         //[0]
                    FileLog.PrintF("OPT10085 ReceivedData 종목코드 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim());       //[1]
                    FileLog.PrintF("OPT10085 ReceivedData 종목명 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목명").Trim());         //[2]
                    FileLog.PrintF("OPT10085 ReceivedData 현재가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim());         //[3]
                    FileLog.PrintF("OPT10085 ReceivedData 매입가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입가").Trim());         //[4]
                    FileLog.PrintF("OPT10085 ReceivedData 매입금액 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입금액").Trim());       //[5]
                    FileLog.PrintF("OPT10085 ReceivedData 보유수량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "보유수량").Trim());       //[6]
                    FileLog.PrintF("OPT10085 ReceivedData 당일매도손익 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매도손익").Trim());   //[7]
                    FileLog.PrintF("OPT10085 ReceivedData 당일매매수수료 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매수수료").Trim()); //[8]
                    FileLog.PrintF("OPT10085 ReceivedData 당일매매세금 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매세금").Trim());   //[9]
                    FileLog.PrintF("OPT10085 ReceivedData 신용구분 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용구분").Trim());       //[10]
                    FileLog.PrintF("OPT10085 ReceivedData 대출일 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대출일").Trim());         //[11]
                    FileLog.PrintF("OPT10085 ReceivedData 결제잔고 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "결제잔고").Trim());       //[12]
                    FileLog.PrintF("OPT10085 ReceivedData 청산가능수량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "청산가능수량").Trim());   //[13]
                    FileLog.PrintF("OPT10085 ReceivedData 신용금액 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용금액").Trim());       //[14]
                    FileLog.PrintF("OPT10085 ReceivedData 신용이자 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용이자").Trim());       //[15]
                    FileLog.PrintF("OPT10085 ReceivedData 만기일 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "만기일").Trim());         //[16]



                    TB_OPT10085 opt10085_Data = new TB_OPT10085();
                    opt10085_Data.purchase_dt = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim();                             //[0]
                    opt10085_Data.stock_cd    = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim();                           //[1]
                    int 현재가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim());                                 //[3]
                    opt10085_Data.curr_amt     = 현재가;
                    opt10085_Data.purchase_amt = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입가").Trim());              //[4]
                    int 매입금액 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입금액").Trim());                               //[5]
                    opt10085_Data.tot_purchase_amt = 매입금액;
                    int 보유수량 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "보유수량").Trim());                               //[6]
                    opt10085_Data.possession_qty         = 보유수량;
                    opt10085_Data.today_sell_profit_loss = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매도손익").Trim()); //[7]
                    String str당일매매수수료 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매수수료");
                    opt10085_Data.today_commission = 0;
                    if (isNotNull(str당일매매수수료) == true)
                    {
                        opt10085_Data.today_commission = Int32.Parse(str당일매매수수료.Trim());                                                //[8]
                    }
                    opt10085_Data.today_tax       = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매세금").Trim()); //[9]
                    opt10085_Data.credit_gubun    = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용구분").Trim();                //[10]
                    opt10085_Data.loan_dt         = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대출일").Trim();                 //[11]
                    opt10085_Data.payment_balance = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "결제잔고").Trim());   //[12]
                    opt10085_Data.sellable_qty    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "청산가능수량").Trim()); //[13]
                    opt10085_Data.credit_amt      = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용금액").Trim());   //[14]
                    opt10085_Data.credit_interest = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용이자").Trim());   //[15]
                    opt10085_Data.expiry_dt       = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "만기일").Trim();                 //[16]

                    /*내가 만들 데이터*/

                    /*매입가에는 수수료가 포함안되어있다. 매입당시 수수료가 통장에서 빠져나가지만 내가 얼마나 수익이 났는지 확인하기 위해
                     * 매입수수료와 매도 수수료를 합쳐서 수수료로 표시해준다.
                     * 수수료는 10원 미만 절삭 86원이면 80원임
                     */
                    //System.Math.Truncate()
                    int 평가금액    = Math.Abs(현재가) * 보유수량;
                    int 매입수수료   = Commission.GetKiwoomCommissionBuy(매입금액);
                    int 매도수수료   = Commission.GetKiwoomCommissionSell(평가금액);
                    int 수수료     = 매입수수료 + 매도수수료;
                    int 매도세금    = Commission.GetTaxSell(평가금액);
                    int 손익분기매입가 = 0;
                    if (보유수량 != 0)                                      //이게 0일경우가 있다 매도를 한상태일경우 보유수량이 0으로 리스트에 계속 존재한다.
                    {
                        손익분기매입가 = (매입수수료 + 매도수수료 + 매도세금 + 매입금액) / 보유수량; // 무조건오림
                    }
                    int 평가손익 = 평가금액 - (매입금액 + 수수료 + 매도세금);
                    // float 수익률 = (평가손익 / 매입금액) * 100;   //int끼리 나눠서... 소수점을 버리는구나.. 이런..
                    float 수익률 = 0;
                    if (매입금액 != 0)
                    {
                        수익률 = ((float)평가손익 / (float)매입금액) * 100;
                    }
                    int 손익금액 = (평가금액 - 매입금액);

                    float 손익율 = 0;
                    if (매입금액 != 0)
                    {
                        손익율 = ((float)손익금액 / (float)매입금액) * 100;
                    }



                    opt10085_Data.evaluated_amt              = 평가금액;
                    opt10085_Data.selling_commission         = 매입수수료;
                    opt10085_Data.buying_commission          = 매도수수료;
                    opt10085_Data.commission                 = 수수료;
                    opt10085_Data.selling_tax                = 매도세금;
                    opt10085_Data.will_profit_amt            = 손익분기매입가;
                    opt10085_Data.valuation_profit_loss      = 평가손익;
                    opt10085_Data.earnings_rt                = 수익률;
                    opt10085_Data.not_commission_profit_loss = 손익금액;
                    opt10085_Data.profit_loss_rt             = 손익율;
                    opt10085_Data.acct_num = 계좌번호;


                    FileLog.PrintF("OPT10085 ReceivedData 평가손익=>" + 평가손익);
                    FileLog.PrintF("OPT10085 ReceivedData 손익금액=>" + 손익금액);
                    FileLog.PrintF("OPT10085 ReceivedData 매입금액=>" + 매입금액);
                    FileLog.PrintF("OPT10085 ReceivedData 평가손익=>" + 평가손익);
                    FileLog.PrintF("OPT10085 ReceivedData 수익률=>" + 수익률);
                    FileLog.PrintF("OPT10085 ReceivedData 손익율=>" + 손익율);


                    //(8025-8089)/8089*100
                    //24005=23775+160+70
                    //24005-24575=-570
                    //24805
                    opt10085_DataList.Add(opt10085_Data);
                }
            }

            //이것은 연속적이지 않기 때문에 바로 제거 한다.
            AppLib.getClass1Instance().removeSpellDictionary(spell.key);
            int    position = spell.key.LastIndexOf("|");
            String key1     = spell.key.Substring(0, position);

            AppLib.getClass1Instance().removeStockCodeDictionary(key1);
            //래치를 호출해서 잠김을 제거한다.--래치 일단 제거 호출하는데도 제거 했다. 1초에 5번 호출 규칙만 적용해보자.
            AppLib.getClass1Instance().setOpt10081(spell.sTrCode);

            DailyData dd = new DailyData();

            dd.insertOpt10085(opt10085_DataList);
        }
Exemplo n.º 16
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPT10001");
            try {
                /*
                 * sScrNo – 화면번호
                 * sRQName – 사용자구분 명
                 * sTrCode – Tran 명
                 * sRecordName – Record 명
                 * sPreNext – 연속조회 유무
                 */
                StringBuilder sbAll = new StringBuilder();
                StringBuilder sb    = new StringBuilder();

                /*일자,종목코드 ,종가,전일대비기호,전일대비,등락율,거래량,공매도량,매매비중,공매도거래대금,공매도평균가*/
                sb.Append("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}|{16}|{17}|{18}|{19}|{20}|{21}|{22}|{23}|{24}|{25}|{26}|{27}|{28}|{29}|{30}|{31}|{32}|{33}|{34}|{35}|{36}|{37}|{38}|{39}|{40}|{41}|{42}");
                String tmp  = sb.ToString();
                String 종목코드 = "XXXX";
                int    nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);
                String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
                String keyStockCode       = String.Format(keyStockCodeLayout
                                                          , e.sRQName
                                                          , e.sTrCode
                                                          , e.sScrNo
                                                          );
                종목코드 = AppLib.getClass1Instance().getStockCode(keyStockCode);

                String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|stockCode:{3}";
                String key       = String.Format(keyLayout
                                                 , e.sRQName
                                                 , e.sTrCode
                                                 , e.sScrNo
                                                 , 종목코드
                                                 );
                String 일자 = DateTime.Now.ToString("yyyyMMdd");

                spell = AppLib.getClass1Instance().getSpell(key).ShallowCopy();

                //Array arr =(Array)axKHOpenAPI.GetCommDataEx(e.sTrCode, e.sRQName);

                if (nCnt > 0)
                {
                    for (int i = 0; i < nCnt; i++)
                    {
                        String 종목코드1 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim();//[0]
                        if (종목코드1.Equals(""))
                        {
                            종목코드1 = 종목코드;                                                                   //일부 종목코드들은 아래 데이터가 아예 안나온다. ///51A077
                        }
                        String 종목명    = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목명").Trim(); //[1]
                        int    결산월    = 0;
                        String str결산월 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "결산월");
                        if (isNotNull(str결산월) == true)
                        {
                            결산월 = Int32.Parse(str결산월.Trim());//[2]
                        }
                        String str액면가 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "액면가");
                        float  액면가    = 0;
                        if (isNotNull(str액면가) == true)
                        {
                            액면가 = float.Parse(str액면가.Trim());//[3]
                        }
                        String str자본금 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "자본금");
                        int    자본금    = 0;
                        if (isNotNull(str자본금) == true)
                        {
                            자본금 = Int32.Parse(str자본금.Trim());//[4]
                        }
                        String str상장주식 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "상장주식");
                        int    상장주식    = 0;
                        if (isNotNull(str상장주식) == true)
                        {
                            상장주식 = Int32.Parse(str상장주식.Trim());//[5]
                        }
                        String str신용비율 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용비율");
                        float  신용비율    = 0;
                        if (isNotNull(str신용비율) == true)
                        {
                            신용비율 = float.Parse(str신용비율.Trim());//[6]
                        }
                        String str연중최고 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "연중최고");
                        int    연중최고    = 0;
                        if (isNotNull(str연중최고) == true)
                        {
                            연중최고 = int.Parse(str연중최고.Trim());//[7]
                        }
                        String str연중최저 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "연중최저");
                        int    연중최저    = 0;
                        if (isNotNull(str연중최저) == true)
                        {
                            연중최저 = int.Parse(str연중최저.Trim());//[8]
                        }
                        String str시가총액 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가총액");
                        int    시가총액    = 0;
                        if (isNotNull(str시가총액) == true)
                        {
                            시가총액 = int.Parse(str시가총액.Trim());//[9]
                        }
                        String str시가총액비중 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가총액비중");
                        int    시가총액비중    = 0;
                        if (isNotNull(str시가총액비중) == true)
                        {
                            시가총액비중 = Int32.Parse(str시가총액비중.Trim());//[10]
                        }
                        String str외인소진률 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "외인소진률");
                        float  외인소진률    = 0;
                        if (isNotNull(str외인소진률) == true)
                        {
                            외인소진률 = float.Parse(str외인소진률.Trim());//[11]
                        }
                        String str대용가 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대용가");
                        int    대용가    = 0;
                        if (isNotNull(str대용가) == true)
                        {
                            대용가 = int.Parse(str대용가.Trim());//[12]
                        }
                        String strPER = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "PER");
                        float  PER    = 0;
                        if (isNotNull(strPER) == true)
                        {
                            PER = float.Parse(strPER.Trim());//[13]
                        }
                        String strEPS = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "EPS");
                        int    EPS    = 0;
                        if (isNotNull(strEPS) == true)
                        {
                            EPS = int.Parse(strEPS.Trim());//[14]
                        }
                        String strROE = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "ROE");
                        float  ROE    = 0;
                        if (isNotNull(strROE) == true)
                        {
                            ROE = float.Parse(strROE.Trim());//[15]
                        }
                        String strPBR = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "PBR");
                        float  PBR    = 0;
                        if (isNotNull(strPBR) == true)
                        {
                            PBR = float.Parse(strPBR.Trim());//[16]
                        }
                        String strEV = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "EV");
                        float  EV    = 0;
                        if (isNotNull(strEV) == true)
                        {
                            EV = float.Parse(strEV.Trim());//[17]
                        }
                        String strBPS = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "BPS");
                        int    BPS    = 0;
                        if (isNotNull(strBPS) == true)
                        {
                            BPS = int.Parse(strBPS.Trim());//[18]
                        }
                        String str매출액 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매출액");
                        int    매출액    = 0;
                        if (isNotNull(str매출액) == true)
                        {
                            매출액 = Int32.Parse(str매출액.Trim());//[19]
                        }
                        String str영업이익 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "영업이익");
                        int    영업이익    = 0;
                        if (isNotNull(str영업이익) == true)
                        {
                            영업이익 = Int32.Parse(str영업이익.Trim());//[20]
                        }
                        String strD250최고 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "250최고");
                        int    D250최고    = 0;
                        if (isNotNull(strD250최고) == true)
                        {
                            D250최고 = Int32.Parse(strD250최고.Trim());//[21]
                        }
                        String strD250최저 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "250최저");
                        int    D250최저    = 0;
                        if (isNotNull(strD250최저) == true)
                        {
                            D250최저 = Int32.Parse(strD250최저.Trim());//[22]
                        }



                        int 시가  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가").Trim());  //[23]
                        int 고가  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "고가").Trim());  //[24]
                        int 저가  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "저가").Trim());  //[25]
                        int 상한가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "상한가").Trim()); //[26]
                        int 하한가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "하한가").Trim()); //[27]
                        int 기준가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "기준가").Trim()); //[28]

                        String str예상체결가 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "예상체결가");
                        int    예상체결가    = 0;
                        if (isNotNull(str예상체결가) == true)
                        {
                            예상체결가 = Int32.Parse(str예상체결가.Trim());//[29]
                        }

                        String str예상체결수량 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "예상체결수량");
                        int    예상체결수량    = 0;
                        if (isNotNull(str예상체결수량) == true)
                        {
                            예상체결수량 = Int32.Parse(str예상체결수량.Trim());                                                                //[30]
                        }
                        String D250최고가일   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "250최고가일").Trim();                //[31]
                        float  D250최고가대비율 = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "250최고가대비율").Trim()); //[32]
                        String D250최저가일   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "250최저가일").Trim();                //[33]
                        float  D250최저가대비율 = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "250최저가대비율").Trim()); //[34]
                        int    현재가        = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim());       //[35]
                        int    대비기호       = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대비기호").Trim());      //[36]
                        int    전일대비       = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일대비").Trim());      //[37]
                        float  등락율        = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "등락율").Trim());       //[38]
                        int    거래량        = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래량").Trim());       //[39]
                        float  거래대비       = float.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래대비").Trim());      //[40]
                        String 액면가단위      = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "액면가단위").Trim();                  //[41]

                        String tmp1 = String.Format(tmp,
                                                    일자,
                                                    종목코드1,
                                                    종목명,
                                                    결산월,
                                                    액면가,
                                                    자본금,
                                                    상장주식,
                                                    신용비율,
                                                    연중최고,
                                                    연중최저,
                                                    시가총액,
                                                    시가총액비중,
                                                    외인소진률,
                                                    대용가,
                                                    PER,
                                                    EPS,
                                                    ROE,
                                                    PBR,
                                                    EV,
                                                    BPS,
                                                    매출액,
                                                    영업이익,
                                                    D250최고,
                                                    D250최저,
                                                    시가,
                                                    고가,
                                                    저가,
                                                    상한가,
                                                    하한가,
                                                    기준가,
                                                    예상체결가,
                                                    예상체결수량,
                                                    D250최고가일,
                                                    D250최고가대비율,
                                                    D250최저가일,
                                                    D250최저가대비율,
                                                    현재가,
                                                    대비기호,
                                                    전일대비,
                                                    등락율,
                                                    거래량,
                                                    거래대비,
                                                    액면가단위
                                                    );
                        sbAll.AppendLine(tmp1);
                    }
                }
                else
                {
                    종목코드 = "00000";
                }

                //이건 nPreNext가 항상 0이다. 당일 조회만 됨
                int prevNext = 0;
                if (!int.TryParse(e.sPrevNext, out prevNext))
                {
                    prevNext = 0;
                }
                String lastStockDate = "";
                ScreenNumber.getClass1Instance().DisconnectRealData(e.sScrNo);
                ScreenNumber.getClass1Instance().SetRealRemove("ALL", "ALL");
                putReceivedQueueAndsetNextSpell(key, sbAll.ToString(), prevNext, lastStockDate);
            }
            catch (Exception ex)
            {
                FileLog.PrintF("[ALERT-ReceivedData-OPT10001]Exception ex=" + ex.Message);
            }
        }
Exemplo n.º 17
0
        /*받은 TR 데이터 처리 */
        private void 코스피요청_처리(int repeat, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            kospi_InfoList.Clear();
            kospi_chart.Annotations.Clear();
            kospi_chart.Series[0].Points.Clear();

            double max = 0;
            double min = 0;

            bool   flowing_flag  = false;
            bool   buy           = false;
            double buy_price_max = 0;
            double buy_price     = 0;


            //값을 List에 추가
            for (int index = 0; index < repeat; index++)
            {
                kospi_InfoList.Add(new PriceInfoEntityObject()
                {
                    일자  = 키움API.GetCommData(e.sTrCode, e.sRQName, index, "일자").Trim(),
                    시가  = double.Parse(키움API.GetCommData(e.sTrCode, e.sRQName, index, "시가").Trim()) * 0.01,
                    고가  = double.Parse(키움API.GetCommData(e.sTrCode, e.sRQName, index, "저가").Trim()) * 0.01,
                    저가  = double.Parse(키움API.GetCommData(e.sTrCode, e.sRQName, index, "고가").Trim()) * 0.01,
                    현재가 = double.Parse(키움API.GetCommData(e.sTrCode, e.sRQName, index, "현재가").Trim()) * 0.01
                });
            }
            // List를 뒤집음
            kospi_InfoList.Reverse();

            for (int index = 0; index < kospi_InfoList.Count; index++)
            {
                if (index == 0)     // max, min
                {
                    max = kospi_InfoList[0].고가;
                    min = kospi_InfoList[0].저가;
                }
                if (max < kospi_InfoList[index].고가)
                {
                    max = kospi_InfoList[index].고가;
                }
                if (min > kospi_InfoList[index].저가)
                {
                    min = kospi_InfoList[index].저가;
                }
                //Console.WriteLine("{0} {1}", kospi_InfoList[index].일자, kospi_InfoList[index].현재가);
                kospi_chart.Series[0].Points.AddXY(kospi_InfoList[index].일자, kospi_InfoList[index].고가);
                kospi_chart.Series[0].Points[index].YValues[1] = kospi_InfoList[index].저가;
                kospi_chart.Series[0].Points[index].YValues[2] = kospi_InfoList[index].시가;
                kospi_chart.Series[0].Points[index].YValues[3] = kospi_InfoList[index].현재가;

                if (index > 20)
                {
                    if (buy)
                    {
                        if (kospi_InfoList[index].현재가 < buy_price * 0.97)
                        {
                            buy = false; // 손절
                            //Console.WriteLine("진입");
                        }
                        if (kospi_InfoList[index].현재가 > buy_price * 1.03)
                        {
                            flowing_flag = true;
                            if (buy_price > buy_price_max)
                            {
                                buy_price_max = buy_price;
                            }

                            if (kospi_InfoList[index].현재가 < buy_price_max * 0.98)
                            {
                                buy          = false; //익절
                                flowing_flag = false;
                            }
                        }
                    }
                    else
                    {
                        if (kospi_InfoList[index].현재가 > kospi_InfoList[index - 20].고가)
                        {
                            buy_price = kospi_InfoList[index].현재가;
                            buy       = true;
                        }
                    }
                    if (flowing_flag)
                    {
                        kospi_chart.Annotations.Add(ArrowAdd(index, kospi_chart, Color.Aqua));
                    }
                }
            }

            kospi_chart.ChartAreas["ChartArea1"].AxisY.Maximum = max;
            kospi_chart.ChartAreas["ChartArea1"].AxisY.Minimum = min;
        }
Exemplo n.º 18
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPT10085");
            //try {

            /*
             * sScrNo – 화면번호
             * sRQName – 사용자구분 명
             * sTrCode – Tran 명
             * sRecordName – Record 명
             * sPreNext – 연속조회 유무
             */
            String 계좌번호 = "XXXXXXXXXX";
            int    nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);
            String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
            String keyStockCode       = String.Format(keyStockCodeLayout
                                                      , e.sRQName
                                                      , e.sTrCode
                                                      , e.sScrNo
                                                      );

            계좌번호 = AppLib.getClass1Instance().getStockCode(keyStockCode);

            String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|accountNum:{3}";
            String key       = String.Format(keyLayout
                                             , e.sRQName
                                             , e.sTrCode
                                             , e.sScrNo
                                             , 계좌번호
                                             );

            List <OPT10085_Data> opt10085_DataList = new List <OPT10085_Data>();


            if (nCnt > 0)
            {
                for (int i = 0; i < nCnt; i++)
                {
                    FileLog.PrintF("OPT10085 ReceivedData 구매일자 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim());         //[0]
                    FileLog.PrintF("OPT10085 ReceivedData 종목코드 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim());       //[1]
                    FileLog.PrintF("OPT10085 ReceivedData 종목명 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목명").Trim());         //[2]
                    FileLog.PrintF("OPT10085 ReceivedData 현재가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim());         //[3]
                    FileLog.PrintF("OPT10085 ReceivedData 매입가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입가").Trim());         //[4]
                    FileLog.PrintF("OPT10085 ReceivedData 매입금액 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입금액").Trim());       //[5]
                    FileLog.PrintF("OPT10085 ReceivedData 보유수량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "보유수량").Trim());       //[6]
                    FileLog.PrintF("OPT10085 ReceivedData 당일매도손익 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매도손익").Trim());   //[7]
                    FileLog.PrintF("OPT10085 ReceivedData 당일매매수수료 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매수수료").Trim()); //[8]
                    FileLog.PrintF("OPT10085 ReceivedData 당일매매세금 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매세금").Trim());   //[9]
                    FileLog.PrintF("OPT10085 ReceivedData 신용구분 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용구분").Trim());       //[10]
                    FileLog.PrintF("OPT10085 ReceivedData 대출일 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대출일").Trim());         //[11]
                    FileLog.PrintF("OPT10085 ReceivedData 결제잔고 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "결제잔고").Trim());       //[12]
                    FileLog.PrintF("OPT10085 ReceivedData 청산가능수량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "청산가능수량").Trim());   //[13]
                    FileLog.PrintF("OPT10085 ReceivedData 신용금액 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용금액").Trim());       //[14]
                    FileLog.PrintF("OPT10085 ReceivedData 신용이자 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용이자").Trim());       //[15]
                    FileLog.PrintF("OPT10085 ReceivedData 만기일 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "만기일").Trim());         //[16]



                    OPT10085_Data opt10085_Data = new OPT10085_Data();
                    opt10085_Data.구매일자 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim();                    //[0]
                    opt10085_Data.종목코드 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim();                  //[1]
                    opt10085_Data.종목명  = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목명").Trim();                   //[2]
                    int 현재가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim());                 //[3]
                    opt10085_Data.현재가 = 현재가;
                    opt10085_Data.매입가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입가").Trim());       //[4]
                    int 매입금액 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매입금액").Trim());               //[5]
                    opt10085_Data.매입금액 = 매입금액;
                    int 보유수량 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "보유수량").Trim());               //[6]
                    opt10085_Data.보유수량   = 보유수량;
                    opt10085_Data.당일매도손익 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매도손익").Trim()); //[7]
                    String str당일매매수수료 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매수수료");
                    opt10085_Data.당일매매수수료 = 0;
                    if (isNotNull(str당일매매수수료) == true)
                    {
                        opt10085_Data.당일매매수수료 = Int32.Parse(str당일매매수수료.Trim());                                                //[8]
                    }
                    opt10085_Data.당일매매세금 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매세금").Trim()); //[9]
                    opt10085_Data.신용구분   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용구분").Trim();                //[10]
                    opt10085_Data.대출일    = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대출일").Trim();                 //[11]
                    opt10085_Data.결제잔고   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "결제잔고").Trim());   //[12]
                    opt10085_Data.청산가능수량 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "청산가능수량").Trim()); //[13]
                    opt10085_Data.신용금액   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용금액").Trim());   //[14]
                    opt10085_Data.신용이자   = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용이자").Trim());   //[15]
                    opt10085_Data.만기일    = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "만기일").Trim();                 //[16]

                    /*내가 만들 데이터*/

                    /*매입가에는 수수료가 포함안되어있다. 매입당시 수수료가 통장에서 빠져나가지만 내가 얼마나 수익이 났는지 확인하기 위해
                     * 매입수수료와 매도 수수료를 합쳐서 수수료로 표시해준다.
                     * 수수료는 10원 미만 절삭 86원이면 80원임
                     */
                    //System.Math.Truncate()
                    int 평가금액    = Math.Abs(현재가) * 보유수량;
                    int 매입수수료   = Commission.GetKiwoomCommissionBuy(매입금액);
                    int 매도수수료   = Commission.GetKiwoomCommissionSell(평가금액);
                    int 수수료     = 매입수수료 + 매도수수료;
                    int 매도세금    = Commission.GetTaxSell(평가금액);
                    int 손익분기매입가 = 0;
                    if (보유수량 != 0)                                      //이게 0일경우가 있다 매도를 한상태일경우 보유수량이 0으로 리스트에 계속 존재한다.
                    {
                        손익분기매입가 = (매입수수료 + 매도수수료 + 매도세금 + 매입금액) / 보유수량; // 무조건오림
                    }
                    int 평가손익 = 평가금액 - (매입금액 + 수수료 + 매도세금);
                    // float 수익률 = (평가손익 / 매입금액) * 100;   //int끼리 나눠서... 소수점을 버리는구나.. 이런..
                    float 수익률 = 0;
                    if (매입금액 != 0)
                    {
                        수익률 = ((float)평가손익 / (float)매입금액) * 100;
                    }
                    int 손익금액 = (평가금액 - 매입금액);

                    float 손익율 = 0;
                    if (매입금액 != 0)
                    {
                        손익율 = ((float)손익금액 / (float)매입금액) * 100;
                    }



                    opt10085_Data.평가금액    = 평가금액;
                    opt10085_Data.매입수수료   = 매입수수료;
                    opt10085_Data.매도수수료   = 매도수수료;
                    opt10085_Data.수수료     = 수수료;
                    opt10085_Data.매도세금    = 매도세금;
                    opt10085_Data.손익분기매입가 = 손익분기매입가;
                    opt10085_Data.평가손익    = 평가손익;
                    opt10085_Data.수익률     = 수익률;
                    opt10085_Data.손익금액    = 손익금액;
                    opt10085_Data.손익율     = 손익율;
                    opt10085_Data.계좌번호    = 계좌번호;


                    FileLog.PrintF("OPT10085 ReceivedData 평가손익=>" + 평가손익);
                    FileLog.PrintF("OPT10085 ReceivedData 손익금액=>" + 손익금액);
                    FileLog.PrintF("OPT10085 ReceivedData 매입금액=>" + 매입금액);
                    FileLog.PrintF("OPT10085 ReceivedData 평가손익=>" + 평가손익);
                    FileLog.PrintF("OPT10085 ReceivedData 수익률=>" + 수익률);
                    FileLog.PrintF("OPT10085 ReceivedData 손익율=>" + 손익율);


                    //(8025-8089)/8089*100
                    //24005=23775+160+70
                    //24005-24575=-570
                    //24805
                    opt10085_DataList.Add(opt10085_Data);
                }
            }
            //axKHOpenAPI.DisconnectRealData(e.sScrNo); 계좌 수익률 정보는  실시간 데이터간 데이터로 들어온다면... 실시간으로 처리하는것이 이익이다..
            //화면번호도 고정이면 좋을것 같다...
            FileLog.PrintF("ReceivedData OPT10085 opt10085_DataList.Count()=>" + opt10085_DataList.Count());
            AppLib.getClass1Instance().removeStockCodeDictionary(keyStockCode);
            AppLib.getClass1Instance().removeSpellDictionary(key);
            MyStock.getClass1Instance().reLoad(opt10085_DataList); //보내는처리 무엇이든.
                                                                   //}
                                                                   //catch(Exception ex)
                                                                   //{
                                                                   //    FileLog.PrintF("[ALERT-ReceivedData-OPT10085]Exception ex=" + ex.Message);
                                                                   //}
        }
Exemplo n.º 19
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            try {
                /*
                 * sScrNo – 화면번호
                 * sRQName – 사용자구분 명
                 * sTrCode – Tran 명
                 * sRecordName – Record 명
                 * sPreNext – 연속조회 유무
                 */
                String 종목코드 = "XXXX";
                String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
                String keyStockCode       = String.Format(keyStockCodeLayout, e.sRQName, e.sTrCode, e.sScrNo);
                종목코드 = AppLib.getClass1Instance().getStockCode(keyStockCode);
                String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|stockCode:{3}";
                String key       = String.Format(keyLayout, e.sRQName, e.sTrCode, e.sScrNo, 종목코드);
                spell = AppLib.getClass1Instance().getSpell(key).ShallowCopy();
                TB_OPT10001 tmp = new TB_OPT10001();

                String 종목코드1 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "종목코드").Trim();
                if (종목코드1.Equals(""))
                {
                    종목코드1 = 종목코드;//일부 종목코드들은 아래 데이터가 아예 안나온다. ///51A077
                }
                tmp.stock_cd = 종목코드1;
                String 결산월 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "결산월").Trim();
                tmp.settlement_mm = 결산월;

                String str액면가 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "액면가").Trim();
                int    액면가    = 0;
                int.TryParse(str액면가.Trim(), out 액면가);
                tmp.face_amt = 액면가;

                String str자본금 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "자본금").Trim();
                int    자본금    = 0;
                int.TryParse(str자본금.Trim(), out 자본금);
                tmp.capital_amt = 자본금;

                String str상장주식 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "상장주식").Trim();
                int    상장주식    = 0;
                int.TryParse(str상장주식.Trim(), out 상장주식);
                tmp.stock_cnt = 상장주식;

                String str신용비율 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "신용비율").Trim();
                float  신용비율    = 0;
                float.TryParse(str신용비율.Trim(), out 신용비율);
                tmp.credit_rt = 신용비율;

                String str연중최고 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "연중최고").Trim();
                int    연중최고    = 0;
                int.TryParse(str연중최고.Trim(), out 연중최고);
                tmp.year_high_amt = 연중최고;

                String str연중최저 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "연중최저").Trim();
                int    연중최저    = 0;
                int.TryParse(str연중최저.Trim(), out 연중최저);
                tmp.year_low_amt = 연중최저;


                String str시가총액 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "시가총액").Trim();
                int    시가총액    = 0;
                int.TryParse(str시가총액.Trim(), out 시가총액);
                tmp.total_mrkt_amt = 시가총액;


                String str시가총액비중 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "시가총액비중").Trim();
                float  시가총액비중    = 0;
                float.TryParse(str시가총액비중.Trim(), out 시가총액비중);
                tmp.total_mrkt_amt_rt = 시가총액비중;

                String str외인소진률 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "외인소진률").Trim();
                float  외인소진률    = 0;
                float.TryParse(str외인소진률.Trim(), out 외인소진률);
                tmp.foreigner_exhaustion_rt = 외인소진률;

                String str대용가 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "대용가").Trim();
                int    대용가    = 0;
                int.TryParse(str대용가.Trim(), out 대용가);
                tmp.substitute_amt = 대용가;

                String strPER = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "PER").Trim();
                float  PER    = 0;
                float.TryParse(strPER.Trim(), out PER);
                tmp.per = PER;

                String strEPS = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "EPS").Trim();
                int    EPS    = 0;
                int.TryParse(strEPS.Trim(), out EPS);
                tmp.eps = EPS;

                String strROE = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "ROE").Trim();
                float  ROE    = 0;
                float.TryParse(strROE.Trim(), out ROE);
                tmp.roe = ROE;

                String strPBR = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "PBR").Trim();
                float  PBR    = 0;
                float.TryParse(strPBR.Trim(), out PBR);
                tmp.pbr = PBR;

                String strEV = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "EV").Trim();
                float  EV    = 0;
                float.TryParse(strEV.Trim(), out EV);
                tmp.ev = EV;

                String strBPS = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "BPS").Trim();
                int    BPS    = 0;
                int.TryParse(strBPS.Trim(), out BPS);
                tmp.bps = BPS;

                String str매출액 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매출액").Trim();
                int    매출액    = 0;
                int.TryParse(str매출액.Trim(), out 매출액);
                tmp.sales = 매출액;

                String str영업이익 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "영업이익").Trim();
                int    영업이익    = 0;
                int.TryParse(str영업이익.Trim(), out 영업이익);
                tmp.business_profits = 영업이익;

                String strD250최고 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "250최고").Trim();
                int    D250최고    = 0;
                int.TryParse(strD250최고.Trim(), out D250최고);
                tmp.d250_high_amt = D250최고;

                String strD250최저 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "250최저").Trim();
                int    D250최저    = 0;
                int.TryParse(strD250최저.Trim(), out D250최저);
                tmp.d250_low_amt = D250최저;

                int 시가  = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "시가").Trim());   //[23]
                int 고가  = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "고가").Trim());   //[24]
                int 저가  = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "저가").Trim());   //[25]
                int 상한가 = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "상한가").Trim());  //[26]
                int 하한가 = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "하한가").Trim());  //[27]
                int 기준가 = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "기준가").Trim());  //[28]
                tmp.start_amt     = 시가;
                tmp.high_amt      = 고가;
                tmp.low_amt       = 저가;
                tmp.upper_amt_lmt = 상한가;
                tmp.lower_amt_lmt = 하한가;
                tmp.yesterday_amt = 기준가;

                String str예상체결가 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "예상체결가").Trim();
                int    예상체결가    = 0;
                int.TryParse(str예상체결가.Trim(), out 예상체결가);
                tmp.expectation_contract_amt = 예상체결가;


                String str예상체결수량 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "예상체결수량").Trim();
                int    예상체결수량    = 0;
                int.TryParse(str예상체결수량.Trim(), out 예상체결수량);
                tmp.expectation_contract_qty = 예상체결수량;

                String D250최고가일 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "250최고가일").Trim();
                tmp.d250_high_dt = D250최고가일;

                float D250최고가대비율 = float.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "250최고가대비율").Trim());
                tmp.d250_high_rt = D250최고가대비율;


                String D250최저가일 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "250최저가일").Trim();
                tmp.d250_low_dt = D250최저가일;

                float D250최저가대비율 = float.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "250최저가대비율").Trim());
                tmp.d250_low_rt = D250최저가대비율;

                int 현재가 = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "현재가").Trim());
                tmp.curr_amt = 현재가;

                int 대비기호 = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "대비기호").Trim());
                tmp.contrast_symbol = 대비기호;

                int 전일대비 = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "전일대비").Trim());
                tmp.contrast_yesterday = 전일대비;

                float 등락율 = float.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "등락율").Trim());
                tmp.fluctuation_rt = 등락율;

                int 거래량 = int.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "거래량").Trim());
                tmp.trade_qty = 거래량;

                float 거래대비 = float.Parse(axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "거래대비").Trim());
                tmp.trade_contrast = 거래대비;

                tmp.face_amt_unit = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "액면가단위").Trim();

                String str유통주식 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "유통주식").Trim();         //[31]
                int    통주식     = 0;
                int.TryParse(str유통주식.Trim(), out 통주식);
                tmp.distribution_stock = 통주식;

                String str유통비율 = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "유통비율").Trim();         //[31]
                float  통비율     = 0;
                float.TryParse(str유통비율.Trim(), out 통비율);
                tmp.distribution_stock_rt = 통비율;

                //이것은 연속적이지 않기 때문에 바로 제거 한다.
                AppLib.getClass1Instance().removeSpellDictionary(spell.key);
                int    position = spell.key.LastIndexOf("|");
                String key1     = spell.key.Substring(0, position);
                AppLib.getClass1Instance().removeStockCodeDictionary(key1);
                //래치를 호출해서 잠김을 제거한다.--래치 일단 제거 호출하는데도 제거 했다. 1초에 5번 호출 규칙만 적용해보자.
                AppLib.getClass1Instance().setOpt10081(spell.sTrCode);

                DailyData dd = new DailyData();
                dd.insertOpt10001(tmp);
            }
            catch (Exception ex)
            {
                FileLog.PrintF("[ALERT-ReceivedData-OPT10001]Exception ex=" + ex.Message);
            }
        }
Exemplo n.º 20
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            /*
             * sScrNo – 화면번호
             * sRQName – 사용자구분 명
             * sTrCode – Tran 명
             * sRecordName – Record 명
             * sPreNext – 연속조회 유무
             */
            FileLog.PrintF("ReceivedData OPT10081");
            try
            {
                StringBuilder sbAll = new StringBuilder();
                StringBuilder sb    = new StringBuilder();
                //sb.Append("일자:{0}|종목코드:{1}|현재가:{2}|거래량:{3}|거래대금:{4}|시가:{5}|고가:{6}|저가:{7}");
                //sb.Append("stock_date:{0}|stock_code:{1}|current_price:{2}|trade_quantity:{3}|trade_price:{4}|start_price:{5}|high_price:{6}|low_price:{7}");
                sb.Append("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}");
                String tmp  = sb.ToString();
                String 종목코드 = "XXXX";
                int    nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);

                String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
                String keyStockCode       = String.Format(keyStockCodeLayout
                                                          , e.sRQName
                                                          , e.sTrCode
                                                          , e.sScrNo
                                                          );
                종목코드 = AppLib.getClass1Instance().getStockCode(keyStockCode);

                String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|stockCode:{3}";
                String key       = String.Format(keyLayout
                                                 , e.sRQName
                                                 , e.sTrCode
                                                 , e.sScrNo
                                                 , 종목코드
                                                 );

                FileLog.PrintF("keyStockCode1  ==" + keyStockCode);
                FileLog.PrintF("key1  ==" + key);

                spell = AppLib.getClass1Instance().getSpell(key).ShallowCopy();
                String startDate = spell.startDate;
                FileLog.PrintF("startDate  ==" + startDate);

                String lastStockDate = "";
                int    startDate일자   = 0;
                if (!int.TryParse(startDate, out startDate일자))
                {
                    startDate일자 = 0;
                }

                if (nCnt > 0)
                {
                    for (int i = 0; i < nCnt; i++)
                    {
                        /*
                         * if (i == 0) {
                         *  종목코드1 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim();
                         * }
                         */



                        String 종목코드1 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim();

                        if (종목코드1 == null || 종목코드1.Trim().Equals(""))
                        {
                            종목코드1 = 종목코드;
                        }
                        // FileLog.PrintF("거래대금  ==" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래대금").Trim());

                        int 현재가  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim());
                        int 거래량  = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래량").Trim());
                        int 거래대금 = 0;  //이게 INF 로 나올때가 있다.. 주식코드는 013900 두원중공업
                        if (!Int32.TryParse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "거래대금").Trim(), out 거래대금))
                        {
                            거래대금 = 0;
                        }
                        int 일자 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim());
                        int 시가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시가").Trim());
                        int 고가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "고가").Trim());
                        int 저가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "저가").Trim());
                        //              int 수정주가구분 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정주가구분").Trim());
                        //              int 수정비율 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정비율").Trim());
                        //              int 대업종구분 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대업종구분").Trim());
                        //              int 소업종구분 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "소업종구분").Trim());
                        //              int 종목정보 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목정보").Trim());
                        //              int 수정주가이벤트 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "수정주가이벤트").Trim());
                        //             int 전일종가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "전일종가").Trim());

                        String tmp1 = String.Format(tmp
                                                    , 일자
                                                    , 종목코드
                                                    , 현재가
                                                    , 거래량
                                                    , 거래대금
                                                    , 시가
                                                    , 고가
                                                    , 저가
                                                    );
                        lastStockDate = 일자.ToString();

                        if (startDate != null)
                        {
                            if (startDate.Equals("ZERO") || startDate.Equals("TWO"))
                            {
                                sbAll.AppendLine(tmp1);
                            }
                            else
                            {
                                if (일자 >= startDate일자)
                                {
                                    sbAll.AppendLine(tmp1);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            sbAll.AppendLine(tmp1);
                        }
                    }
                }
                else
                {
                    종목코드 = "00000";
                }

                int prevNext = 0;
                if (!int.TryParse(e.sPrevNext, out prevNext))
                {
                    prevNext = 0;
                }
                ScreenNumber.getClass1Instance().DisconnectRealData(e.sScrNo);
                ScreenNumber.getClass1Instance().SetRealRemove("ALL", "ALL");
                putReceivedQueueAndsetNextSpell(key, sbAll.ToString(), prevNext, lastStockDate);
            }
            catch (Exception ex)
            {
                FileLog.PrintF("[ALERT-ReceivedData-OPT10081]Exception ex=" + ex.Message);
            }
        }
Exemplo n.º 21
0
        public override void ReceivedData(AxKHOpenAPILib.AxKHOpenAPI axKHOpenAPI, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            FileLog.PrintF("ReceivedData OPT10075");
            //try {

            /*
             * sScrNo – 화면번호
             * sRQName – 사용자구분 명
             * sTrCode – Tran 명
             * sRecordName – Record 명
             * sPreNext – 연속조회 유무
             */
            String 계좌번호 = "XXXXXXXXXX";
            int    nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);
            String keyStockCodeLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}";
            String keyStockCode       = String.Format(keyStockCodeLayout
                                                      , e.sRQName
                                                      , e.sTrCode
                                                      , e.sScrNo
                                                      );

            계좌번호 = AppLib.getClass1Instance().getStockCode(keyStockCode);

            String keyLayout = "sRQName:{0}|sTrCode:{1}|sScreenNo:{2}|accountNum:{3}";
            String key       = String.Format(keyLayout
                                             , e.sRQName
                                             , e.sTrCode
                                             , e.sScrNo
                                             , 계좌번호
                                             );

            List <OPT10075_Data> OPT10075_DataList = new List <OPT10075_Data>();


            if (nCnt > 0)
            {
                for (int i = 0; i < nCnt; i++)
                {
                    FileLog.PrintF("OPT10075 ReceivedData 계좌번호 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "계좌번호").ToString().Trim());       //[0]
                    FileLog.PrintF("OPT10075 ReceivedData 주문번호 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문번호").ToString().Trim());       //[1]
                    FileLog.PrintF("OPT10075 ReceivedData 관리사번 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "관리사번").ToString().Trim());       //[2]
                    FileLog.PrintF("OPT10075 ReceivedData 종목코드 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").ToString().Trim());       //[3]
                    FileLog.PrintF("OPT10075 ReceivedData 업무구분 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "업무구분").ToString().Trim());       //[4]
                    FileLog.PrintF("OPT10075 ReceivedData 주문상태 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문상태").ToString().Trim());       //[5]
                    FileLog.PrintF("OPT10075 ReceivedData 종목명 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목명").ToString().Trim());         //[6]
                    FileLog.PrintF("OPT10075 ReceivedData 주문수량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문수량").ToString().Trim());       //[7]
                    FileLog.PrintF("OPT10075 ReceivedData 주문가격 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문가격").ToString().Trim());       //[8]
                    FileLog.PrintF("OPT10075 ReceivedData 미체결수량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "미체결수량").ToString().Trim());     //[9]
                    FileLog.PrintF("OPT10075 ReceivedData 체결누적금액 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결누적금액").ToString().Trim());   //[10]
                    FileLog.PrintF("OPT10075 ReceivedData 원주문번호 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "원주문번호").ToString().Trim());     //[11]
                    FileLog.PrintF("OPT10075 ReceivedData 주문구분 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문구분").ToString().Trim());       //[12]
                    FileLog.PrintF("OPT10075 ReceivedData 매매구분 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매매구분").ToString().Trim());       //[13]
                    FileLog.PrintF("OPT10075 ReceivedData 시간 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시간").ToString().Trim());           //[14]
                    FileLog.PrintF("OPT10075 ReceivedData 체결번호 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결번호").ToString().Trim());       //[15]
                    FileLog.PrintF("OPT10075 ReceivedData 체결가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결가").ToString().Trim());         //[16]
                    FileLog.PrintF("OPT10075 ReceivedData 체결량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결량").ToString().Trim());         //[17]
                    FileLog.PrintF("OPT10075 ReceivedData 현재가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").ToString().Trim());         //[18]
                    FileLog.PrintF("OPT10075 ReceivedData 매도호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도호가").ToString().Trim());       //[19]
                    FileLog.PrintF("OPT10075 ReceivedData 매수호가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수호가").ToString().Trim());       //[20]
                    FileLog.PrintF("OPT10075 ReceivedData 단위체결가 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "단위체결가").ToString().Trim());     //[21]
                    FileLog.PrintF("OPT10075 ReceivedData 단위체결량 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "단위체결량").ToString().Trim());     //[22]
                    FileLog.PrintF("OPT10075 ReceivedData 당일매매수수료 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매수수료").ToString().Trim()); //[23]
                    FileLog.PrintF("OPT10075 ReceivedData 단일매매세금 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "단일매매세금").ToString().Trim());   //[24]
                    FileLog.PrintF("OPT10075 ReceivedData 개인투자자 =>" + axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "개인투자자").ToString().Trim());     //[25]

                    OPT10075_Data opt10075_Data = new OPT10075_Data();

                    String 현재일자    = DateTime.Now.ToString("yyyy-MM-dd");
                    String 체결시간TMP = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "시간").ToString().Trim(); //[14]
                                                                                                                   //체결시간이 6자리이므로 HHMMSS ==> HH:MM:SS로 바꿔야한다.
                    String 체결시간 = 체결시간TMP.Substring(0, 2) + ":" + 체결시간TMP.Substring(2, 2) + ":" + 체결시간TMP.Substring(4, 2);
                    opt10075_Data.체결시간 = 현재일자 + " " + 체결시간;



                    opt10075_Data.계좌번호   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "계좌번호").ToString().Trim();              //[0]
                    opt10075_Data.주문번호   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문번호").ToString().Trim();              //[1]
                    opt10075_Data.관리사번   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "관리사번").ToString().Trim();              //[2]
                    opt10075_Data.종목코드   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").ToString().Trim();              //[3]
                    opt10075_Data.업무구분   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "업무구분").ToString().Trim();              //[4]
                    opt10075_Data.주문상태   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문상태").ToString().Trim();              //[5]
                    opt10075_Data.종목명    = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목명").ToString().Trim();               //[6]
                    opt10075_Data.주문수량   = int.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문수량").ToString().Trim());   //[7]
                    opt10075_Data.주문가격   = int.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문가격").ToString().Trim());   //[8]
                    opt10075_Data.미체결수량  = int.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "미체결수량").ToString().Trim());  //[9]
                    opt10075_Data.체결누계금액 = int.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결누계금액").ToString().Trim()); //[10]
                    opt10075_Data.원주문번호  = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "원주문번호").ToString().Trim();             //[11]
                    opt10075_Data.주문구분   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "주문구분").ToString().Trim();              //[12]
                    opt10075_Data.매매구분   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매매구분").ToString().Trim();              //[13]
                    opt10075_Data.체결번호   = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결번호").ToString().Trim();              //[15]
                    opt10075_Data.체결가    = int.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결가").ToString().Trim());    //[16]
                    opt10075_Data.체결량    = int.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "체결량").ToString().Trim());    //[17]
                    opt10075_Data.현재가    = int.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").ToString().Trim());    //[18]
                    String str매도호가 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매도호가").ToString().Trim();                    //[19]
                    opt10075_Data.매도호가 = 0;
                    if (!str매도호가.Equals(""))
                    {
                        opt10075_Data.매도호가 = int.Parse(str매도호가);
                    }
                    String str매수호가 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "매수호가").ToString().Trim(); //[20]
                    opt10075_Data.매수호가 = 0;
                    if (!str매수호가.Equals(""))
                    {
                        opt10075_Data.매수호가 = int.Parse(str매수호가);
                    }
                    String str단위체결가 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "단위체결가").ToString().Trim(); //[21]
                    opt10075_Data.단위체결가 = 0;
                    if (!str단위체결가.Equals(""))
                    {
                        opt10075_Data.단위체결가 = int.Parse(str단위체결가);
                    }
                    String str단위체결량 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "단위체결량").ToString().Trim(); //[22]
                    opt10075_Data.단위체결량 = 0;
                    if (!str단위체결량.Equals(""))
                    {
                        opt10075_Data.단위체결량 = int.Parse(str단위체결량);
                    }
                    String str당일매매수수료 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매수수료").ToString().Trim(); //[23]
                    opt10075_Data.당일매매수수료 = 0;
                    if (!str당일매매수수료.Equals(""))
                    {
                        opt10075_Data.당일매매수수료 = int.Parse(str당일매매수수료);
                    }
                    String str당일매매세금 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매세금").ToString().Trim(); //[24]
                    opt10075_Data.당일매매세금 = 0;
                    if (!str당일매매세금.Equals(""))
                    {
                        opt10075_Data.당일매매세금 = int.Parse(str당일매매세금);
                    }
                    opt10075_Data.개인투자자 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "개인투자자").ToString().Trim(); //[25]


                    //(8025-8089)/8089*100
                    //24005=23775+160+70
                    //24005-24575=-570
                    //24805
                    OPT10075_DataList.Add(opt10075_Data);
                }
            }


            //이것은 연속적이지 않기 때문에 바로 제거 한다.
            AppLib.getClass1Instance().removeSpellDictionary(spell.key);
            int    position = spell.key.LastIndexOf("|");
            String key1     = spell.key.Substring(0, position);

            AppLib.getClass1Instance().removeStockCodeDictionary(key1);
            //래치를 호출해서 잠김을 제거한다.--래치 일단 제거 호출하는데도 제거 했다. 1초에 5번 호출 규칙만 적용해보자.
            AppLib.getClass1Instance().setOpt10081(spell.sTrCode);

            //DailyData dd = new DailyData();
            //dd.insertOpt10001(tmp);
        }