Esempio n. 1
0
        //손절 테스트
        private Boolean executeTest(DataRow itemRow)
        {
            String shcode;                           //종목코드
            String hname;                            //종목명
            String close;                            //현재가
            String searchNm;                         //검색조건
            String searchCode;                       //검색코드

            shcode     = itemRow["종목코드"].ToString(); //종목코드
            hname      = itemRow["종목명"].ToString();  //종목명
            close      = itemRow["현재가"].ToString();  //현재가
            searchNm   = itemRow["검색조건"].ToString(); //검색조건
            searchCode = itemRow["검색코드"].ToString(); //검색코드


            //글로벌 매도가능 설정값 체크
            if (!mainForm.cbx_sell_at.Checked)
            {
                return(false);
            }


            int t0424VoListFindIndex = mainForm.xing_t0424.getT0424VoList().Find("expcode", shcode);//보유종목인지 체크

            if (t0424VoListFindIndex >= 0)
            {
                T0424Vo t0424Vo = mainForm.xing_t0424.getT0424VoList().ElementAt(t0424VoListFindIndex);

                //이미 주문이 실행된 상태
                if (t0424Vo.orderAt == "Y")
                {
                    return(false);
                }

                //주문 전송
                Double 평균단가  = t0424Vo.pamt;  //매도주문일경우 매수금액을 알기위해 넣어준다.
                String 종목코드  = t0424Vo.expcode;
                String 종목명   = t0424Vo.hname;
                Double 현재가   = t0424Vo.price;
                String 매도전략명 = t0424Vo.searchNm;
                Double 수량    = t0424Vo.mdposqt;
                Double 수익율   = t0424Vo.sunikrt;
                //String 상세매매구분 = "매도검색 매도";

                //매도주문
                t0424Vo.orderAt = "Y";
                Xing_CSPAT00600 xing_CSPAT00600 = mainForm.CSPAT00600Mng.get600();
                xing_CSPAT00600.call_request(종목명, 종목코드, "매도", 수량, 현재가, 매도전략명, 평균단가, "손절검색");

                mainForm.log("<t1857Stop:" + 매도전략명 + "><" + 종목명 + ">" + 수익율 + "% " + 수량 + "주 " + 현재가 + "원");
            }

            return(true);
        }//buyTest END
Esempio n. 2
0
        //선택 매도
        private void btn_checkSell_Click(object sender, EventArgs e)
        {
            Double 평균단가; //매도주문일경우 매수금액을 알기위해 넣어준다.
            String 종목코드;
            String 종목명;
            Double 현재가;
            String 매수전략명;
            Double 수량;
            Double 수익율;
            //String 상세매매구분 = null;
            //String 매매구분 = null;
            String 매도주문여부; //매도주문여부

            //EBindingList<T0424Vo> t0424VoList = ((EBindingList<T0424Vo>)this.grd_t0424.DataSource);
            for (int i = 0; i < grd_t0424.RowCount; i++)
            {
                if (this.grd_t0424.Rows[i].Cells["grd_t0424_check"].FormattedValue.ToString() == "True")
                {
                    T0424Vo t0424Vo = (T0424Vo)this.grd_t0424.Rows[i].DataBoundItem;
                    평균단가   = t0424Vo.pamt;  //매도주문일경우 매수금액을 알기위해 넣어준다.
                    종목코드   = t0424Vo.expcode;
                    종목명    = t0424Vo.hname;
                    현재가    = t0424Vo.price;
                    매수전략명  = t0424Vo.searchNm;
                    수량     = t0424Vo.mdposqt;
                    매도주문여부 = t0424Vo.orderAt;
                    수익율    = t0424Vo.sunikrt;

                    if (매도주문여부 == "N")
                    {
                        Xing_CSPAT00600 xing_CSPAT00600 = this.CSPAT00600Mng.get600();
                        xing_CSPAT00600.call_request(종목명, 종목코드, "매도", 수량, 현재가, 매수전략명, 평균단가, "선택매도");
                        t0424Vo.orderAt = "Y";    //일괄 매도시 주문여부를 true로 설정

                        this.log("<main:선택매도> " + 종목명 + " " + 수익율 + "% " + 수량 + "주 " + 현재가 + "원<" + 매수전략명 + ">");
                    }
                    else
                    {
                        //이미 매도주문 실행 종목
                        MessageBox.Show(종목명 + "이미 매도주문이 이루어 졌습니다.");
                    }
                    //선택체크해제
                    this.grd_t0424.Rows[i].Cells["grd_t0424_check"].Value = false;
                }
            }
        }//btn_checkSell_Click END
