tr-opt20001(업종현재가요청)
- REQUEST Code
string trCd = "opt20001";
// 시장구분 = 0:코스피, 1:코스닥, 2:코스피200
axKHOpenAPI.SetInputValue("시장구분", "0");
// 업종코드 = 001:종합(KOSPI), 002:대형주, 003:중형주, 004:소형주 101:종합(KOSDAQ), 201:KOSPI200, 302:KOSTAR, 701: KRX100 나머지 ※ 업종코드 참고
axKHOpenAPI.SetInputValue("업종코드", "001");
axKHOpenAPI.CommRqData("RQName", trCd, 0, GetScrNum());
- RESPONSE Code
//TR 조회 요구에 대한 데이터 수신 이벤트
private void axKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) {
switch (e.sTrCode.ToLower()) {
case "opt20001": // 업종현재가요청
funcOpt20001(sender, e);
break;
}
}
// 업종현재가요청
private void funcOpt20001(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e) {
try {
string[] columns = new string[] { "시간", "현재가n", "전일대비기호n", "전일대비n", "등락률n", "거래량n", "누적거래량n" };
List<string[]> list = new List<string[]>();
list.Add(columns);
Console.WriteLine("<!-- Start funcOpt20001 (업종현재가요청) -->");
int nCnt = axKHOpenAPI.GetRepeatCnt(e.sTrCode, e.sRQName);
for (int ni = 0; ni < nCnt; ni++) {
string[] row = new string[columns.Length];
for (int i = 0; i < columns.Length; i++) {
row[i] = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, ni, columns[i]).Trim();
}
list.Add(row);
}
PrintHtmlTable(list);
Console.WriteLine("<!-- End funcOpt20001 (업종현재가요청) -->");
}
catch (Exception e1) {
Console.WriteLine(e1.StackTrace);
}
}
public void PrintHtmlTable(List<string[]> list) {
string table = "<table>\r\n";
for (int i = 0; i < list.Count; i++) {
table +="<tr>";
for (int j = 0; j < list[i].Length; j++) {
table += string.Format("<td>{0}</td>", list[i][j]);
}
table +="</tr>\r\n";
}
table +="</table>";
Console.WriteLine(table);
tbLog.Text = table;
}
- RESPONSE Data Sample
시간n | 현재가n | 전일대비기호n | 전일대비n | 등락률n | 거래량n | 누적거래량n |
999999 | -2232.84 | 5 | -5.02 | -0.22 | 26421 | 428682 |
888888 | -2232.84 | 5 | -5.02 | -0.22 | 2 | 402261 |
153220 | -2232.84 | 5 | -5.02 | -0.22 | 27 | 402259 |
153040 | -2232.84 | 5 | -5.02 | -0.22 | 947 | 402232 |
153030 | -2232.79 | 5 | -5.07 | -0.23 | 2951 | 401285 |
153020 | -2232.37 | 5 | -5.49 | -0.25 | 3909 | 398334 |
153010 | -2234.49 | 5 | -3.37 | -0.15 | 2237 | 394425 |
152000 | -2234.16 | 5 | -3.70 | -0.17 | 339 | 392188 |
151950 | -2234.02 | 5 | -3.84 | -0.17 | 337 | 391849 |
151940 | -2233.39 | 5 | -4.47 | -0.20 | 305 | 391512 |
151930 | -2233.43 | 5 | -4.43 | -0.20 | 312 | 391207 |
151920 | -2233.45 | 5 | -4.41 | -0.20 | 337 | 390895 |
151910 | -2234.02 | 5 | -3.84 | -0.17 | 316 | 390558 |
151900 | -2234.28 | 5 | -3.58 | -0.16 | 191 | 390242 |
151850 | -2235.14 | 5 | -2.72 | -0.12 | 130 | 390051 |
151840 | -2233.94 | 5 | -3.92 | -0.18 | 207 | 389921 |
151830 | -2234.68 | 5 | -3.18 | -0.14 | 177 | 389714 |
151820 | -2233.58 | 5 | -4.28 | -0.19 | 246 | 389537 |
151810 | -2234.03 | 5 | -3.83 | -0.17 | 274 | 389291 |
151800 | -2234.61 | 5 | -3.25 | -0.15 | 194 | 389017 |
키움 open-api TR 목록
728x90
댓글