Example #1
0
        private void kiwoomApi_OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
        {
            // 실시간 조건검색 요청으로 종목 편입 확인 (type - I : 종목편입, D : 종목이탈)
            if (e.strType.Equals("I"))
            {
                Console.WriteLine("조건검색 실시간 편입 [" + e.sTrCode + "]");

                ConditionStock conditionStock = conditionStocks.SingleOrDefault(item => item.StockNo.Equals(e.sTrCode));

                if (conditionStock != null)
                {
                    conditionStock.Status = "편입";
                    conditionStock.upTransferCnt();
                }
                else
                {
                    conditionStocks.Add(new ConditionStock(e.sTrCode, kiwoomApi.GetMasterCodeName(e.sTrCode)));
                    requestRealtimeQuote(SCREEN_NO_CONDITION, e.sTrCode, conditionStocks.Count > 0 ? REALTIME_ADD : REALTIME_NEW);
                }

                // 실시간으로 여러 종목을 가져올 경우는 없는가? 확인이 필요할듯..
            }
            else if (e.strType.Equals("D"))
            {
                Console.WriteLine("조건검색 실시간 이탈 [" + e.sTrCode + "]");

                ConditionStock conditionStock = conditionStocks.SingleOrDefault(item => item.StockNo.Equals(e.sTrCode));

                if (conditionStock != null)
                {
                    conditionStock.Status = "이탈";
                    //removeRealtimeQuote(SCREEN_NO_CONDITION, e.sTrCode);
                }
            }
        }
Example #2
0
        private void OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
        {
            string code            = e.sTrCode.Trim();
            string condition_name  = e.strConditionName;
            string condition_index = e.strConditionIndex;

            if (e.strType == "I") // 조건검색 편입
            {
                int flag = 0;
                realTimeAccountOfflabel.Checked = true;
                Delay(700);
                itemInsertListBox.Items.Insert(0, "[" + condition_index + ":" + condition_name + "]" + " " + code);

                for (int i = 0; i < realTimeFundList.Count; i++)
                {
                    if (code.Trim() == (realTimeFundList[i].종목코드).Trim())
                    {
                        flag = 1;
                    }
                }
                for (int i = 0; i < realTimeAccountGridView.Rows.Count; i++)
                {
                    string checkCode = (realTimeAccountGridView.Rows[i].Cells[0].Value.ToString()).Trim();
                    if (code.Trim() == checkCode.Substring(1))
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)
                {
                    real_cnt++;
                    if (real_cnt >= 4)
                    {
                        Delay(1000);
                        real_cnt = 0;
                    }
                    axKHOpenAPI1.SetInputValue("종목코드", code);
                    Console.WriteLine(axKHOpenAPI1.CommRqData("주식기본정보요청", "opt10001", 0, GetScrNum()));
                    Console.WriteLine("요청성공");


                    autoTimer.Interval = 5000;
                    autoTimer.Elapsed += new ElapsedEventHandler(errorReset);
                    autoTimer.Start();
                }
                else
                {
                    Console.WriteLine("이미존재해서 리턴");
                    realTimeAccountOnlabel.Checked = true;
                    Delay(500);
                    return;
                }
            }
            if (e.strType == "D")   //조건검색 이탈
            {
                itemDeleteListBox.Items.Insert(0, "[" + condition_index + ":" + condition_name + "]" + " " + code);
            }
        }
Example #3
0
 public void axKHOpenAPI_OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent apiEvent)
 {
     try {
         Logger.getInstance.print(Log.StockAPI콜백, "========= 조건조회 실시간 편입/이탈 ==========");
         Logger.getInstance.print(Log.StockAPI콜백, "[종목코드] : " + apiEvent.sTrCode);
         Logger.getInstance.print(Log.StockAPI콜백, "[실시간타입] : " + apiEvent.strType);
         Logger.getInstance.print(Log.StockAPI콜백, "[조건명] : " + apiEvent.strConditionName);
         Logger.getInstance.print(Log.StockAPI콜백, "[조건명 인덱스] : " + apiEvent.strConditionIndex);
     }
     catch (AccessViolationException execption) {
         Logger.getInstance.print(Log.에러, "[실시간 조건 조회 콜백 에러] {0}\n{1}\n{2}", execption.Message, execption.StackTrace, execption.InnerException);
     }
     this.runNextOrderFlag();
 }