Esempio n. 3
0
        }// end function

        public Xing_CSPAT00600 get600()
        {
            Log.WriteLine("Xing_CSPAT00600 카운트::" + this.xing_CSPAT00600List.Count());
            for (int i = 0; i < this.xing_CSPAT00600List.Count(); i++)
            {
                if (this.xing_CSPAT00600List.ElementAt(i).completeAt)
                {
                    this.xing_CSPAT00600List.ElementAt(i).completeAt = false;
                    return(this.xing_CSPAT00600List.ElementAt(i));
                }
            }
            Xing_CSPAT00600 item600 = new Xing_CSPAT00600(mainForm);

            item600.completeAt = false;
            this.xing_CSPAT00600List.Add(item600);
            return(item600);
        }
Esempio n. 4
0
        }//fn END

        //목표 수익율 도달 Test 후 도달여부에 따라 매도 호출
        public Boolean tradingStopTest(T0424Vo t0424Vo, int index, Double 목표수익율)
        {
            //try{
            Double 수익율    = t0424Vo.sunikrt;
            Double 현재가격   = t0424Vo.price;
            String 감시제외여부 = t0424Vo.exclWatchAt;                        //감시제외여부

            //종목 에러 있으면 매매 하지 않는다.
            if (t0424Vo.errorcd != "" && t0424Vo.errorcd != null)
            {
                return(false);
            }

            //이미 주문이 실행된 상태
            if (t0424Vo.orderAt == "Y")
            {
                return(false);
            }

            if (감시제외여부 == "Y")
            {
                mainForm.grd_t0424.Rows[index].DefaultCellStyle.BackColor = Color.Gray;
                return(false);
            }

            Double 평균단가   = t0424Vo.pamt;       //매도주문일경우 매수금액을 알기위해 넣어준다.
            String 종목코드   = t0424Vo.expcode;
            String 종목명    = t0424Vo.hname;
            Double 현재가    = t0424Vo.price;
            String 매수전량명  = t0424Vo.searchNm;
            Double 수량     = t0424Vo.mdposqt;
            String 상세매매구분 = null;
            String 매매구분   = null;

            //매도--------------------------------------------------------------------------------
            if (mainForm.cbx_sell_at.Checked)
            {
                if (Util.isSellTime())
                {
                    //손절
                    Boolean 손절기능여부 = Properties.Settings.Default.STOP_LOSS_AT;
                    if (손절기능여부)
                    {
                        Double 손절율 = Properties.Settings.Default.STOP_LOSS_RATE;
                        if (수익율 <= 손절율)
                        {
                            매매구분   = "매도";
                            상세매매구분 = "손절";
                        }
                    }
                    if (종목코드 == "005070")
                    {
                        String tessst = "3";
                    }

                    //목표수익 달성후 지정 비율 하락이상 반전시 매도
                    Double 추적청산율 = Double.Parse(t0424Vo.maxRt) + Double.Parse(Properties.Settings.Default.STOP_TARGET_DOWN_RATE);
                    if (Double.Parse(Properties.Settings.Default.STOP_TARGET_DOWN_RATE) < 0)
                    {                                                             //설정값이 0이면 사용하지 않는다.
                        if (Double.Parse(t0424Vo.maxRt) >= 목표수익율 && 수익율 <= 추적청산율) //최대도달 수익율
                        {
                            매매구분   = "매도";
                            상세매매구분 = "추적청산";
                        }
                    }
                    else
                    {
                        //목표수익 달성시...
                        if (수익율 >= 목표수익율)
                        {
                            //ordptnDetail(상세주문구분-신규매수|반복매수|금일매도|청산)
                            //upOrdno(상위매수주문번호-금일매도일때만 셋팅될것같다)
                            //upExecprc">상위체결금액-없으면 평균단가 넣어주자</param>
                            //IsuNo(종목코드) Quantity(수량) Price(가격)
                            //2틀연속 DataLog 의 매수단가가 잘못 들어가는것들이 있어서 원인을 찾기전에 수익율 < 수익율 2 인경우 주문을 제한하자.메세지창으로 관리하자.
                            //청산일때만 체크
                            if (t0424Vo.sunikrt < 1)
                            {
                                Log.WriteLine("<ERROR-수익청산><t0424-496:" + t0424Vo.hname + "><" + 수익율.ToString() + ">");
                                t0424Vo.errorcd = "sunikrt error";
                                return(false);
                            }

                            매매구분   = "매도";
                            상세매매구분 = "수익청산";
                        }
                    }
                }
                // 일괄매도 - 매도시간 설정값 영향 없이 단독 실행
                if (Properties.Settings.Default.ALL_SELL_AT)
                {
                    TimeSpan nowTimeSpan     = TimeSpan.Parse(mainForm.xing_t0167.hour + ":" + mainForm.xing_t0167.minute + ":" + mainForm.xing_t0167.second);
                    DateTime allSellTimeFrom = Properties.Settings.Default.ALL_SELL_TIME_FROM;
                    DateTime allSellTimeTo   = Properties.Settings.Default.ALL_SELL_TIME_TO;
                    목표수익율 = Double.Parse(Properties.Settings.Default.ALL_SELL_RATE);
                    if (nowTimeSpan >= allSellTimeFrom.TimeOfDay && nowTimeSpan <= allSellTimeTo.TimeOfDay)
                    {
                        if (Properties.Settings.Default.ALL_SELL_RATE_SE.Equals("이상"))
                        {
                            if (수익율 >= 목표수익율)
                            {
                                매매구분   = "매도";
                                상세매매구분 = "일괄매도";
                            }
                        }
                        if (Properties.Settings.Default.ALL_SELL_RATE_SE.Equals("이하"))
                        {
                            if (수익율 < 목표수익율)
                            {
                                매매구분   = "매도";
                                상세매매구분 = "일괄매도";
                            }
                        }
                    }
                }


                String 지정시간초과수익율 = Properties.Settings.Default.SELL_TARGET_TIME_OVR_RATE;
                if (Properties.Settings.Default.SELL_TARGET_TIME_AT && 수익율 < Double.Parse(지정시간초과수익율))
                {
                    Boolean targetTimeFlag = false;
                    String  minute         = mainForm.xing_t0167.minute;
                    if (Properties.Settings.Default.SELL_TARGET_TIME_10)
                    {
                        if (minute == "11")
                        {
                            targetTimeFlag = true;
                        }
                    }
                    if (Properties.Settings.Default.SELL_TARGET_TIME_20)
                    {
                        if (minute == "21")
                        {
                            targetTimeFlag = true;
                        }
                    }
                    if (Properties.Settings.Default.SELL_TARGET_TIME_30)
                    {
                        if (minute == "31")
                        {
                            targetTimeFlag = true;
                        }
                    }
                    if (Properties.Settings.Default.SELL_TARGET_TIME_40)
                    {
                        if (minute == "41")
                        {
                            targetTimeFlag = true;
                        }
                    }
                    if (Properties.Settings.Default.SELL_TARGET_TIME_50)
                    {
                        if (minute == "51")
                        {
                            targetTimeFlag = true;
                        }
                    }
                    if (Properties.Settings.Default.SELL_TARGET_TIME_00)
                    {
                        if (minute == "01")
                        {
                            targetTimeFlag = true;
                        }
                    }
                    if (!targetTimeFlag)
                    {
                        return(false);
                    }
                }
            }    //mainForm.cbx_sell_at.Checked end

            //추가 매수--------------------------------------------------------------------------------
            if (mainForm.cbx_buy_at.Checked)
            {
                if (Util.isBuyTime())
                {
                    //지정 하락 비율 이하이면 추가매수 1번만.
                    if (Properties.Settings.Default.ADD_BUY_AT)
                    {
                        if (int.Parse(t0424Vo.buyCnt) < 2 && 수익율 < Double.Parse(Properties.Settings.Default.ADD_BUY_RATE))
                        {
                            매매구분   = "매수";
                            상세매매구분 = "추가매수(1회)";
                        }
                    }
                }
            }

            //주문.
            if (매매구분 != null)
            {
                t0424Vo.orderAt = "Y";

                Xing_CSPAT00600 xing_CSPAT00600 = mainForm.CSPAT00600Mng.get600();
                xing_CSPAT00600.call_request(종목명, 종목코드, 매매구분, 수량, 현재가, 매수전량명, 평균단가, 상세매매구분);
                //청산 주문여부를 true로 설정


                mainForm.log("<t0424:" + 상세매매구분 + "> " + 종목명 + " " + 수익율 + "% " + 수량 + "주 " + 현재가 + "원<" + 매수전량명 + ">");
            }

            // }
            //catch (Exception ex){
            //    Log.WriteLine("t0424 : " + ex.Message);
            //    Log.WriteLine("t0424 : " + ex.StackTrace);
            //}
            return(false);
        }//stopProFitTarget end
