#股票 #客户端 #交易 #API客户端 #API #韩国投资

korea-investment-api-bohyuk

为Rust编写的韩国投资API客户端(非官方)

1个稳定版本

1.0.0 2024年5月31日

#23 in #股票

MIT 许可证

110KB
2.5K SLoC

韩国投资证券API for Rust

此项目是基于 korea-investment-api 的分支。

致谢

此crate是基于 Xanthorrhizol 的工作。

当前支持的功能

  • 认证
  • 国内股票订单
    • 现金订单
    • 修正/取消
  • 国内股票价格
    • 按日
    • 交易量排名
  • 实时价格
    • 成交
    • 挂单
    • 成交通知

使用方法

  • 创建结构体
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);
    }
}

依赖项

~11–25MB
~386K SLoC