Example #4
0
 public void onReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
 {
     if (e.strType == "I")
     {
         string stockName = axKHOpenAPI1.GetMasterCodeName(e.sTrCode);
         insertListBox.Items.Add("종목편입| 조건인덱스 : " + e.strConditionIndex + " | 종목코드 : " + e.sTrCode + " | " + "종목명 : " + stockName);
         currentCondition = e.strConditionIndex + ":" + e.strConditionName;
         axKHOpenAPI1.SetInputValue("종목코드", e.sTrCode);
         axKHOpenAPI1.CommRqData("자동거래2차매수", "opt10001", 0, "5152");
     }
     else if (e.strType == "D")
     {
         string stockName = axKHOpenAPI1.GetMasterCodeName(e.sTrCode);
         deleteListBox.Items.Add("종목이탈| 조건인덱스 : " + e.strConditionIndex + " | 종목코드 : " + e.sTrCode + " | " + "종목명 : " + stockName);
     }
 }
Example #5
0
        private void axKHOpenAPI_OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
        {
            Logger(Log.실시간, "========= 조건조회 실시간 편입/이탈 ==========");
            Logger(Log.실시간, "[종목코드] : " + e.sTrCode);
            Logger(Log.실시간, "[실시간타입] : " + e.strType);
            Logger(Log.실시간, "[조건명] : " + e.strConditionName);
            Logger(Log.실시간, "[조건명 인덱스] : " + e.strConditionIndex);

            // 자동주문 로직
            if (_bRealTrade && e.strType == "I")
            {
                // 해당 종목 1주 시장가 주문
                // =================================================

                // 계좌번호 입력 여부 확인
                if (cbo계좌.Text.Length != 10)
                {
                    Logger(Log.에러, "계좌번호 10자리를 입력해 주세요");

                    return;
                }

                // =================================================
                // 주식주문
                int lRet;

                lRet = axKHOpenAPI.SendOrder("주식주문",
                                             GetScrNum(),
                                             cbo계좌.Text.Trim(),
                                             1,                // 매매구분
                                             e.sTrCode.Trim(), // 종목코드
                                             1,                // 주문수량
                                             1,                // 주문가격
                                             "03",             // 거래구분 (시장가)
                                             "0");             // 원주문 번호

                if (lRet == 0)
                {
                    Logger(Log.일반, "주문이 전송 되었습니다");
                }
                else
                {
                    Logger(Log.에러, "주문이 전송 실패 하였습니다. [에러] : " + lRet);
                }
            }
        }
