본문 바로가기
키움자동매매

tr-opt20009(업종년봉조회요청)

by Knowledge Store In Hyunsoft 2022. 10. 10.

tr-opt20009(업종년봉조회요청)

  • REQUEST Code
string trCd = "opt20009";

// 시장구분 = 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 "opt20009": // 업종년봉조회요청 
            funcOpt20009(sender, e);
            break;
    }
}

// 업종년봉조회요청 
private void funcOpt20009(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 funcOpt20009 (업종년봉조회요청) -->");
        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 funcOpt20009 (업종년봉조회요청) -->");
    }
    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
20221007 -2232.84 5 -5.02 -0.22 428682
20221006 +2237.86 2 +22.64 +1.02 643015
20221005 +2215.22 2 +5.84 +0.26 855790
20221004 +2209.38 2 +53.89 +2.50 421003
20220930 -2155.49 5 -15.44 -0.71 950269
20220929 +2170.93 2 +1.64 +0.08 508500
20220928 -2169.29 5 -54.57 -2.45 596136
20220927 +2223.86 2 +2.92 +0.13 487939
20220926 -2220.94 5 -69.06 -3.02 621995
20220923 -2290.00 5 -42.31 -1.81 446460
20220922 -2332.31 5 -14.90 -0.63 446820
20220921 -2347.21 5 -20.64 -0.87 378165
20220920 +2367.85 2 +12.19 +0.52 419340
20220919 -2355.66 5 -27.12 -1.14 403937
20220916 -2382.78 5 -19.05 -0.79 440798
20220915 -2401.83 5 -9.59 -0.40 424110
20220914 -2411.42 5 -38.12 -1.56 461507
20220913 +2449.54 2 +65.26 +2.74 367102
20220908 +2384.28 2 +7.82 +0.33 423620
20220907 -2376.46 5 -33.56 -1.39 378200

 

키움 open-api TR 목록

728x90

댓글