示例#1
0
        //----------------------------------------------------------- Event  -----------------------------------------------------------

        //---------------------------------------------- 키움 OpenApi TR 요청 결과 처리부 ----------------------------------------------
        private void trAccountBalance(AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            long totalValuationAmount = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, 0, "총평가손익금액"));
            long estimatedBalance     = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, 0, "추정예탁자산"));

            this.AccountBalanceEvent(totalValuationAmount, estimatedBalance);

            int cnt = openApi.GetRepeatCnt(e.sTrCode, e.sRQName);

            this.holdings.Clear();

            for (int i = 0; i < cnt; i++)
            {
                string stockNo       = openApi.GetCommData(e.sTrCode, e.sRQName, i, "종목번호").Trim().Replace("A", "");
                string stockName     = openApi.GetCommData(e.sTrCode, e.sRQName, i, "종목명").Trim();
                long   currentPrice  = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "현재가").Trim());
                int    qty           = int.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "보유수량").Trim());
                long   buyPrice      = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "매입가").Trim());
                long   totalBuyPrice = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "매입금액").Trim());
                long   profit        = long.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "평가손익").Trim());
                float  profitRate    = float.Parse(openApi.GetCommData(e.sTrCode, e.sRQName, i, "수익률(%)").Trim());

                this.holdings.Add(new Holding(stockNo, stockName, currentPrice, qty, buyPrice, totalBuyPrice, profit, profitRate, loginInfo.getServerGubun));
            }

            if (this.holdings.Count > 0)
            {
                string codeList = string.Join(";", holdings.Select(item => item.StockNo));

                // 실시간 시세 요청
                requestRealtimeQuote(SCREEN_NO_ACCOUNT_INFO, codeList, REALTIME_NEW);
            }
        }
示例#2
0
        // 콜백 함수 내에서 사용되어야 함
        internal static TOut GetSingleData <TOut>(this AxKHOpenAPI api, TOut instance = null) where TOut : EntityBase
        {
            if (instance == null)
            {
                instance = Activator.CreateInstance <TOut>();
            }
            var type   = instance.GetType();
            var tAttri = type.GetCustomAttribute <TransactionAttribute>(true);

            foreach (var property in instance.GetOutputProperties())
            {
                //var name = property.GetName<OutputAttribute>();
                //if (string.IsNullOrEmpty(name))
                if (string.IsNullOrEmpty(property.Name))
                {
                    continue;
                }

                //var result = api.CommGetData(tAttri.TRCode, "", tAttri.Name, 0, property.Name).Trim();
                var result = api.GetCommData(tAttri.TRCode, tAttri.Name + "요청", 0, property.Name.TrimStart('D')).Trim();
                //Console.WriteLine("[tAttri.TRCode]=" + tAttri.TRCode);
                //Console.WriteLine("[tAttri.Name]=" + tAttri.Name+"요청");
                Console.WriteLine(property.Name + " => " + result);
                //axKHOpenAPI1.SetInputValue("종목코드", obj.itemCode);

                property.SetValue(instance, result);
            }

            return(instance);
        }
示例#3
0
        /// <summary>
        ///[24]설명 수신 데이터를 반환한다.
        ///입력값
        ///strTrCode – Tran 코드
        ///strRecordName – 레코드명
        ///nIndex – 복수데이터 인덱스
        ///strItemName – 아이템명
        ///반환값 수신 데이터
        ///비고 Ex)현재가출력 - openApi.GetCommData(“OPT00001”, “주식기본정보”, 0, “현재가”);
        /// </summary>
        public String GetCommData(String strTrCode, String strRecordName, int nIndex, String strItemName)
        {
            String ret = axKHOpenAPI.GetCommData(strTrCode, strRecordName, nIndex, strItemName);

            FileLog.PrintF("GetCommData(" + strTrCode + "," + strRecordName + "," + nIndex + "," + strItemName + "):" + ret);
            return(ret);
        }
示例#4
0
 public string getData(string key, int idx)
 {
     return(m_gateway.GetCommData(m_trcode, m_reqName, idx, key));
 }