Example #6
0
        void OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
        {
            try
            {
                string 종목코드  = e.sTrCode;
                string 조건식번호 = e.strConditionIndex;
                string 조건명   = e.strConditionName;

                ConditionObject conditionObject = conditionObjectList.Find(o => o.조건식번호 == int.Parse(조건식번호));

                if (conditionObject != null)
                {
                    if (e.strType == "I") // 종목 편입
                    {
                        insertListBox.Items.Add("편입 => 코드:" + 종목코드 + " |번호: " + 조건식번호 + " |조건명: " + 조건명);

                        axKHOpenAPI1.SetInputValue("종목코드", 종목코드);
                        axKHOpenAPI1.CommRqData("편입종목정보요청;" + 조건식번호, "opt10001", 0, "5005"); // OnReceiveTrData 로 전달됨
                    }
                    else if (e.strType == "D")                                               // 종목 이탈
                    {
                        deleteListBox.Items.Add("이탈 => 코드: " + 종목코드 + " |번호: " + 조건식번호 + " |조건명: " + 조건명);
                        ItemObject itemObject = conditionObject.itemObjectList.Find(o => o.종목코드 == 종목코드);

                        if (itemObject != null)
                        {
                            conditionObject.itemObjectList.Remove(itemObject);           // 객체에서 제거
                            for (int i = 0; i < conditionItemDataGridView.RowCount; i++) // UI에서 제거
                            {
                                if ((string)conditionItemDataGridView["종목코드", i].Value == 종목코드)
                                {
                                    conditionItemDataGridView.Rows.RemoveAt(i);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Console.WriteLine("OnReceiveRealCondition 메소드 Exception:");
                Console.WriteLine(error.ToString());
            }
        }
Example #7
0
        private void axKHOpenAPI_OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
        {
            String 종목코드   = e.sTrCode;
            String 조건식이름  = e.strConditionName;
            String 조건명인덱스 = e.strConditionIndex;

            if (e.strType.Equals("I"))  //종목편입
            {
                itemInsertListBox.Items.Insert(0, "[" + 조건명인덱스 + "." + 조건식이름 + "] : " + 종목코드);

                axKHOpenAPI1.SetInputValue("종목코드", 종목코드);
                axKHOpenAPI1.CommRqData("주식기본정보요청;" + 조건명인덱스, "opt10001", 0, GetScrNum());
            }
            else if (e.strType.Equals("D")) //종목이탈
            {
                itemDeleteListBox.Items.Insert(0, "[" + 조건명인덱스 + "." + 조건식이름 + "] : " + 종목코드);
            }
            Console.WriteLine(e.strConditionIndex + " 종목명:" + e.sTrCode + " -" + e.strType);
        }
Example #8
0
        // =================================================<<조건조회 실시간 편입/이탈 정보 업데이트>>========================================//
        // 조건조회 실시간 편입/이탈 정보 업데이트하여 데이터그리드뷰에 갱신하기

        private void axKHOpenAPI_OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
        {
            string strCodeName = axKHOpenAPI.GetMasterCodeName(e.sTrCode); // 종목명을 가져온다.

            if (e.strType == "I") { //종목편입
                UpdateDataGridViewData(실시간검색뷰, "종목코드", e.sTrCode, "종목코드", e.sTrCode, DATATYPE.STR);
                UpdateDataGridViewData(실시간검색뷰, "종목코드", e.sTrCode, "상태", "편입", DATATYPE.STR);
                UpdateDataGridViewData(실시간검색뷰, "종목코드", e.sTrCode, "종목명", strCodeName, DATATYPE.STR);
                UpdateDataGridViewData(실시간검색뷰, "종목코드", e.sTrCode, "매수조건식", e.strConditionIndex + "^" + e.strConditionName, DATATYPE.STR);
                logger.Write(LOGTYPE.C, string.Format("[{0}][{1}][{2} {3}", "편입", e.strConditionName, e.sTrCode, strCodeName));

                axKHOpenAPI.CommKwRqData(e.sTrCode, 0, 1, 0, "관심종목정보요청", GetScrNum());
                axKHOpenAPI.SetRealReg(_strRealConScrNum, e.sTrCode, "9001;302;10;11;12;13;25", "1");// 실시간 시세등록
            } else if (e.strType == "D") { //종목이탈
                logger.Write(LOGTYPE.C, string.Format("[{0}][{1}][{2} {3}", "이탈", e.strConditionName, e.sTrCode, strCodeName));
                axKHOpenAPI.SetRealRemove(_strRealConScrNum, e.sTrCode);// 실시간 시세해지
                
                UpdateDataGridViewData(실시간검색뷰, "종목코드", e.sTrCode, "상태", "이탈", DATATYPE.STR);
            }
        }
Example #9
0
        private void API_OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
        {
            string conditionIndex = e.strConditionIndex;
            string conditionName  = e.strConditionName;

            realConditionListBox.Items.Add("조건식 명 : " + conditionName + " 조건식 인덱스 : " + conditionIndex);

            string itemCode = e.sTrCode; //편입 또는 이탈 종목 코드
            string type     = e.strType; //편입 (I) 이탈 (D)

            if (type.Equals("I"))
            {
                realConditionListBox.Items.Add("종목편입 : " + axKHOpenAPI1.GetMasterCodeName(itemCode) + " " + itemCode);
                //axKHOpenAPI1.SetRealReg(GetScreenNum(), itemCode, , );
            }
            else if (type.Equals("D"))
            {
                realConditionListBox.Items.Add("종목이탈 : " + axKHOpenAPI1.GetMasterCodeName(itemCode) + " " + itemCode);
                //axKHOpenAPI1.SetRealRemove(GetScreenNum(), itemCode, , );
            }
        }
Example #10
0
 private void kiwoomApi_OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
 {
 }
Example #11
0
 private void M_axKHOpenAPI_OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
 {
     throw new NotImplementedException();
 }
Example #12
0
 private static void AxKH_OnReceiveRealCondition(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealConditionEvent e)
 {
 }