示例#1
0
        private void dbUpdateOrderStatus(TB_OPT10085 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.order_status);
                cmd.Parameters.AddWithValue("@종목코드", opt10085_data.stock_cd);
                cmd.Parameters.AddWithValue("@계좌번호", opt10085_data.acct_num);
                cmd.ExecuteNonQuery();
            }
        }
示例#2
0
        private void dbUpdate(TB_OPT10085 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.curr_amt);
                cmd.Parameters.AddWithValue("@평가금액", opt10085_data.evaluated_amt);
                cmd.Parameters.AddWithValue("@매도수수료", opt10085_data.buying_commission);
                cmd.Parameters.AddWithValue("@수수료", opt10085_data.commission);
                cmd.Parameters.AddWithValue("@매도세금", opt10085_data.selling_tax);
                cmd.Parameters.AddWithValue("@손익분기매입가", opt10085_data.will_profit_amt);
                cmd.Parameters.AddWithValue("@평가손익", opt10085_data.valuation_profit_loss);
                cmd.Parameters.AddWithValue("@수익률", opt10085_data.earnings_rt);
                cmd.Parameters.AddWithValue("@손익금액", opt10085_data.not_commission_profit_loss);
                cmd.Parameters.AddWithValue("@손익율", opt10085_data.profit_loss_rt);
                cmd.Parameters.AddWithValue("@업데이트날짜", dayTime);
                cmd.Parameters.AddWithValue("@종목코드", opt10085_data.stock_cd);
                cmd.ExecuteNonQuery();
            }
        }
