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

bin+lib korea-investment-api

Korea Investment API client for Rust(Not official)

10 stable releases

1.3.0 Mar 8, 2024
1.2.3 Mar 8, 2024
1.1.7 Feb 24, 2024
1.0.0 Dec 31, 2023
0.3.0 Oct 28, 2023

#506 in Web programming

Download history 4/week @ 2023-12-28 39/week @ 2024-02-08 24/week @ 2024-02-15 373/week @ 2024-02-22 67/week @ 2024-02-29 894/week @ 2024-03-07 60/week @ 2024-03-14 1/week @ 2024-03-21 61/week @ 2024-03-28 30/week @ 2024-04-04

93 downloads per month

MIT license

110KB
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

~13–28MB
~429K SLoC