Esempio n. 5
0
        //매도 테스트
        private Boolean executeTest(DataRow itemRow, int configSearchCode)
        {
            String shcode;                           //종목코드
            String hname;                            //종목명
            String close;                            //현재가
            String searchNm;                         //검색조건
            String searchCode;                       //검색코드

            shcode     = itemRow["종목코드"].ToString(); //종목코드
            hname      = itemRow["종목명"].ToString();  //종목명
            close      = itemRow["현재가"].ToString();  //현재가
            searchNm   = itemRow["검색조건"].ToString(); //검색조건
            searchCode = itemRow["검색코드"].ToString(); //검색코드

            //검색코드 설정값 비교
            if (int.Parse(searchCode) < configSearchCode)
            {
                return(false);
            }

            if (!mainForm.cbx_sell_at.Checked)
            {
                //itemRow["상태"] = "매도정지 상태";
                return(false);
            }

            //
            int t0424VoListFindIndex = mainForm.xing_t0424.getT0424VoList().Find("expcode", shcode);//보유종목인지 체크

            if (t0424VoListFindIndex >= 0)
            {
                T0424Vo t0424Vo = mainForm.xing_t0424.getT0424VoList().ElementAt(t0424VoListFindIndex);

                //이미 주문이 실행된 상태
                if (t0424Vo.orderAt == "Y")
                {
                    return(false);
                }

                //주문 전송
                Double 평균단가  = t0424Vo.pamt;    //매도주문일경우 매수금액을 알기위해 넣어준다.
                String 종목코드  = t0424Vo.expcode;
                String 종목명   = t0424Vo.hname;
                Double 현재가   = t0424Vo.price;
                String 매도전략명 = t0424Vo.searchNm;
                Double 수량    = t0424Vo.mdposqt;
                Double 수익율   = t0424Vo.sunikrt;
                //String 상세매매구분 = "매도검색 매도";

                //+수익일때만 매도
                if (Properties.Settings.Default.SELL_PLUS_ONLY_AT)
                {
                    if (수익율 < 1)
                    {
                        return(false);
                    }
                }

                //매도주문
                t0424Vo.orderAt = "Y";
                Xing_CSPAT00600 xing_CSPAT00600 = mainForm.CSPAT00600Mng.get600();
                xing_CSPAT00600.call_request(종목명, 종목코드, "매도", 수량, 현재가, 매도전략명, 평균단가, "매도검색 매도");


                mainForm.log("<t1857Sell:" + 매도전략명 + "><" + 종목명 + ">" + 수익율 + "% " + 수량 + "주 " + 현재가 + "원");
            }

            return(true);
        }//buyTest END