示例#3
0
        private void SendDirectDb(List <TB_OPT10085> 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].purchase_dt);
                                cmd.Parameters.AddWithValue("@계좌번호" + i, opt10085_DataList[i].acct_num);
                                cmd.Parameters.AddWithValue("@종목코드" + i, opt10085_DataList[i].stock_cd);
                                cmd.Parameters.AddWithValue("@현재가" + i, opt10085_DataList[i].curr_amt);
                                cmd.Parameters.AddWithValue("@매입가" + i, opt10085_DataList[i].purchase_amt);
                                cmd.Parameters.AddWithValue("@매입금액" + i, opt10085_DataList[i].tot_purchase_amt);
                                cmd.Parameters.AddWithValue("@보유수량" + i, opt10085_DataList[i].possession_qty);
                                cmd.Parameters.AddWithValue("@당일매도손익" + i, opt10085_DataList[i].today_sell_profit_loss);
                                cmd.Parameters.AddWithValue("@당일매매수수료" + i, opt10085_DataList[i].today_commission);
                                cmd.Parameters.AddWithValue("@당일매매세금" + i, opt10085_DataList[i].today_tax);
                                cmd.Parameters.AddWithValue("@신용구분" + i, opt10085_DataList[i].credit_gubun);
                                cmd.Parameters.AddWithValue("@대출일" + i, opt10085_DataList[i].loan_dt);
                                cmd.Parameters.AddWithValue("@결제잔고" + i, opt10085_DataList[i].payment_balance);
                                cmd.Parameters.AddWithValue("@청산가능수량" + i, opt10085_DataList[i].sellable_qty);
                                cmd.Parameters.AddWithValue("@신용금액" + i, opt10085_DataList[i].credit_amt);
                                cmd.Parameters.AddWithValue("@신용이자" + i, opt10085_DataList[i].credit_interest);
                                cmd.Parameters.AddWithValue("@만기일" + i, opt10085_DataList[i].expiry_dt);
                                cmd.Parameters.AddWithValue("@평가손익" + i, opt10085_DataList[i].valuation_profit_loss);
                                cmd.Parameters.AddWithValue("@수익률" + i, opt10085_DataList[i].earnings_rt);
                                cmd.Parameters.AddWithValue("@평가금액" + i, opt10085_DataList[i].evaluated_amt);
                                cmd.Parameters.AddWithValue("@수수료" + i, opt10085_DataList[i].commission);
                                cmd.Parameters.AddWithValue("@매입수수료" + i, opt10085_DataList[i].selling_commission);
                                cmd.Parameters.AddWithValue("@매도수수료" + i, opt10085_DataList[i].buying_commission);
                                cmd.Parameters.AddWithValue("@매도세금" + i, opt10085_DataList[i].selling_tax);
                                cmd.Parameters.AddWithValue("@손익분기매입가" + i, opt10085_DataList[i].will_profit_amt);
                                cmd.Parameters.AddWithValue("@손익금액" + i, opt10085_DataList[i].not_commission_profit_loss);
                                cmd.Parameters.AddWithValue("@손익율" + i, opt10085_DataList[i].profit_loss_rt);
                                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# 인덱서를 사용하여
                                // 필드 데이타 엑세스
                                TB_OPT10085 tmp = new TB_OPT10085();
                                tmp.purchase_dt            = rdr["DATE_OF_PURCHASE"].ToString().Trim();
                                tmp.acct_num               = rdr["ACCOUNT_NUMBER"].ToString().Trim();
                                tmp.stock_cd               = rdr["STOCK_CODE"].ToString().Trim();
                                tmp.curr_amt               = int.Parse(rdr["CURRENT_PRICE"].ToString().Trim());
                                tmp.purchase_amt           = int.Parse(rdr["PURCHASE_PRICE"].ToString().Trim());
                                tmp.tot_purchase_amt       = int.Parse(rdr["TOTAL_AMOUNT_OF_PURCHASE"].ToString().Trim());
                                tmp.possession_qty         = int.Parse(rdr["POSSESSION_QUANTITY"].ToString().Trim());
                                tmp.today_sell_profit_loss = int.Parse(rdr["TODAY_SELL_PROFIT_AND_LOSS"].ToString().Trim());
                                tmp.today_commission       = int.Parse(rdr["TODAY_COMMISSION"].ToString().Trim());
                                tmp.today_tax              = int.Parse(rdr["TODAY_TAX"].ToString().Trim());
                                tmp.credit_gubun           = rdr["CREDIT_GUBUN"].ToString().Trim();
                                tmp.loan_dt                    = rdr["LOAN_DATE"].ToString().Trim();
                                tmp.payment_balance            = int.Parse(rdr["PAYMENT_BALANCE"].ToString().Trim());
                                tmp.sellable_qty               = int.Parse(rdr["SELLABLE_QUANTITY"].ToString().Trim());
                                tmp.credit_amt                 = int.Parse(rdr["CREDIT_AMOUNT"].ToString().Trim());
                                tmp.credit_interest            = int.Parse(rdr["CREDIT_INTEREST"].ToString().Trim());
                                tmp.expiry_dt                  = rdr["EXPIRATION_DATE"].ToString().Trim();
                                tmp.valuation_profit_loss      = int.Parse(rdr["VALUATION_PROFIT_AND_LOSS"].ToString().Trim());
                                tmp.earnings_rt                = float.Parse(rdr["EARNINGS_RATE"].ToString().Trim());
                                tmp.evaluated_amt              = int.Parse(rdr["EVALUATED_PRICE"].ToString().Trim());
                                tmp.commission                 = int.Parse(rdr["COMMISSION"].ToString().Trim());
                                tmp.selling_commission         = int.Parse(rdr["BUYING_COMMISSION"].ToString().Trim());
                                tmp.buying_commission          = int.Parse(rdr["SELLING_COMMISSION"].ToString().Trim());
                                tmp.selling_tax                = int.Parse(rdr["SELLING_TAX"].ToString().Trim());
                                tmp.will_profit_amt            = int.Parse(rdr["WILL_PROFIT_PRICE"].ToString().Trim());
                                tmp.not_commission_profit_loss = int.Parse(rdr["NOT_COMMISSION_PROFIT_AND_LOSS"].ToString().Trim());
                                tmp.profit_loss_rt             = float.Parse(rdr["NOT_COMMISSION_PROFIT_AND_LOSS_RATE"].ToString().Trim());
                                tmp.order_status               = 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());
                }
            }
        }
