pub struct KrxEndpoints {
pub openapi_base: &'static str,
pub public_data_portal: &'static str,
pub data_marketplace: &'static str,
}
impl Default for KrxEndpoints {
fn default() -> Self {
Self {
openapi_base: "https://data-dbg.krx.co.kr",
public_data_portal: "https://apis.data.go.kr/1160100/service/GetKrxListedInfoService/getItemInfo",
data_marketplace: "http://data.krx.co.kr/comm/bldAttendant/getJsonData.cmd",
}
}
}
#[derive(Debug, Clone)]
pub enum KrxEndpoint {
KospiDailyTrading,
KospiBaseInfo,
KosdaqDailyTrading,
KosdaqBaseInfo,
KonexDailyTrading,
KonexBaseInfo,
WarrantDailyTrading,
SubscriptionWarrantDailyTrading,
IndexDailyTrading,
}
impl KrxEndpoint {
pub fn path(&self) -> &'static str {
match self {
Self::KospiDailyTrading => "/svc/apis/sto/stk_bydd_trd.json",
Self::KospiBaseInfo => "/svc/apis/sto/stk_isu_base_info.json",
Self::KosdaqDailyTrading => "/svc/apis/sto/ksq_bydd_trd.json",
Self::KosdaqBaseInfo => "/svc/apis/sto/ksq_isu_base_info.json",
Self::KonexDailyTrading => "/svc/apis/sto/knx_bydd_trd.json",
Self::KonexBaseInfo => "/svc/apis/sto/knx_isu_base_info.json",
Self::WarrantDailyTrading => "/svc/apis/sto/sw_bydd_trd.json",
Self::SubscriptionWarrantDailyTrading => "/svc/apis/sto/sr_bydd_trd.json",
Self::IndexDailyTrading => "/svc/apis/idx/idx_bydd_trd.json",
}
}
}
pub fn _format_symbol(symbol: &crate::core::types::Symbol) -> String {
symbol.base.to_uppercase()
}
pub fn _format_isin(short_code: &str) -> String {
if short_code.starts_with("KR") {
short_code.to_string()
} else {
format!("KR7{}003", short_code)
}
}
pub fn _parse_symbol(ticker: &str) -> crate::core::types::Symbol {
crate::core::types::Symbol::new(ticker, "")
}
#[derive(Debug, Clone, Copy)]
pub enum MarketId {
Kospi,
Kosdaq,
Konex,
All,
}
impl MarketId {
pub fn as_str(&self) -> &'static str {
match self {
Self::Kospi => "STK",
Self::Kosdaq => "KSQ",
Self::Konex => "KNX",
Self::All => "ALL",
}
}
pub fn daily_trading_endpoint(&self) -> KrxEndpoint {
match self {
Self::Kospi => KrxEndpoint::KospiDailyTrading,
Self::Kosdaq => KrxEndpoint::KosdaqDailyTrading,
Self::Konex => KrxEndpoint::KonexDailyTrading,
Self::All => KrxEndpoint::KospiDailyTrading, }
}
}
pub fn format_date(year: i32, month: u32, day: u32) -> String {
format!("{:04}{:02}{:02}", year, month, day)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn format_today() -> String {
use chrono::{Local, Datelike};
let now = Local::now();
format!("{:04}{:02}{:02}", now.year(), now.month(), now.day())
}