Esempio n. 6
0
        //매수 테스트
        private Boolean executeTest(DataRow itemRow, int configSearchCode, TimeSpan nowTimeSpan, int rowIndex, Boolean kosBuyAt, Boolean kodBuyAt)
        {
            try
            {
                String shcode     = itemRow["종목코드"].ToString(); //종목코드
                String hname      = itemRow["종목명"].ToString();  //종목명
                String close      = itemRow["현재가"].ToString();  //현재가
                String searchNm   = itemRow["검색조건"].ToString(); //검색조건
                String searchCode = itemRow["검색코드"].ToString(); //검색코드
                String gubun      = itemRow["시장구분"].ToString(); //시장구분(1:코스피 2:코드닥)


                //시장구분 코스피
                if (gubun.Equals("1"))
                {
                    //코스피 체크
                    if (!kosBuyAt)
                    {
                        itemRow["상태"] = "코스피x";
                        return(false);
                    }
                }
                else if (gubun.Equals("2"))
                {
                    //코스닥 체크
                    if (!kodBuyAt)
                    {
                        itemRow["상태"] = "코스닥x";
                        return(false);
                    }
                }
                else
                {
                    itemRow["상태"] = "시장구분x";
                    return(false);
                }
                //검색코드 설정값 비교
                if (int.Parse(searchCode) < configSearchCode)
                {
                    itemRow["상태"] = "조건식매수 금지 ";
                    return(false);
                }

                //배팅금액 설정
                //int battingAtm = int.Parse(Properties.Settings.Default.BUY_BATTING_AMT) * 10000;

                //매수금지목록
                if (Properties.Settings.Default.STOP_STOP_BUYOFF_AT)
                {
                    DataTable stopSearchListDt = mainForm.xing_t1857Stop.getSearchListDt();
                    DataRow[] SellListDtRow    = null;
                    SellListDtRow = stopSearchListDt.Select("종목코드 Like '" + shcode + "'");
                    if (SellListDtRow.Count() > 0)
                    {
                        //mainForm.grd_t0424.Rows[t0424VoListFindIndex].Cells["c_expcode"].Style.BackColor = Color.Red;
                        mainForm.grd_t1833_dt.Rows[rowIndex].Cells["종목명"].Style.BackColor = Color.Red;
                        itemRow["상태"] = "매수제외";
                        return(false);
                    }
                }



                String ordptnDetail; //매수 상세 구분을 해준다. 신규매수|반복매수
                                     //금일 매수 체결 내용이 있고 미체결 잔량이 0인 건은 매수 하지 않는다.
                var toDayBuyT0425VoList = from item in mainForm.xing_t0425.getT0425VoList()
                                          where item.expcode == shcode && item.medosu == "매수"
                                          select item;
                if (toDayBuyT0425VoList.Count() > 0)
                {
                    itemRow["상태"] = "금일매수종목X";
                    return(false);
                }

                var toDaySellT0425VoList = from item in mainForm.xing_t0425.getT0425VoList()
                                           where item.expcode == shcode && item.medosu == "매도"
                                           select item;

                if (toDaySellT0425VoList.Count() > 0)
                {
                    if (!Properties.Settings.Default.SELL_TO_RE_BUY_AT)
                    {
                        itemRow["상태"] = "금일매도종목X";
                        return(false);
                    }
                }

                //5.보유종목 반복매수여부 테스트 -두번째 컨디션일 경우 보유종목일경우에만 중복 매수한다.
                int t0424VoListFindIndex = mainForm.xing_t0424.getT0424VoList().Find("expcode", shcode);//보유종목인지 체크

                if (t0424VoListFindIndex >= 0)
                {
                    //검색종목 추가매수 여부 옵션 체크
                    if (!Properties.Settings.Default.ADD_BUY_SIGNAL_AT)
                    {
                        itemRow["상태"] = "신호추가매수X";
                        return(false);
                    }

                    //기존 종목 수익률
                    EBindingList <T0424Vo> t0424VoList = mainForm.xing_t0424.getT0424VoList();
                    Double sunikrt = t0424VoList.ElementAt(t0424VoListFindIndex).sunikrt;

                    //추가매수 하락율 체크
                    if (sunikrt > double.Parse(Properties.Settings.Default.ADD_BUY_SIGNAL_RATE))
                    {
                        itemRow["상태"] = "하락율 미달x";
                        return(false);
                    }

                    ordptnDetail = "신호추가매수";
                    ////배팅금액 설정
                    //battingAtm = int.Parse(Properties.Settings.Default.ADD_BUY_AMT) * 10000;
                    //1.반복매수면 투자율 제한 하지 않는다.
                    //2.반복매수면 매수금지 종목이라도 매수한다.
                }
                else    //-보유종목이 아니고 신규매수해야 한다면.

                //자본금대비 투자 비율이 높으면 신규매수 하지 않는다.
                {
                    Double 투자율 = Double.Parse(mainForm.tradingInfoDt.Rows[0]["투자율"].ToString());
                    if (투자율 >= Double.Parse(Properties.Settings.Default.BASE_MONEY_BUY_RATE))
                    {
                        itemRow["상태"] = "투자율제한 매수X";
                        return(false);
                    }
                    ordptnDetail = "신규매수";
                }

                //추가 매수일수 있기때문에 추가매수 체크위에 위치하자
                if (ordptnDetail == "신규매수")
                {
                    String 종목제한수 = Properties.Settings.Default.MAX_BUY_COUNT;
                    int    보유종목수 = mainForm.grd_t0424.RowCount;
                    if (보유종목수 >= int.Parse(종목제한수))
                    {
                        //mainForm.grd_t0424.Rows[t0424VoListFindIndex].Cells["c_expcode"].Style.BackColor = Color.Red;
                        //mainForm.grd_t1833_dt.Rows[rowIndex].Cells["종목명"].Style.BackColor = Color.Red;
                        itemRow["상태"] = "종목수초과";
                        return(false);
                    }
                }



                //매수 가능 시간 비교
                if (!Util.isBuyTime())
                {
                    itemRow["상태"] = "시간x<" + ordptnDetail + ">";
                    return(false);
                }

                //4.매수
                //임시로 넣어둔다 왜 현제가가 0으로 넘어오는지 모르겠다.
                if (close == "0")
                {
                    itemRow["상태"] = "오류:246";
                    return(false);
                }

                //this 함수가 3번 호출 된다. 주문이 3번 나갈 수가 있어서 추가 해준다.
                if (itemRow["상태"].ToString().IndexOf("주문전송") >= 0)
                {
                    return(false);
                }

                if (!mainForm.cbx_buy_at.Checked)
                {
                    itemRow["상태"] = "매수정지 상태";
                    return(false);
                }

                /// <summary>
                /// 현물정상주문
                /// </summary>
                /// <param name="ordptnDetail">상세주문구분 신규매수|반복매수|금일매도|청산</param>
                /// <param name="IsuNo">종목번호</param>
                /// <param name="Quantity">수량</param>
                /// <param name="Price">가격</param>


                //실시간 가격 모니터링 등록
                mainForm.real_S3.call_real(shcode);
                mainForm.real_K3.call_real(shcode);
                //매수 실행
                Xing_CSPAT00600 xing_CSPAT00600 = mainForm.CSPAT00600Mng.get600();
                xing_CSPAT00600.call_request(hname, shcode, "매수", 0, Double.Parse(close), searchNm, 0, ordptnDetail);

                //로그출력
                itemRow["상태"] = "주문전송<" + ordptnDetail + ">";
                mainForm.log("<t1857Buy:" + searchNm + "><" + hname + "> <" + close + "원>" + ordptnDetail);
            }
            catch (Exception ex)
            {
                Log.WriteLine("t1857Buy: " + ex.Message);
                Log.WriteLine("t1857Buy: " + ex.StackTrace);
            }
            return(true);
        }//buyTest END