示例#4
0
        private void autoSale(TB_OPT10085 opt10085_data)
        {
            FileLog.PrintF("autoSale loss_status=>" + loss_status + ",loss_rate=>" + loss_rate + ",종목코드=>" + opt10085_data.stock_cd + ",손익율=>" + opt10085_data.profit_loss_rt + ",주문상태=>" + opt10085_data.order_status);
            //주식체결 정보가 들어와서 주식 현재가가 변동이 있을때 자동 판매로직이 실행됨
            /*손절매*/
            if (loss_status == true)
            {
                if (opt10085_data.profit_loss_rt <= this.loss_rate && opt10085_data.order_status == 1)//주문상태가 1 즉 보여상태이어야한다.
                {
                    if (MyOrder.getClass1Instance().ExistsOrder(opt10085_data.stock_cd) == false)
                    {
                        //매도주문

                        int    nOrderType  = 2;//신규메도
                        String sCode       = opt10085_data.stock_cd;
                        String sScreenNo   = ScreenNumber.getClass1Instance().GetAnyTimeScrNum();
                        int    nQty        = opt10085_data.possession_qty;
                        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.order_status = 2;
                        dbUpdateOrderStatus(opt10085_data);
                    }
                }
            }
            /*이익실현*/
            if (profit_status == true)
            {
                if (opt10085_data.profit_loss_rt >= this.profit_rate && opt10085_data.order_status == 1) //주문상태가 1 즉 보여상태이어야한다.
                {
                    //매도주문
                    if (MyOrder.getClass1Instance().ExistsOrder(opt10085_data.stock_cd) == false)
                    {
                        int    nOrderType  = 2;//신규메도
                        String sCode       = opt10085_data.stock_cd;
                        int    nQty        = opt10085_data.possession_qty;
                        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.order_status = 2;
                        dbUpdateOrderStatus(opt10085_data);
                    }
                }
            }
        }
