#api #client #stock #trading #korea-investment

bin+lib korea-investment-api

Korea Investment API client for Rust(Not official)

5 releases (stable)

new 1.1.7 Feb 24, 2024
1.1.2 Feb 12, 2024
1.0.0 Dec 31, 2023
0.3.0 Oct 28, 2023

#1508 in Web programming

Download history 4/week @ 2023-11-03 1/week @ 2023-11-10 2/week @ 2023-11-17 3/week @ 2023-11-24 5/week @ 2023-12-01 1/week @ 2023-12-15 2/week @ 2023-12-22 36/week @ 2023-12-29 2/week @ 2024-01-05 2/week @ 2024-01-12 4/week @ 2024-01-26 2/week @ 2024-02-02 114/week @ 2024-02-09 151/week @ 2024-02-16

271 downloads per month

MIT license

105KB
2.5K SLoC

한국투자증권 API for Rust

현재 지원되는 기능

  • 인증
  • 국내 주식 주문
    • 현금주문
    • 정정/취소
  • 국내 주식 시세
    • 일자별
    • 거래량순위
  • 실시간 시세
    • 체결
    • 호가
    • 체결통보

사용 방법

  • 구조체 생성
use korea_investment_api::{KoreaInvestmentApi, Environment, Account, Error};

static APPKEY: &'static str = "some-app-key";
static APPSECRET: &'static str = "some-app-secret";
static CANO: &'static str = "12345678";
static ACNT_PRDT_CD: &'static str = "01";
static HTS_ID: &'static str = "my-hts-id";

async fn get_api() -> Result<KoreaInvestmentApi, Error> {
    let account = Account {
        cano: CANO.to_string(),
        acnt_prdt_cd: ACNT_PRDT_CD.to_string(),
    };
    KoreaInvestmentApi::new(
        Environment::Virtual, // 실전투자: Real, 모의투자: Virtual
        APPKEY,
        APPSECRET,
        account,
        HTS_ID,
    ).await
}
  • API 사용
use korea_investment_api::types::{MarketCode, PeriodCode, TrId};

#[tokio::main]
async fn main() {
    let api = get_api().await.unwrap();

    // 삼성전자 일자별 가격(단일 API 호출)
    let samsung_electronics_daily_prices = api.quote.daily_price(
        MarketCode::Stock, // 주식(Stock) vs ETF(Etf)
        "005930", // 6자리 종목 코드
        PeriodCode::ThirtyDays, // 기간 코드(ThirtyDays(30일), ThirtyWeeks(30주), ThirtyMonths(30달))
        false, // 수정주가 원주가 가격 여부(수정주가 반영: true)
    ).await;
    
    // 삼성전자 호가 실시간 시세 구독
    let subscribe_response = api.k_data.subscribe_market("KR7005930003", TrId::RealtimeOrdb).unwrap();

    // 구독한 시세 읽기
    while let Ok(ordb) = api.k_data.ordb_recv() {
        println!("Got orderbook: {:?}", ordb);
    }
}

Dependencies

~12–26MB
~413K SLoC