From 709a7bc83c27123f4f1439b04f5eb6763f58ac85 Mon Sep 17 00:00:00 2001 From: Hayot Date: Sun, 1 Sep 2024 17:28:10 +0900 Subject: [PATCH] feat: add helpers --- src/api.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 3 +++ src/models.rs | 7 +++++++ 3 files changed, 68 insertions(+) diff --git a/src/api.rs b/src/api.rs index f497e09..cf01e62 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,9 +1,16 @@ use crate::candle::Candle; use crate::client::Client; +use crate::forex::Forex; use crate::fundingrate::FundingRate; +use crate::google::GoogleTrend; +use crate::naver::NaverTrend; + pub enum API { CandleApi(CandleApi), FundingRateApi(FundingRateApi), + ForexApi(ForexApi), + NaverTrendApi(NaverTrendApi), + GoogleTrendApi(GoogleTrendApi), } pub enum CandleApi { @@ -20,6 +27,21 @@ pub enum FundingRateApi { LatestFundingRate, } +pub enum ForexApi { + Symbols, + Forex, +} + +pub enum NaverTrendApi { + Symbols, + Trend, +} + +pub enum GoogleTrendApi { + Keywords, + Trend, +} + impl From for String { fn from(item: API) -> Self { String::from(match item { @@ -35,6 +57,18 @@ impl From for String { FundingRateApi::HistoricalFundingRate => "/funding-rate", FundingRateApi::LatestFundingRate => "/funding-rate/latest", }, + API::ForexApi(route) => match route { + ForexApi::Symbols => "/forex/symbols", + ForexApi::Forex => "/forex", + }, + API::NaverTrendApi(route) => match route { + NaverTrendApi::Symbols => "/naver/symbols", + NaverTrendApi::Trend => "/naver/trend", + }, + API::GoogleTrendApi(route) => match route { + GoogleTrendApi::Keywords => "/google/keywords", + GoogleTrendApi::Trend => "/google/trend", + }, }) } } @@ -58,3 +92,27 @@ impl Datamaxi for FundingRate { } } } + +impl Datamaxi for Forex { + fn new(api_key: String) -> Forex { + Forex { + client: Client::new(api_key), + } + } +} + +impl Datamaxi for NaverTrend { + fn new(api_key: String) -> NaverTrend { + NaverTrend { + client: Client::new(api_key), + } + } +} + +impl Datamaxi for GoogleTrend { + fn new(api_key: String) -> GoogleTrend { + GoogleTrend { + client: Client::new(api_key), + } + } +} diff --git a/src/lib.rs b/src/lib.rs index c5619f0..b9650e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,9 @@ pub mod client; pub mod api; pub mod candle; pub mod error; +pub mod forex; pub mod fundingrate; +pub mod google; pub mod models; +pub mod naver; pub mod utils; diff --git a/src/models.rs b/src/models.rs index 1a61ac4..ec8163b 100644 --- a/src/models.rs +++ b/src/models.rs @@ -50,3 +50,10 @@ pub struct LatestFundingRateDetail { pub q: String, pub r: f64, } + +#[derive(Deserialize, Debug)] +pub struct ForexDetail { + pub s: String, + pub d: i64, + pub r: f64, +}