示例#5
0
        public void insertOpt10085(List <TB_OPT10085> lst)
        {
            using (var conn = new NpgsqlConnection(Config.GetDbConnStr()))
            {
                try
                {
                    conn.Open();
                    String sql = @" insert into tb_opt10085
        (
		    purchase_dt ,
			acct_num ,
			stock_cd ,
			curr_amt ,
			purchase_amt ,
			tot_purchase_amt ,
			possession_qty ,
			today_sell_profit_loss ,
			today_commission ,
			today_tax ,
			credit_gubun ,
			loan_dt ,
			payment_balance ,
			sellable_qty ,
			credit_amt ,
			credit_interest ,
			expiry_dt ,
			valuation_profit_loss ,
			earnings_rt ,
			evaluated_amt ,
			commission ,
			selling_commission ,
			buying_commission ,
			selling_tax ,
			will_profit_amt ,
			not_commission_profit_loss ,
			profit_loss_rt ,
			order_status,
			crt_dtm
        ) 
  values ( 
	        @p_purchase_dt ,
			@p_acct_num ,
			@p_stock_cd ,
			@p_curr_amt ,
			@p_purchase_amt ,
			@p_tot_purchase_amt ,
			@p_possession_qty ,
			@p_today_sell_profit_loss ,
			@p_today_commission ,
			@p_today_tax ,
			@p_credit_gubun ,
			@p_loan_dt ,
			@p_payment_balance ,
			@p_sellable_qty ,
			@p_credit_amt ,
			@p_credit_interest ,
			@p_expiry_dt ,
			@p_valuation_profit_loss ,
			@p_earnings_rt ,
			@p_evaluated_amt ,
			@p_commission ,
			@p_selling_commission ,
			@p_buying_commission ,
			@p_selling_tax ,
			@p_will_profit_amt ,
			@p_not_commission_profit_loss ,
			@p_profit_loss_rt ,
			@p_order_status,
	        now() 
	)"    ;


                    using (var cmd = new NpgsqlCommand(sql, conn))
                    {
                        for (int i = 0; i < lst.Count(); i++)
                        {
                            TB_OPT10085 tmp = lst[i];
                            //cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("@p_purchase_dt", NpgsqlTypes.NpgsqlDbType.Text, tmp.purchase_dt);
                            cmd.Parameters.AddWithValue("@p_acct_num", NpgsqlTypes.NpgsqlDbType.Text, tmp.acct_num);
                            cmd.Parameters.AddWithValue("@p_stock_cd", NpgsqlTypes.NpgsqlDbType.Text, tmp.stock_cd);
                            cmd.Parameters.AddWithValue("@p_curr_amt", NpgsqlTypes.NpgsqlDbType.Integer, tmp.curr_amt);
                            cmd.Parameters.AddWithValue("@p_purchase_amt", NpgsqlTypes.NpgsqlDbType.Integer, tmp.purchase_amt);
                            cmd.Parameters.AddWithValue("@p_tot_purchase_amt", NpgsqlTypes.NpgsqlDbType.Integer, tmp.tot_purchase_amt);
                            cmd.Parameters.AddWithValue("@p_possession_qty", NpgsqlTypes.NpgsqlDbType.Integer, tmp.possession_qty);
                            cmd.Parameters.AddWithValue("@p_today_sell_profit_loss", NpgsqlTypes.NpgsqlDbType.Integer, tmp.today_sell_profit_loss);
                            cmd.Parameters.AddWithValue("@p_today_commission", NpgsqlTypes.NpgsqlDbType.Integer, tmp.today_commission);
                            cmd.Parameters.AddWithValue("@p_today_tax", NpgsqlTypes.NpgsqlDbType.Integer, tmp.today_tax);
                            cmd.Parameters.AddWithValue("@p_credit_gubun", NpgsqlTypes.NpgsqlDbType.Text, tmp.credit_gubun);
                            cmd.Parameters.AddWithValue("@p_loan_dt", NpgsqlTypes.NpgsqlDbType.Text, tmp.loan_dt);
                            cmd.Parameters.AddWithValue("@p_payment_balance", NpgsqlTypes.NpgsqlDbType.Integer, tmp.payment_balance);
                            cmd.Parameters.AddWithValue("@p_sellable_qty", NpgsqlTypes.NpgsqlDbType.Integer, tmp.sellable_qty);
                            cmd.Parameters.AddWithValue("@p_credit_amt", NpgsqlTypes.NpgsqlDbType.Integer, tmp.credit_amt);
                            cmd.Parameters.AddWithValue("@p_credit_interest", NpgsqlTypes.NpgsqlDbType.Integer, tmp.credit_interest);
                            cmd.Parameters.AddWithValue("@p_expiry_dt", NpgsqlTypes.NpgsqlDbType.Text, tmp.expiry_dt);
                            cmd.Parameters.AddWithValue("@p_valuation_profit_loss", NpgsqlTypes.NpgsqlDbType.Integer, tmp.valuation_profit_loss);

                            cmd.Parameters.AddWithValue("@p_earnings_rt", NpgsqlTypes.NpgsqlDbType.Real, tmp.earnings_rt);
                            cmd.Parameters.AddWithValue("@p_evaluated_amt", NpgsqlTypes.NpgsqlDbType.Integer, tmp.evaluated_amt);
                            cmd.Parameters.AddWithValue("@p_commission", NpgsqlTypes.NpgsqlDbType.Integer, tmp.commission);
                            cmd.Parameters.AddWithValue("@p_selling_commission", NpgsqlTypes.NpgsqlDbType.Integer, tmp.selling_commission);
                            cmd.Parameters.AddWithValue("@p_buying_commission", NpgsqlTypes.NpgsqlDbType.Integer, tmp.buying_commission);
                            cmd.Parameters.AddWithValue("@p_selling_tax", NpgsqlTypes.NpgsqlDbType.Integer, tmp.selling_tax);
                            cmd.Parameters.AddWithValue("@p_will_profit_amt", NpgsqlTypes.NpgsqlDbType.Integer, tmp.will_profit_amt);
                            cmd.Parameters.AddWithValue("@p_not_commission_profit_loss", NpgsqlTypes.NpgsqlDbType.Integer, tmp.not_commission_profit_loss);
                            cmd.Parameters.AddWithValue("@p_profit_loss_rt", NpgsqlTypes.NpgsqlDbType.Real, tmp.profit_loss_rt);
                            cmd.Parameters.AddWithValue("@p_order_status", NpgsqlTypes.NpgsqlDbType.Integer, tmp.order_status);
                            cmd.ExecuteNonQuery();
                            cmd.Parameters.Clear();
                        }
                    }
                }
                catch (Exception ex)
                {
                    FileLog.PrintF("[insertOpt10085]Exception ex=" + ex.Message);
                    //{ "42883: insert_tb_stock(p_market_cd => text, p_stock_cd => text, p_stock_nm => text, p_stock_dt => text, p_cnt => integer, p_last_price => text, p_stock_state => text, p_construction => text) 이름의 함수가 없음"}
                    //		Message	"42601: 구문 오류, 입력 끝부분"	string
                }
            }
        }
