}//grd_t0424_CellValueChanged END public void tradingInfoUpdate() { //MessageBox.Show(grd_t0424.Rows[e.RowIndex].Cells["price"].Value.ToString()); //현재 가격이 변경되면 EBindingList <T0424Vo> t0424VoList = this.xing_t0424.getT0424VoList(); Double 예수금 = Double.Parse(xing_CSPAQ12200.Dps); Double 예수금D2 = Double.Parse(xing_CSPAQ12200.D2Dps); Double 실현손익 = xing_t0424.dtsunik; Double 종목수 = t0424VoList.Count(); Double 매입금액 = t0424VoList.Select(item => item.mamt).Sum(); Double 평가금액 = t0424VoList.Select(item => item.appamt).Sum(); Double 평가손익 = 평가금액 - 매입금액; Double 수익률 = this.xing_t0424.getSunikrt(평가금액, 매입금액); Double 예탁자산총액 = 평가금액 + 예수금D2; Double 누적수익 = this.chartData.getSumDtsunik() + 실현손익; Double 투자율 = Util.getInputRate(매입금액, 예수금D2); DataRow tmpRow = tradingInfoDt.Rows[0]; //tradingInfoDt.Columns.Add("날자", typeof(string)); tmpRow["예수금"] = 예수금; tmpRow["예수금(D2)"] = 예수금D2; tmpRow["예탁자산총액"] = 예탁자산총액; tmpRow["매입금액"] = 매입금액; tmpRow["평가금액"] = 평가금액; tmpRow["수익률"] = 수익률; tmpRow["평가손익"] = 평가손익; tmpRow["실현손익"] = 실현손익; tmpRow["투자율"] = 투자율; tmpRow["누적수익"] = 누적수익; }
//감시제외종목 그리드 동기화 public void exclWatchSync() { //private EBindingList<T0424Vo> t0424VoList; //private EBindingList<T0424Vo> t0424VoExclList; this.excludeT0424VoList.Clear(); for (int i = 0; i < t0424VoList.Count(); i++) { if (t0424VoList.ElementAt(i).exclWatchAt == "Y") { int findIndex = this.excludeT0424VoList.Find("expcode", t0424VoList.ElementAt(i).expcode.Replace("A", "")); if (findIndex >= 0) { //mainForm.grd_t0424Excl.Rows[tmpIndex].Cells["e_ordermtd" ].Value = tmpT0424Vo.ordermtd; //주문매체 //mainForm.grd_t0424Excl.Rows[findIndex].Cells["e_targClearPrc" ].Value = Util.GetNumberFormat(t0424VoList.ElementAt(i).targClearPrc); //목표청산가격 //mainForm.grd_t0424Excl.Rows[findIndex].Cells["e_secEntPrc" ].Value = Util.GetNumberFormat(t0424VoList.ElementAt(i).secEntPrc); //2차진입가격 //mainForm.grd_t0424Excl.Rows[findIndex].Cells["e_secEntAmt" ].Value = Util.GetNumberFormat(t0424VoList.ElementAt(i).secEntAmt); //2차진입비중가격 //mainForm.grd_t0424Excl.Rows[findIndex].Cells["e_stopPrc" ].Value = Util.GetNumberFormat(t0424VoList.ElementAt(i).stopPrc); //손절가격 mainForm.grd_t0424Excl.Rows[findIndex].Cells["e_exclWatchAt"].Value = t0424VoList.ElementAt(i).exclWatchAt; //감시제외여부 mainForm.grd_t0424Excl.Rows[findIndex].Cells["e_price"].Value = t0424VoList.ElementAt(i).price; //현재가격 } else { //감시제외 그리드에 추가 ExcludeT0424Vo excludeT0424Vo = new ExcludeT0424Vo(); excludeT0424Vo.expcode = t0424VoList.ElementAt(i).expcode; excludeT0424Vo.hname = t0424VoList.ElementAt(i).hname; //excludeT0424Vo.targClearPrc = t0424VoList.ElementAt(i).targClearPrc; //excludeT0424Vo.secEntPrc = t0424VoList.ElementAt(i).secEntPrc; //excludeT0424Vo.secEntAmt = t0424VoList.ElementAt(i).secEntAmt; //excludeT0424Vo.stopPrc = t0424VoList.ElementAt(i).stopPrc; excludeT0424Vo.exclWatchAt = t0424VoList.ElementAt(i).exclWatchAt; excludeT0424Vo.price = t0424VoList.ElementAt(i).price; this.excludeT0424VoList.Add(excludeT0424Vo); int addIndex = excludeT0424VoList.Count() - 1; mainForm.t0424ExclPriceChangedProcess(addIndex); } } if (t0424VoList.ElementAt(i).exclWatchAt == "N") {//감시제외 그리드에서 삭제. int tmpIndex = this.excludeT0424VoList.Find("expcode", t0424VoList.ElementAt(i).expcode.Replace("A", "")); if (tmpIndex >= 0) { this.excludeT0424VoList.RemoveAt(tmpIndex); } } } }//fn END
/// <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