private void dbUpdateOrderStatus(OPT10085_Data opt10085_data) { FileLog.PrintF("MyStock dbUpdateOrderStatus"); using (MySqlConnection conn = new MySqlConnection(Config.GetDbConnStr())) { string sql = @"UPDATE opt10085s SET order_status=@주문상태 WHERE stock_code=@종목코드 AND account_number=@계좌번호 ; "; conn.Open(); MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@주문상태", opt10085_data.주문상태); cmd.Parameters.AddWithValue("@종목코드", opt10085_data.종목코드); cmd.Parameters.AddWithValue("@계좌번호", opt10085_data.계좌번호); cmd.ExecuteNonQuery(); } }
private void dbUpdate(OPT10085_Data opt10085_data) { FileLog.PrintF("MyStock dbUpdate"); using (MySqlConnection conn = new MySqlConnection(Config.GetDbConnStr())) { String dayTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string sql = @"UPDATE opt10085s SET current_price=@현재가 ,evaluated_price=@평가금액 ,selling_commission=@매도수수료 ,commission=@수수료 ,selling_tax=@매도세금 ,will_profit_price=@손익분기매입가 ,valuation_profit_and_loss=@평가손익 ,earnings_rate=@수익률 ,not_commission_profit_and_loss=@손익금액 ,not_commission_profit_and_loss_rate=@손익율 ,updated_at=@업데이트날짜 WHERE stock_code=@종목코드 ; "; conn.Open(); MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@현재가", opt10085_data.현재가); cmd.Parameters.AddWithValue("@평가금액", opt10085_data.평가금액); cmd.Parameters.AddWithValue("@매도수수료", opt10085_data.매도수수료); cmd.Parameters.AddWithValue("@수수료", opt10085_data.수수료); cmd.Parameters.AddWithValue("@매도세금", opt10085_data.매도세금); cmd.Parameters.AddWithValue("@손익분기매입가", opt10085_data.손익분기매입가); cmd.Parameters.AddWithValue("@평가손익", opt10085_data.평가손익); cmd.Parameters.AddWithValue("@수익률", opt10085_data.수익률); cmd.Parameters.AddWithValue("@손익금액", opt10085_data.손익금액); cmd.Parameters.AddWithValue("@손익율", opt10085_data.손익율); cmd.Parameters.AddWithValue("@업데이트날짜", dayTime); cmd.Parameters.AddWithValue("@종목코드", opt10085_data.종목코드); cmd.ExecuteNonQuery(); } }
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); //} }
private void SendDirectDb(List <OPT10085_Data> opt10085_DataList) { lock (_lockStockList) { try { using (MySqlConnection conn = new MySqlConnection(Config.GetDbConnStr())) { String sql1 = "DELETE FROM opt10085s;"; conn.Open(); MySqlTransaction tr = conn.BeginTransaction(); String dayTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); try { MySqlCommand cmd = new MySqlCommand(sql1, conn, tr); cmd.ExecuteNonQuery(); string sql2 = @"INSERT INTO opt10085s ( date_of_purchase ,account_number ,stock_code ,stock_name ,current_price ,purchase_price ,total_amount_of_purchase ,possession_quantity ,today_sell_profit_and_loss ,today_commission ,today_tax ,credit_gubun ,loan_date ,payment_balance ,sellable_quantity ,credit_amount ,credit_interest ,expiration_date ,valuation_profit_and_loss ,earnings_rate ,evaluated_price ,commission ,buying_commission ,selling_commission ,selling_tax ,will_profit_price ,not_commission_profit_and_loss ,not_commission_profit_and_loss_rate ,order_status ,created_at ,updated_at ) VALUES"; String sql2_1 = @" ( @구매일자{0} ,@계좌번호{0} ,@종목코드{0} ,@종목명{0} ,@현재가{0} ,@매입가{0} ,@매입금액{0} ,@보유수량{0} ,@당일매도손익{0} ,@당일매매수수료{0} ,@당일매매세금{0} ,@신용구분{0} ,@대출일{0} ,@결제잔고{0} ,@청산가능수량{0} ,@신용금액{0} ,@신용이자{0} ,@만기일{0} ,@평가손익{0} ,@수익률{0} ,@평가금액{0} ,@수수료{0} ,@매입수수료{0} ,@매도수수료{0} ,@매도세금{0} ,@손익분기매입가{0} ,@손익금액{0} ,@손익율{0} ,@주문상태{0} ,@등록날짜{0} ,@업데이트날짜{0} ),"; StringBuilder queryBuilder = new StringBuilder(sql2); for (int i = 0; i < opt10085_DataList.Count(); i++) { queryBuilder.AppendFormat(sql2_1, i); //once we're done looping we remove the last ',' and replace it with a ';' if (i == opt10085_DataList.Count() - 1) { queryBuilder.Replace(',', ';', queryBuilder.Length - 1, 1); } } String sql2_2 = queryBuilder.ToString(); FileLog.PrintF("SendDirectDb2 sql2_2:" + sql2_2.ToString()); cmd.CommandText = sql2_2; for (int i = 0; i < opt10085_DataList.Count(); i++) { cmd.Parameters.AddWithValue("@구매일자" + i, opt10085_DataList[i].구매일자); cmd.Parameters.AddWithValue("@계좌번호" + i, opt10085_DataList[i].계좌번호); cmd.Parameters.AddWithValue("@종목코드" + i, opt10085_DataList[i].종목코드); cmd.Parameters.AddWithValue("@종목명" + i, opt10085_DataList[i].종목명); cmd.Parameters.AddWithValue("@현재가" + i, opt10085_DataList[i].현재가); cmd.Parameters.AddWithValue("@매입가" + i, opt10085_DataList[i].매입가); cmd.Parameters.AddWithValue("@매입금액" + i, opt10085_DataList[i].매입금액); cmd.Parameters.AddWithValue("@보유수량" + i, opt10085_DataList[i].보유수량); cmd.Parameters.AddWithValue("@당일매도손익" + i, opt10085_DataList[i].당일매도손익); cmd.Parameters.AddWithValue("@당일매매수수료" + i, opt10085_DataList[i].당일매매수수료); cmd.Parameters.AddWithValue("@당일매매세금" + i, opt10085_DataList[i].당일매매세금); cmd.Parameters.AddWithValue("@신용구분" + i, opt10085_DataList[i].신용구분); cmd.Parameters.AddWithValue("@대출일" + i, opt10085_DataList[i].대출일); cmd.Parameters.AddWithValue("@결제잔고" + i, opt10085_DataList[i].결제잔고); cmd.Parameters.AddWithValue("@청산가능수량" + i, opt10085_DataList[i].청산가능수량); cmd.Parameters.AddWithValue("@신용금액" + i, opt10085_DataList[i].신용금액); cmd.Parameters.AddWithValue("@신용이자" + i, opt10085_DataList[i].신용이자); cmd.Parameters.AddWithValue("@만기일" + i, opt10085_DataList[i].만기일); cmd.Parameters.AddWithValue("@평가손익" + i, opt10085_DataList[i].평가손익); cmd.Parameters.AddWithValue("@수익률" + i, opt10085_DataList[i].수익률); cmd.Parameters.AddWithValue("@평가금액" + i, opt10085_DataList[i].평가금액); cmd.Parameters.AddWithValue("@수수료" + i, opt10085_DataList[i].수수료); cmd.Parameters.AddWithValue("@매입수수료" + i, opt10085_DataList[i].매입수수료); cmd.Parameters.AddWithValue("@매도수수료" + i, opt10085_DataList[i].매도수수료); cmd.Parameters.AddWithValue("@매도세금" + i, opt10085_DataList[i].매도세금); cmd.Parameters.AddWithValue("@손익분기매입가" + i, opt10085_DataList[i].손익분기매입가); cmd.Parameters.AddWithValue("@손익금액" + i, opt10085_DataList[i].손익금액); cmd.Parameters.AddWithValue("@손익율" + i, opt10085_DataList[i].손익율); cmd.Parameters.AddWithValue("@주문상태" + i, 1);//1 은 보유를 의미 cmd.Parameters.AddWithValue("@업데이트날짜" + i, dayTime); cmd.Parameters.AddWithValue("@등록날짜" + i, dayTime); } cmd.ExecuteNonQuery(); String sql3 = @"SELECT DATE_OF_PURCHASE ,ACCOUNT_NUMBER ,STOCK_CODE ,STOCK_NAME ,CURRENT_PRICE ,PURCHASE_PRICE ,TOTAL_AMOUNT_OF_PURCHASE ,POSSESSION_QUANTITY ,TODAY_SELL_PROFIT_AND_LOSS ,TODAY_COMMISSION ,TODAY_TAX ,CREDIT_GUBUN ,LOAN_DATE ,PAYMENT_BALANCE ,SELLABLE_QUANTITY ,CREDIT_AMOUNT ,CREDIT_INTEREST ,EXPIRATION_DATE ,VALUATION_PROFIT_AND_LOSS ,EARNINGS_RATE ,EVALUATED_PRICE ,COMMISSION ,BUYING_COMMISSION ,SELLING_COMMISSION ,SELLING_TAX ,WILL_PROFIT_PRICE ,NOT_COMMISSION_PROFIT_AND_LOSS ,NOT_COMMISSION_PROFIT_AND_LOSS_RATE ,ORDER_STATUS FROM opt10085s ORDER BY date_of_purchase DESC"; cmd.CommandText = sql3; MySqlDataReader rdr = cmd.ExecuteReader(); // 다음 레코드 계속 가져와서 루핑 while (rdr.Read()) { // C# 인덱서를 사용하여 // 필드 데이타 엑세스 OPT10085_Data tmp = new OPT10085_Data(); tmp.구매일자 = rdr["DATE_OF_PURCHASE"].ToString().Trim(); tmp.계좌번호 = rdr["ACCOUNT_NUMBER"].ToString().Trim(); tmp.종목코드 = rdr["STOCK_CODE"].ToString().Trim(); tmp.종목명 = rdr["STOCK_NAME"].ToString().Trim(); tmp.현재가 = int.Parse(rdr["CURRENT_PRICE"].ToString().Trim()); tmp.매입가 = int.Parse(rdr["PURCHASE_PRICE"].ToString().Trim()); tmp.매입금액 = int.Parse(rdr["TOTAL_AMOUNT_OF_PURCHASE"].ToString().Trim()); tmp.보유수량 = int.Parse(rdr["POSSESSION_QUANTITY"].ToString().Trim()); tmp.당일매도손익 = int.Parse(rdr["TODAY_SELL_PROFIT_AND_LOSS"].ToString().Trim()); tmp.당일매매수수료 = int.Parse(rdr["TODAY_COMMISSION"].ToString().Trim()); tmp.당일매매세금 = int.Parse(rdr["TODAY_TAX"].ToString().Trim()); tmp.신용구분 = rdr["CREDIT_GUBUN"].ToString().Trim(); tmp.대출일 = rdr["LOAN_DATE"].ToString().Trim(); tmp.결제잔고 = int.Parse(rdr["PAYMENT_BALANCE"].ToString().Trim()); tmp.청산가능수량 = int.Parse(rdr["SELLABLE_QUANTITY"].ToString().Trim()); tmp.신용금액 = int.Parse(rdr["CREDIT_AMOUNT"].ToString().Trim()); tmp.신용이자 = int.Parse(rdr["CREDIT_INTEREST"].ToString().Trim()); tmp.만기일 = rdr["EXPIRATION_DATE"].ToString().Trim(); tmp.평가손익 = int.Parse(rdr["VALUATION_PROFIT_AND_LOSS"].ToString().Trim()); tmp.수익률 = float.Parse(rdr["EARNINGS_RATE"].ToString().Trim()); tmp.평가금액 = int.Parse(rdr["EVALUATED_PRICE"].ToString().Trim()); tmp.수수료 = int.Parse(rdr["COMMISSION"].ToString().Trim()); tmp.매입수수료 = int.Parse(rdr["BUYING_COMMISSION"].ToString().Trim()); tmp.매도수수료 = int.Parse(rdr["SELLING_COMMISSION"].ToString().Trim()); tmp.매도세금 = int.Parse(rdr["SELLING_TAX"].ToString().Trim()); tmp.손익분기매입가 = int.Parse(rdr["WILL_PROFIT_PRICE"].ToString().Trim()); tmp.손익금액 = int.Parse(rdr["NOT_COMMISSION_PROFIT_AND_LOSS"].ToString().Trim()); tmp.손익율 = float.Parse(rdr["NOT_COMMISSION_PROFIT_AND_LOSS_RATE"].ToString().Trim()); tmp.주문상태 = int.Parse(rdr["ORDER_STATUS"].ToString().Trim()); stockList.Add(tmp); } // 사용후 닫음 rdr.Close(); tr.Commit(); } catch (MySqlException ex2) { try { tr.Rollback(); } catch (MySqlException ex1) { FileLog.PrintF("SendDirectDb1 Error:" + ex1.ToString()); } FileLog.PrintF("SendDirectDb2 Error:" + ex2.ToString()); } } } catch (MySqlException ex3) { FileLog.PrintF("SendDirectDb3 Error:" + ex3.ToString()); } } }
private void autoSale(OPT10085_Data opt10085_data) { FileLog.PrintF("autoSale loss_status=>" + loss_status + ",loss_rate=>" + loss_rate + ",종목코드=>" + opt10085_data.종목코드 + ",손익율=>" + opt10085_data.손익율 + ",주문상태=>" + opt10085_data.주문상태); //주식체결 정보가 들어와서 주식 현재가가 변동이 있을때 자동 판매로직이 실행됨 /*손절매*/ if (loss_status == true) { if (opt10085_data.손익율 <= this.loss_rate && opt10085_data.주문상태 == 1)//주문상태가 1 즉 보여상태이어야한다. { if (MyOrder.getClass1Instance().ExistsOrder(opt10085_data.종목코드) == false) { //매도주문 int nOrderType = 2;//신규메도 String sCode = opt10085_data.종목코드; String sScreenNo = ScreenNumber.getClass1Instance().GetAnyTimeScrNum(); int nQty = opt10085_data.보유수량; int nPrice = 0; //일단 시장가매도하자. String sHogaGb = "03"; //시장가 매도 String sOrgOrderNo = ""; //원주문번호는 공백 FileLog.PrintF("autoSale sScreenNo=>" + sScreenNo); FileLog.PrintF("autoSale accountNumber=>" + accountNumber); FileLog.PrintF("autoSale nOrderType=>" + nOrderType); FileLog.PrintF("autoSale sCode=>" + sCode); FileLog.PrintF("autoSale nQty=>" + nQty); FileLog.PrintF("autoSale nPrice=>" + nPrice); FileLog.PrintF("autoSale sHogaGb=>" + sHogaGb); FileLog.PrintF("autoSale sOrgOrderNo=>" + sOrgOrderNo); //아 이거 1초에 5번 즉 0.2초 제한이 여기도 있다. ㅠㅠ이렇게 바로 보내면 안된다... int ret = AppLib.getClass1Instance().getAxKHOpenAPIInstance().SendOrder("손절매_매도주문", sScreenNo, accountNumber, nOrderType, sCode, nQty, nPrice, sHogaGb, sOrgOrderNo); FileLog.PrintF("MyStock AutoSale ret=>" + ret); //상태가 하나더 있어야겠다 주문접수를 한상태인거는 다시 매도를 시도하면 안되므로 opt10085_data.주문상태 = 2; dbUpdateOrderStatus(opt10085_data); } } } /*이익실현*/ if (profit_status == true) { if (opt10085_data.손익율 >= this.profit_rate && opt10085_data.주문상태 == 1)//주문상태가 1 즉 보여상태이어야한다. { //매도주문 if (MyOrder.getClass1Instance().ExistsOrder(opt10085_data.종목코드) == false) { int nOrderType = 2;//신규메도 String sCode = opt10085_data.종목코드; int nQty = opt10085_data.보유수량; int nPrice = 0; //일단 시장가매도하자. String sHogaGb = "03"; //시장가 매도 String sOrgOrderNo = ""; //원주문번호는 공백 String sScreenNo = ScreenNumber.getClass1Instance().GetAnyTimeScrNum(); FileLog.PrintF("autoSale sScreenNo=>" + sScreenNo); FileLog.PrintF("autoSale accountNumber=>" + accountNumber); FileLog.PrintF("autoSale nOrderType=>" + nOrderType); FileLog.PrintF("autoSale sCode=>" + sCode); FileLog.PrintF("autoSale nQty=>" + nQty); FileLog.PrintF("autoSale nPrice=>" + nPrice); FileLog.PrintF("autoSale sHogaGb=>" + sHogaGb); FileLog.PrintF("autoSale sOrgOrderNo=>" + sOrgOrderNo); int ret = AppLib.getClass1Instance().getAxKHOpenAPIInstance().SendOrder("이익매_매도주문", sScreenNo, accountNumber, nOrderType, sCode, nQty, nPrice, sHogaGb, sOrgOrderNo); FileLog.PrintF("MyStock AutoSale ret=>" + ret); opt10085_data.주문상태 = 2; dbUpdateOrderStatus(opt10085_data); } } } }