示例#6
0
        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
                                             , 계좌번호
                                             );

            spell = AppLib.getClass1Instance().getSpell(key).ShallowCopy();

            List <TB_OPT10085> opt10085_DataList = new List <TB_OPT10085>();


            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]



                    TB_OPT10085 opt10085_Data = new TB_OPT10085();
                    opt10085_Data.purchase_dt = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "일자").Trim();                             //[0]
                    opt10085_Data.stock_cd    = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "종목코드").Trim();                           //[1]
                    int 현재가 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "현재가").Trim());                                 //[3]
                    opt10085_Data.curr_amt     = 현재가;
                    opt10085_Data.purchase_amt = 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.tot_purchase_amt = 매입금액;
                    int 보유수량 = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "보유수량").Trim());                               //[6]
                    opt10085_Data.possession_qty         = 보유수량;
                    opt10085_Data.today_sell_profit_loss = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매도손익").Trim()); //[7]
                    String str당일매매수수료 = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매수수료");
                    opt10085_Data.today_commission = 0;
                    if (isNotNull(str당일매매수수료) == true)
                    {
                        opt10085_Data.today_commission = Int32.Parse(str당일매매수수료.Trim());                                                //[8]
                    }
                    opt10085_Data.today_tax       = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "당일매매세금").Trim()); //[9]
                    opt10085_Data.credit_gubun    = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용구분").Trim();                //[10]
                    opt10085_Data.loan_dt         = axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "대출일").Trim();                 //[11]
                    opt10085_Data.payment_balance = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "결제잔고").Trim());   //[12]
                    opt10085_Data.sellable_qty    = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "청산가능수량").Trim()); //[13]
                    opt10085_Data.credit_amt      = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용금액").Trim());   //[14]
                    opt10085_Data.credit_interest = Int32.Parse(axKHOpenAPI.CommGetData(e.sTrCode, "", e.sRQName, i, "신용이자").Trim());   //[15]
                    opt10085_Data.expiry_dt       = 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.evaluated_amt              = 평가금액;
                    opt10085_Data.selling_commission         = 매입수수료;
                    opt10085_Data.buying_commission          = 매도수수료;
                    opt10085_Data.commission                 = 수수료;
                    opt10085_Data.selling_tax                = 매도세금;
                    opt10085_Data.will_profit_amt            = 손익분기매입가;
                    opt10085_Data.valuation_profit_loss      = 평가손익;
                    opt10085_Data.earnings_rt                = 수익률;
                    opt10085_Data.not_commission_profit_loss = 손익금액;
                    opt10085_Data.profit_loss_rt             = 손익율;
                    opt10085_Data.acct_num = 계좌번호;


                    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);
                }
            }

            //이것은 연속적이지 않기 때문에 바로 제거 한다.
            AppLib.getClass1Instance().removeSpellDictionary(spell.key);
            int    position = spell.key.LastIndexOf("|");
            String key1     = spell.key.Substring(0, position);

            AppLib.getClass1Instance().removeStockCodeDictionary(key1);
            //래치를 호출해서 잠김을 제거한다.--래치 일단 제거 호출하는데도 제거 했다. 1초에 5번 호출 규칙만 적용해보자.
            AppLib.getClass1Instance().setOpt10081(spell.sTrCode);

            DailyData dd = new DailyData();

            dd.insertOpt10085(opt10085_DataList);
        }