KHOpenApi.NET 1.5.8

dotnet add package KHOpenApi.NET --version 1.5.8
                    
NuGet\Install-Package KHOpenApi.NET -Version 1.5.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KHOpenApi.NET" Version="1.5.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KHOpenApi.NET" Version="1.5.8" />
                    
Directory.Packages.props
<PackageReference Include="KHOpenApi.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KHOpenApi.NET --version 1.5.8
                    
#r "nuget: KHOpenApi.NET, 1.5.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KHOpenApi.NET@1.5.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KHOpenApi.NET&version=1.5.8
                    
Install as a Cake Addin
#tool nuget:?package=KHOpenApi.NET&version=1.5.8
                    
Install as a Cake Tool

KHOpenApi.NET (영웅문 / 영웅문 Global)

NuGet version

키움증권 OpenAPI를 C#에서 사용하기 위한 래퍼 라이브러리입니다.

✨ 주요 기능

  • 국내(영웅문), 해외(영웅문 Global) OpenAPI 지원
  • WPF, WinForms, WinUI3 지원
  • 비동기 로그인/요청/조건검색/주문 API 지원
    • 로그인/조건식: CommConnectAsync, GetConditionLoadAsync
    • TR 요청: CommRqDataAsync, CommKwRqDataAsync, RequestTrAsync
    • 조건검색: SendConditionAsync
    • 주문: SendOrderAsync, SendOrderFOAsync, SendOrderCreditAsync

🧩 개발 환경

  • Visual Studio 2022+
  • netstandard2.0

🚀 빠른 시작

1) WPF

MainWindow.xaml.cs

public partial class MainWindow : Window
{
    // OCX 인터페이스
    private AxKHOpenAPI axKHOpenAPI; // 국내 (영웅문)
    private AxKFOpenAPI axKFOpenAPI; // 해외 (영웅문 Global)

    public MainWindow()
    {
        InitializeComponent();

        // ActiveX 세팅
        var handle = new WindowInteropHelper(Application.Current.MainWindow).EnsureHandle();

        axKHOpenAPI = new AxKHOpenAPI(handle);
        button_login_KH.IsEnabled = axKHOpenAPI.Created;

        axKFOpenAPI = new AxKFOpenAPI(handle);
        button_login_KF.IsEnabled = axKFOpenAPI.Created;
    }

    private async void button_login_KH_Click(object sender, RoutedEventArgs e)
    {
        log_list.Items.Add("국내 로그인 요청중...");
        var (ret, msg) = await axKHOpenAPI.CommConnectAsync();
        log_list.Items.Add(ret == 0 ? "국내 로그인 성공" : $"국내 로그인 실패: {msg}");
    }

    private async void button_login_KF_Click(object sender, RoutedEventArgs e)
    {
        log_list.Items.Add("해외 로그인 요청중...");
        var (ret, msg) = await axKFOpenAPI.CommConnectAsync(1);
        log_list.Items.Add(ret == 0 ? "해외 로그인 성공" : $"해외 로그인 실패: {msg}");
    }
}

2) 비동기 API 예시

// 로그인 + 조건식 로딩 (nuget 1.5.0+)
async Task TestLoginAsync()
{
    var (nRet, sMsg) = await axKHOpenAPI.CommConnectAsync();
    if (nRet != 0)
    {
        OutLog($"로그인 실패: {sMsg}");
        return;
    }

    (nRet, sMsg) = await axKHOpenAPI.GetConditionLoadAsync();
    if (nRet != 1)
    {
        OutLog($"사용자 조건검색리스트요청 실패: {sMsg}");
        return;
    }

    var condList = sMsg.Split(';', StringSplitOptions.RemoveEmptyEntries).ToList();
    OutLog($"조건검색식 개수: {condList.Count}");
}

// TR 비동기 요청 (nuget 1.5.0+)
async Task TestRequestAsync()
{
    axKHOpenAPI.SetInputValue("종목코드", "005930");
    string itemName = string.Empty;

    var (nRet, sMsg) = await axKHOpenAPI.CommRqDataAsync("주식기본정보요청", "OPT10001", 0, "1000", e =>
    {
        itemName = axKHOpenAPI.GetCommData(e.sTrCode, e.sRQName, 0, "종목명").Trim();
    });

    if (nRet == 0)
        log_list.Items.Add(itemName);
    else
        log_list.Items.Add($"비동기 요청실패: {sMsg}");
}

// 간편 TR 요청 (nuget 1.5.3+)
async Task TestSimpleRequestAsync()
{
    var response = await api.RequestTrAsync(
        "OPT10001",
        [("종목코드", "005930")],
        ["종목명", "액면가", "영업이익", "시가", "고가", "저가", "현재가", "거래량"],
        []);

    if (response.nErrCode != 0)
    {
        print($"요청실패: {response.rsp_msg}");
        return;
    }

    // response.OutputSingleDatas / OutputMultiDatas 사용
}

// 비동기 조건검색 (nuget 1.5.3+)
async Task TestConditionAsync()
{
    var (nRet, sMsg) = await api.SendConditionAsync("8001", conditionInfo.Name, conditionInfo.Code, 0);
    if (nRet != 1)
    {
        print($"검색식 요청실패: {sMsg}");
        return;
    }

    // sMsg: 종목코드1;종목코드2;...
}

// 비동기 주문 (nuget 1.5.3+)
async Task TestOrderAsync()
{
    var (nRet, sMsg) = await axKHOpenAPI.SendOrderAsync("매수주문", "0101", 계좌번호, 1, "005930", 1, 80000, "00", string.Empty);
    if (nRet != 0)
    {
        print($"주문 요청실패: {sMsg}");
        return;
    }
}

3) WinForms

Form1.cs

public partial class Form1 : Form
{
    private AxKHOpenAPI axKHOpenAPI; // 국내 (영웅문)
    private AxKFOpenAPI axKFOpenAPI; // 해외 (영웅문 Global)

    public Form1()
    {
        InitializeComponent();

        // ActiveX 세팅
        axKHOpenAPI = new AxKHOpenAPI(Handle);

        // WPF 샘플과 동일한 방식으로 사용
    }
}

4) WinUI3

target platforms: x86/x64, UnPackaged
참고: WinUI3 x86 모드에서 글로벌 OpenAPI는 오류가 발생할 수 있으며, x64 모드에서는 정상 동작합니다.

MainWindow.xaml.cs

public sealed partial class MainWindow : Window
{
    private AxKHOpenAPI axKHOpenAPI; // 국내 (영웅문)
    private AxKFOpenAPI axKFOpenAPI; // 해외 (영웅문 Global)

    public MainWindow()
    {
        InitializeComponent();

        // ActiveX 세팅
        IntPtr handle = WinRT.Interop.WindowNative.GetWindowHandle(this);
        axKHOpenAPI = new AxKHOpenAPI(handle);

        // WPF 샘플과 동일한 방식으로 사용
    }
}


Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.5.8 81 3/15/2026
1.5.7 486 11/1/2024
1.5.6 230 10/2/2024
1.5.4 272 8/12/2024
1.5.3 279 7/21/2024
1.5.2 343 3/31/2024
1.5.1 435 2/18/2024
1.5.0 500 1/9/2024
1.4.0 562 11/5/2023
1.3.0 809 1/14/2023
1.1.0 879 9/21/2022
1.0.4 1,213 8/23/2022
1.0.3 871 8/22/2022
1.0.2 872 8/20/2022
1.0.1 847 8/19/2022
Loading failed