示例#5
0
        public void axKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            if (e.sRQName.Contains(ConstName.RECEIVE_TR_DATA_HOGA))
            {
                StockWithBiddingEntity newObj = new StockWithBiddingEntity();

                string[] rqNameArray = e.sRQName.Split(':');
                if (rqNameArray.Length == 3)
                {
                    string itemCode = rqNameArray[1];
                    newObj.Code = itemCode;
                }
                for (int i = 0; i < 10; i++)
                {
                    if (i == 9)
                    {
                        Console.WriteLine("매도 최우선호가 / 잔량 ");
                        string firstSellHoga = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매도최우선호가").Trim().Replace("+", "");
                        string firstSellQnt  = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매도최우선잔량").Trim();
                        if (!string.IsNullOrEmpty(firstSellHoga))
                        {
                            newObj.SetSellHoga(i, long.Parse(firstSellHoga));
                        }
                        if (!string.IsNullOrEmpty(firstSellQnt))
                        {
                            newObj.SetSellQnt(i, long.Parse(firstSellQnt));
                        }
                    }
                    else
                    {
                        Console.WriteLine("매도" + (10 - i) + "차선호가 /잔량");
                        string hoga = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매도" + (10 - i) + "차선호가").Trim().Replace("+", ""));
                        string qnt  = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매도" + (10 - i) + "차선잔량").Trim());

                        if (!string.IsNullOrEmpty(hoga))
                        {
                            newObj.SetSellHoga(i, long.Parse(hoga));
                        }
                        if (!string.IsNullOrEmpty(qnt))
                        {
                            newObj.SetSellQnt(i, long.Parse(qnt));
                        }
                    }
                }
                for (int i = 0; i < 10; i++)
                {
                    if (i == 0)
                    {
                        Console.WriteLine("매수 최우선호가 / 잔량 ");
                        string firstBuyHoga = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매수최우선호가").Trim().Replace("+", ""));
                        string firstBuyQnt  = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매수최우선잔량").Trim());
                        if (!string.IsNullOrEmpty(firstBuyHoga))
                        {
                            newObj.SetBuyHoga(i, long.Parse(firstBuyHoga));
                        }
                        if (!string.IsNullOrEmpty(firstBuyQnt))
                        {
                            newObj.SetBuyQnt(i, long.Parse(firstBuyQnt));
                        }
                    }
                    else
                    {
                        Console.WriteLine("매수" + (i + 1) + "차선호가 / 잔량");
                        string hoga = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매수" + (i + 1) + "차선호가").Trim().Replace("+", ""));
                        string qnt  = (axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "매수" + (i + 1) + "차선잔량").Trim());
                        if (!string.IsNullOrEmpty(hoga))
                        {
                            newObj.SetBuyHoga(i, long.Parse(hoga));
                        }
                        if (!string.IsNullOrEmpty(qnt))
                        {
                            newObj.SetBuyQnt(i, long.Parse(qnt));
                        }
                    }
                }
                StockWithBiddingManager.GetInstance().SetItem(newObj);
            }
        }
示例#6
0
        private void OnReceiveTrData(object sender, _DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            var temp = axAPI.GetCommDataEx(e.sTrCode, e.sRQName);

            if (temp != null)
            {
                string[,] ts = new string[((object[, ])temp).GetUpperBound(0) + 1, ((object[, ])temp).GetUpperBound(1) + 1];
                int x, y, lx = ((object[, ])temp).GetUpperBound(0), ly = ((object[, ])temp).GetUpperBound(1);

                for (x = 0; x <= lx; x++)
                {
                    sb = new StringBuilder(64);

                    for (y = 0; y <= ly; y++)
                    {
                        ts[x, y] = (string)((object[, ])temp)[x, y];

                        if (ts[x, y].Length > 13 && !e.sTrCode.Equals("opt50001") && Retention.Equals(ts[x, y].Substring(2)))
                        {
                            sb          = new StringBuilder(it);
                            e.sPrevNext = "0";

                            break;
                        }
                        sb.Append(ts[x, y]);

                        if (y != ly)
                        {
                            sb.Append(",");
                        }
                    }
                    if (!e.sTrCode.Equals("opt50001") && sb.ToString() != it)
                    {
                        SendMemorize?.Invoke(this, new MemorizeEvent(sb));

                        continue;
                    }
                    if (sb.ToString() == it)
                    {
                        break;
                    }

                    if (e.sTrCode.Equals("opt50001"))
                    {
                        Remaining = axAPI.GetCommData(e.sTrCode, e.sRQName, 0, "잔존일수").Trim();

                        return;
                    }
                }
                if (e.sPrevNext.Equals("2") && !e.sTrCode.Equals("opt50001"))
                {
                    rq = new Task(() =>
                    {
                        tr = new Opt50028
                        {
                            Value    = Code,
                            RQName   = Code + Retention,
                            PrevNext = 2
                        };
                        InputValueRqData(tr);
                    });
                    request.RequestTrData(rq);

                    return;
                }
                if (e.sPrevNext.Equals("0") && !e.sTrCode.Equals("opt50001"))
                {
                    SendMemorize?.Invoke(this, new MemorizeEvent(e.sPrevNext));
                }
            }
        }