//손절 테스트 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
}//receiveDataEventHandler END public void getSummaryVo(T0424Vo t0424Vo) { String 종목코드 = t0424Vo.expcode; Double 매도가능수량 = t0424Vo.mdposqt; String 에러코드 = t0424Vo.errorcd; SummaryVo summaryVo = mainForm.tradingHistory.getSummaryVo(종목코드); if (summaryVo == null) { t0424Vo.errorcd = "summaryVo is null"; } else { String 최대수익율 = Util.nvl(summaryVo.maxRt, "0"); String 최소수익율 = Util.nvl(summaryVo.minRt, "0"); t0424Vo.sellCnt = summaryVo.sellCnt; //매도 횟수. t0424Vo.buyCnt = summaryVo.buyCnt; //매수 횟수 t0424Vo.firstBuyDt = summaryVo.firstBuyDt; //최초진입일시 t0424Vo.sumMdposqt = summaryVo.sumMdposqt; //매도가능이력 t0424Vo.ordermtd = summaryVo.ordermtd; //주문매체 t0424Vo.exclWatchAt = summaryVo.exclWatchAt; //감시제외여부 t0424Vo.searchNm = summaryVo.searchNm; //검색조건 이름 t0424Vo.maxRt = 최대수익율; //최대도달 수익율 t0424Vo.minRt = 최소수익율; //최소도달 수익율 //매도가능수량이 같지 않으면 에러표시 해주자. //String c_mdposqt = this.grd_t0424.Rows[rowIndex].Cells["c_mdposqt"].Value.ToString(); if (매도가능수량.ToString() != summaryVo.sumMdposqt) { t0424Vo.errorcd = "mdposqt not equals"; //this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.Red; } else if (매도가능수량.ToString() == summaryVo.sumMdposqt) { if (t0424Vo.errorcd.Equals("mdposqt not equals"))//기존 다른 에러코드가 존재하면 초기화 하지 않는다. { t0424Vo.errorcd = ""; //this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.White; } } //확장정보 에러일경우 에러상태를 풀어준다. if (t0424Vo.errorcd != null && t0424Vo.errorcd.Equals("summaryVo is null"))//summaryVo is null { t0424Vo.errorcd = ""; //this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.White; } } }
//선택 매도 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
}//histoySync END //종목매수 정보를 이력 DB에 저장 public void t0424VoToHistoryInsert(T0424Vo t0424Vo, String index) { //이력정보가 없으면 이력정보를 등록해준다. t0424Vo.expcode.Replace("A", ""); //t0424Vo.pamt2 = t0424Vo.pamt; //평균단가2 t0424Vo.sellCnt = "0"; //매도 횟수. t0424Vo.buyCnt = "1"; //매수 횟수 //t0424Vo.sellSunik = "0";//중간매도손익 /////////////////////////DB 신규저장///////////////////////////// TradingHistoryVo dataLogVo = new TradingHistoryVo(); dataLogVo.ordno = "I" + DateTime.Now.ToString("yyMMddHHmmss") + index; //주문번호 dataLogVo.dt = DateTime.Now.ToString("yyyyMMddHHmmss"); dataLogVo.accno = mainForm.account; //계좌번호 dataLogVo.ordptncode = "02"; //주문구분 01:매도|02:매수 dataLogVo.Isuno = t0424Vo.expcode.Replace("A", ""); //종목코드 dataLogVo.ordqty = t0424Vo.mdposqt.ToString(); //주문수량 - 매도가능수량 dataLogVo.execqty = t0424Vo.mdposqt.ToString(); //체결수량 - 매도가능수량 dataLogVo.ordprc = t0424Vo.pamt.ToString(); //주문가격 - 평균단가 dataLogVo.execprc = t0424Vo.pamt.ToString(); //체결가격 - 평균단가 dataLogVo.Isunm = t0424Vo.hname; //종목명 dataLogVo.ordptnDetail = "동기화"; //상세 주문구분 신규매수|반복매수|금일매도|청산 dataLogVo.upOrdno = dataLogVo.ordno; //상위 매수 주문번호 -값이없으면 자신의 주문번호로 넣는다. dataLogVo.upExecprc = "0"; //상위체결가격 dataLogVo.sellOrdAt = "N"; //매도주문 여부 YN default:N -02:매 일때만 값이 있어야한다. dataLogVo.useYN = "Y"; //사용여부 dataLogVo.ordermtd = "XING API"; //2.DB에 해당 주문 정보가 없을때 처리해줘야한다. volist로 변경후 테스트한후에 필요하면 처리로직 추가해주자. mainForm.tradingHistory.insert(dataLogVo); //쿼리 호출 //mainForm.tradingHistory.getTradingHistoryVoList().Add(dataLogVo); //mainForm.dataLog.dbSync(); Log.WriteLine("t0424::최초 이력 등록" + t0424Vo.hname + "(" + t0424Vo.expcode + ") . "); //프로그램 최초에만 동작해야 하는데 신규매수 매도시 이력 등록이 잘 안된다는 뜻이다. }
/// <summary> /// 주식잔고2(T0424) 데이터 응답 처리 /// </summary> /// <param name="szTrCode">조회코드</param> void receiveDataEventHandler(string szTrCode) { try { String cts_expcode = base.GetFieldData("t0424OutBlock", "cts_expcode", 0);//CTS_종목번호-연속조회키 //1.계좌 잔고 목록을 그리드에 추가 int blockCount = base.GetBlockCount("t0424OutBlock1"); T0424Vo tmpT0424Vo = null; String expcode; //종목코드 String mdposqt; //매도가능 String 주문여부; int findIndex; for (int i = 0; i < blockCount; i++) { expcode = base.GetFieldData("t0424OutBlock1", "expcode", i); //종목코드 mdposqt = base.GetFieldData("t0424OutBlock1", "mdposqt", i); //매도가능 //1.t0424 는 매도가능수량이 0 건인것은 없어야하는데 가끔 검색되어 나온다...그냥 스킵하자. if (Double.Parse(mdposqt) <= 0) { //Log.WriteLine("t0424 는 매도가능수량이 0 건인것은 조회 되지 말아야하는데... 가끔 검색되어 나오는지 잘 모르겠다..."); //Log.WriteLine("t0424::" + base.GetFieldData("t0424OutBlock1", "hname", i) + "(" + expcode + ")t0424 는 매도가능수량이 0 건인것은 조회 되지 말아야하는데... "); continue; } findIndex = t0424VoList.Find("expcode", expcode); if (findIndex < 0) { tmpT0424Vo = new T0424Vo(); this.t0424VoList.Add(tmpT0424Vo); findIndex = this.t0424VoList.Count() - 1; //mainForm.grd_t0424.Rows[findIndex].Cells["orderAt"].Value = "N"; tmpT0424Vo.orderAt = "N"; tmpT0424Vo.errorcd = ""; tmpT0424Vo.expcode = base.GetFieldData("t0424OutBlock1", "expcode", i); //종목코드 tmpT0424Vo.hname = base.GetFieldData("t0424OutBlock1", "hname", i); //종목명 tmpT0424Vo.mdposqt = Double.Parse(base.GetFieldData("t0424OutBlock1", "mdposqt", i)); //매도가능 수량 tmpT0424Vo.price = Double.Parse(base.GetFieldData("t0424OutBlock1", "price", i)); //현재가 tmpT0424Vo.appamt = Double.Parse(base.GetFieldData("t0424OutBlock1", "appamt", i)); //평가금액 tmpT0424Vo.dtsunik = Double.Parse(base.GetFieldData("t0424OutBlock1", "dtsunik", i)); //평가손익 tmpT0424Vo.sunikrt = Double.Parse(base.GetFieldData("t0424OutBlock1", "sunikrt", i)); //수익율 tmpT0424Vo.pamt = Double.Parse(base.GetFieldData("t0424OutBlock1", "pamt", i)); //평균단가 tmpT0424Vo.mamt = Double.Parse(base.GetFieldData("t0424OutBlock1", "mamt", i)); //매입금액 tmpT0424Vo.fee = Double.Parse(base.GetFieldData("t0424OutBlock1", "fee", i)); //수수료 tmpT0424Vo.tax = Double.Parse(base.GetFieldData("t0424OutBlock1", "tax", i)); //제세금 tmpT0424Vo.jonggb = base.GetFieldData("t0424OutBlock1", "jonggb", i); //종목시장구분 } else { tmpT0424Vo = t0424VoList.ElementAt(findIndex); mainForm.grd_t0424.Rows[findIndex].Cells["c_mdposqt"].Value = Double.Parse(base.GetFieldData("t0424OutBlock1", "mdposqt", i)); //매도가능 수량 mainForm.grd_t0424.Rows[findIndex].Cells["price"].Value = Double.Parse(base.GetFieldData("t0424OutBlock1", "price", i)); //현재가 mainForm.grd_t0424.Rows[findIndex].Cells["appamt"].Value = Double.Parse(base.GetFieldData("t0424OutBlock1", "appamt", i)); //평가금액 mainForm.grd_t0424.Rows[findIndex].Cells["dtsunik"].Value = Double.Parse(base.GetFieldData("t0424OutBlock1", "dtsunik", i)); //평가손익 mainForm.grd_t0424.Rows[findIndex].Cells["c_sunikrt"].Value = Double.Parse(base.GetFieldData("t0424OutBlock1", "sunikrt", i)); //수익율 mainForm.grd_t0424.Rows[findIndex].Cells["pamt"].Value = Double.Parse(base.GetFieldData("t0424OutBlock1", "pamt", i)); //평균단가 mainForm.grd_t0424.Rows[findIndex].Cells["mamt"].Value = Double.Parse(base.GetFieldData("t0424OutBlock1", "mamt", i)); //매입금액 mainForm.grd_t0424.Rows[findIndex].Cells["fee"].Value = Double.Parse(base.GetFieldData("t0424OutBlock1", "fee", i)); //수수료 mainForm.grd_t0424.Rows[findIndex].Cells["tax"].Value = Double.Parse(base.GetFieldData("t0424OutBlock1", "tax", i)); //제세금 } //주문여부 = mainForm.grd_t0424.Rows[findIndex].Cells["orderAt"].Value.ToString(); 주문여부 = tmpT0424Vo.orderAt; //매도 주문후 취소된 종목은 N상태이고 종목 정보가 업데이트 되면 주문여부를 N 으로 다시 돌려놓는다. if (주문여부 == "C") {//주문이 나가 종목은 t0424에서 종목 정보가 넘어오지 않아서 주문한 시점부터 정보가 업데이트 되지 않느다. //mainForm.grd_t0424.Rows[findIndex].Cells["orderAt"].Value = "N"; tmpT0424Vo.orderAt = "N"; } //그리드에서 삭제여부 mainForm.grd_t0424.Rows[findIndex].Cells["deleteAt"].Value = "N"; tmpT0424Vo.deleteAt = "N"; //확장정보 this.getSummaryVo(tmpT0424Vo); mainForm.priceChangedProcess(findIndex); }//for end //2.연속 데이타 정보가 남아있는지 구분 if (base.IsNext) { //연속 데이타 정보를 호출. base.SetFieldData("t0424InBlock", "cts_expcode", 0, cts_expcode); // CTS종목번호 : 처음 조회시는 SPACE base.Request(true); //연속조회일경우 true } else //마지막 데이타일때 메인폼에 출력해준다. //초기화 여부 { if (initAt) { //1.매매이력 동기화 --그냥 에러만 표시하는걸로 확인수 폼에서 클릭 //2.감시제외종목 그리드 동기화 this.exclWatchSync(); foreach (T0424Vo t0424Vo in t0424VoList) { //실시간 현재가 종목 등록 //코스피 if (t0424Vo.jonggb == "3") { mainForm.real_S3.call_real(t0424Vo.expcode); } //코스닥 if (t0424Vo.jonggb == "2") { mainForm.real_K3.call_real(t0424Vo.expcode); } } this.initAt = false; } else { //매매거래 가능 시간이고 매매가능여부 값이 Y일때 체크후 매도 로직 호출 if (Double.Parse(mainForm.xing_t0167.time.Substring(0, 4)) > 901 && Double.Parse(mainForm.xing_t0167.time.Substring(0, 4)) < 1519) { //목표수익율 설정 Double 목표수익율 = Double.Parse(Properties.Settings.Default.STOP_TARGET_RATE); for (int i = 0; i < this.t0424VoList.Count(); i++) { //1.거래가능여부 && 주문중상태가 아니고 && 종목거래 에러 여부 T0424Vo tmpt0424Vo = t0424VoList.ElementAt(i); if (tmpt0424Vo.errorcd == "") { this.tradingStopTest(t0424VoList.ElementAt(i), i, 목표수익율); } else { ; } this.t0424VoList.ElementAt(i).deleteAt = "Y"; } } } this.dtsunik = Double.Parse(this.GetFieldData("t0424OutBlock", "dtsunik", 0));// 실현손익 //트레이딩 정보 업데이트 mainForm.tradingInfoUpdate(); //로그 및 중복 요청 처리 2:코스닥, 3:코스피 mainForm.input_t0424_log.Text = "[" + DateTime.Now.TimeOfDay.ToString().Substring(0, 8) + "]t0424 :: 잔고조회 완료"; mainForm.h_totalCount.Text = t0424VoList.Count().ToString(); //응답처리 완료 completeAt = true; }//end }catch (Exception ex) { Log.WriteLine("t0424 : " + ex.Message); Log.WriteLine("t0424 : " + ex.StackTrace); } }//receiveDataEventHandler END
}//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
//매도 테스트 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
//그리드 현재가 변경 이벤트 public void priceChangedProcess(int rowIndex) { T0424Vo t0424Vo = (T0424Vo)this.grd_t0424.Rows[rowIndex].DataBoundItem; String 종목코드 = t0424Vo.expcode; Double 수익율 = t0424Vo.sunikrt; String 에러코드 = t0424Vo.errorcd == null ? "" : t0424Vo.errorcd; Double 매도가능수량 = t0424Vo.mdposqt; String 최대수익율 = t0424Vo.maxRt == null ? "0" : t0424Vo.maxRt; String 최소수익율 = t0424Vo.minRt == null ? "0" : t0424Vo.minRt; //매매이력정보 호출 //if (종목코드=="081660") //{ // String ddd = "dd"; //} //SummaryVo summaryVo = this.tradingHistory.getSummaryVo(종목코드); //if (summaryVo != null) { // String 최대수익율 = Util.nvl(summaryVo.maxRt, "0"); // String 최소수익율 = Util.nvl(summaryVo.minRt, "0"); // this.grd_t0424.Rows[rowIndex].Cells["sellCnt" ].Value = summaryVo.sellCnt; //매도 횟수. // this.grd_t0424.Rows[rowIndex].Cells["buyCnt" ].Value = summaryVo.buyCnt; //매수 횟수 // this.grd_t0424.Rows[rowIndex].Cells["firstBuyDt" ].Value = summaryVo.firstBuyDt; //최초진입일시 // this.grd_t0424.Rows[rowIndex].Cells["sumMdposqt" ].Value = summaryVo.sumMdposqt; //매도가능이력 // this.grd_t0424.Rows[rowIndex].Cells["c_ordermtd" ].Value = summaryVo.ordermtd; //주문매체 // this.grd_t0424.Rows[rowIndex].Cells["c_exclWatchAt" ].Value = summaryVo.exclWatchAt; //감시제외여부 // this.grd_t0424.Rows[rowIndex].Cells["searchNm" ].Value = summaryVo.searchNm; //검색조건 이름 // this.grd_t0424.Rows[rowIndex].Cells["maxRt" ].Value = 최대수익율; //최대도달 수익율 // this.grd_t0424.Rows[rowIndex].Cells["minRt" ].Value = 최소수익율; //최소도달 수익율 // //매도가능수량이 같지 않으면 에러표시 해주자. // //String c_mdposqt = this.grd_t0424.Rows[rowIndex].Cells["c_mdposqt"].Value.ToString(); // if (매도가능수량.ToString() != summaryVo.sumMdposqt) // { // t0424Vo.errorcd = "mdposqt not equals"; // this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.Red; // } // else if (매도가능수량.ToString() == summaryVo.sumMdposqt) // { // if (errorcd.Equals("mdposqt not equals"))//기존 다른 에러코드가 존재하면 초기화 하지 않는다. // { // t0424Vo.errorcd = ""; // this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.White; // } // } // //확장정보 에러일경우 에러상태를 풀어준다. // if (errorcd != null && errorcd.Equals("notHistory")) { // t0424Vo.errorcd = ""; // this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.White; // } //String c_mdposqt = this.grd_t0424.Rows[rowIndex].Cells["c_mdposqt"].Value.ToString(); //if (매도가능수량.ToString() != t0424Vo.sumMdposqt) //{ // //t0424Vo.errorcd = "mdposqt not equals"; // this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.Red; //} //else if (매도가능수량.ToString() == t0424Vo.sumMdposqt) //{ // if (t0424Vo.errorcd.Equals("mdposqt not equals"))//기존 다른 에러코드가 존재하면 초기화 하지 않는다. // { // //t0424Vo.errorcd = ""; // this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.White; // } //} ////확장정보 에러일경우 에러상태를 풀어준다. //if (t0424Vo.errorcd != null && t0424Vo.errorcd.Equals("notHistory")) //{ // //t0424Vo.errorcd = ""; // this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.White; //} if (t0424Vo.errorcd == null || t0424Vo.errorcd == "") { this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.White; } else { this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.Red; } //그리드 수익에따라 폰트색 지정 Color color = 수익율 < 0 ? Color.Blue : Color.Red; grd_t0424.Rows[rowIndex].Cells["price"].Style.ForeColor = color; //현재가 grd_t0424.Rows[rowIndex].Cells["c_sunikrt"].Style.ForeColor = color; //손익율 grd_t0424.Rows[rowIndex].Cells["dtsunik"].Style.ForeColor = color; //평가손익금 grd_t0424.Rows[rowIndex].Cells["appamt"].Style.ForeColor = color; //평가금액 //제외종목 가격도 같이 수정해주자. int findIndex = this.xing_t0424.getExcludeT0424VoList().Find("expcode", 종목코드); if (findIndex >= 0) { grd_t0424Excl.Rows[findIndex].Cells["e_price"].Value = grd_t0424.Rows[rowIndex].Cells["price"].Value; } //수익율 최소 최대 업데이트 //String 현재수익율 = this.grd_t0424.Rows[rowIndex].Cells["c_sunikrt"].Value.ToString(); //double d현재수익 = double.Parse(현재수익율.Trim()); //double d최대수익율 = double.Parse(최대수익율.Trim()); if (최대수익율 == "∞") { this.tradingHistory.maxHisRtUpdate(종목코드, 수익율.ToString()); this.log("∞ mainForm line 1020"); } if (수익율 > double.Parse(최대수익율)) { this.tradingHistory.maxHisRtUpdate(종목코드, 수익율.ToString()); this.grd_t0424.Rows[rowIndex].Cells["maxRt"].Value = 수익율; //최대도달 수익율 } if (수익율 < double.Parse(최소수익율)) { this.tradingHistory.minHisRtUpdate(종목코드, 수익율.ToString()); this.grd_t0424.Rows[rowIndex].Cells["minRt"].Value = 수익율; //최소도달 수익율 } //} else { // //이력정보가 없으면 에러코드등록해준다. // t0424Vo.errorcd = "notHistory"; // this.grd_t0424.Rows[rowIndex].DefaultCellStyle.BackColor = Color.Red; //} }