Skip to content

Commit

Permalink
feat: add helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
hayotbisonai committed Sep 1, 2024
1 parent 65c8a42 commit 709a7bc
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<API> for String {
fn from(item: API) -> Self {
String::from(match item {
Expand All @@ -35,6 +57,18 @@ impl From<API> 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",
},
})
}
}
Expand All @@ -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),
}
}
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 7 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

0 comments on commit 709a7bc

Please sign in to comment.