// 콜백 함수 내에서 사용되어야 함 internal static IList <T> GetMultiData <T>(this AxKHOpenAPI api) where T : EntityBase { var tAttri = typeof(T).GetCustomAttribute <TransactionAttribute>(true); var properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty); var cnt = api.GetRepeatCnt(tAttri.TRCode, tAttri.Name); var datacnt = api.GetDataCount(tAttri.Name); var list = new List <T>(); for (int i = 0; i < cnt; i++) { Console.WriteLine("### Loop = " + i); var entity = Activator.CreateInstance <T>(); foreach (var property in properties) { var cAttri = property.GetCustomAttribute <OutputAttribute>(true); if (cAttri == null) { continue; } var result = api.CommGetData(tAttri.TRCode, "", tAttri.Name, i, cAttri.Name).Trim(); property.SetValue(entity, result); Console.WriteLine("{0},{1},{2},{3} : {4}", i, tAttri.TRCode, tAttri.Name, cAttri.Name, result); } list.Add(entity); } return(list); }
/// <summary> ///[11]설명 레코드 반복횟수를 반환한다. ///입력값 sTrCode – Tran 명 ///입력값 sRecordName – 레코드 명 ///반환값 레코드의 반복횟수 ///비고 Ex) openApi.GetRepeatCnt(“OPT00001”, “주식기본정보”); /// </summary> public int GetRepeatCnt(String sTrCode, String sRecordName) { int ret = axKHOpenAPI.GetRepeatCnt(sTrCode, sRecordName); FileLog.PrintF("GetRepeatCnt(" + sTrCode + "," + sRecordName + "):" + ret); return(ret); }
//----------------------------------------------------------- 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); } }
internal static int GetCount <T>(this AxKHOpenAPI api) where T : EntityBase { var tAttri = typeof(T).GetCustomAttribute <TransactionAttribute>(true); Console.WriteLine("[tAttri.TRCode]" + tAttri.TRCode); Console.WriteLine("[tAttri.Name]" + tAttri.Name); var cnt = api.GetRepeatCnt(tAttri.TRCode, tAttri.Name); Console.WriteLine("[cnt]" + cnt); var datacnt = api.GetDataCount(tAttri.Name); return(datacnt); }