-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from book-io/add-some-missing-endpoints
Add a few missing endpoints and bug fixes
- Loading branch information
Showing
9 changed files
with
126 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::models::markets::{DexPairOHLC, DexPairOHLCParameters}; | ||
|
||
use super::maestro::Maestro; | ||
use std::{error::Error, fmt::Display}; | ||
|
||
impl Maestro { | ||
/// Returns market activity in candlestick OHLC format for a specific DEX and token pair | ||
pub async fn markets_dex_pair_ohlc( | ||
&self, | ||
dex: impl Display, | ||
pair: impl Display, | ||
parameters: Option<DexPairOHLCParameters>, | ||
) -> Result<Vec<DexPairOHLC>, Box<dyn Error>> { | ||
let ps = parameters | ||
.and_then(|p| serde_qs::to_string(&p).ok()) | ||
.map(|x| format!("?{x}")) | ||
.unwrap_or_default(); | ||
let url = format!("/markets/dexs/ohlc/{dex}/{pair}{ps}"); | ||
let resp = self.get(&url).await?; | ||
|
||
serde_json::from_str(&resp).map_err(|e| Box::new(e) as Box<dyn Error>) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use chrono::{DateTime, Utc}; | ||
use rust_decimal::Decimal; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, Deserialize)] | ||
pub struct DexPairOHLC { | ||
pub coin_a_change_pct: Decimal, | ||
pub coin_a_close: Decimal, | ||
pub coin_a_high: Decimal, | ||
pub coin_a_low: Decimal, | ||
pub coin_a_open: Decimal, | ||
pub coin_a_volume: Decimal, | ||
pub coin_b_change_pct: Decimal, | ||
pub coin_b_close: Decimal, | ||
pub coin_b_high: Decimal, | ||
pub coin_b_low: Decimal, | ||
pub coin_b_open: Decimal, | ||
pub coin_b_volume: Decimal, | ||
pub count: i64, | ||
pub timestamp: DateTime<Utc>, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Serialize)] | ||
pub enum Resolution { | ||
#[serde(rename = "1m")] | ||
OneMinute, | ||
#[serde(rename = "5m")] | ||
FiveMinutes, | ||
#[serde(rename = "15m")] | ||
FifteenMinutes, | ||
#[serde(rename = "30m")] | ||
ThirtyMinutes, | ||
#[serde(rename = "1h")] | ||
OneHour, | ||
#[serde(rename = "4h")] | ||
FourHours, | ||
#[serde(rename = "1d")] | ||
OneDay, | ||
#[serde(rename = "1w")] | ||
OneWeek, | ||
#[serde(rename = "1mo")] | ||
OneMonth, | ||
} | ||
|
||
#[derive(Clone, Copy, Debug, Serialize)] | ||
pub enum Sort { | ||
#[serde(rename = "asc")] | ||
Asc, | ||
#[serde(rename = "desc")] | ||
Desc, | ||
} | ||
|
||
#[derive(Clone, Debug, Default, Serialize)] | ||
pub struct DexPairOHLCParameters { | ||
pub resolution: Option<Resolution>, | ||
pub from: Option<String>, | ||
pub to: Option<String>, | ||
pub limit: Option<i64>, | ||
pub sort: Option<Sort>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters