-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All Trades endpoint #71
Conversation
if let Some(base_asset) = &self.base_asset { | ||
match &base_asset.0 { | ||
AssetType::Native => { | ||
query.push(format!("base_asset_type=native")); | ||
} | ||
AssetType::Alphanumeric4(asset) => { | ||
query.push(format!("base_asset_type=credit_alphanum4")); | ||
query.push(format!("&base_asset_code={}", asset.asset_code)); | ||
query.push(format!("&base_asset_issuer={}", asset.asset_issuer)); | ||
} | ||
AssetType::Alphanumeric12(asset) => { | ||
query.push(format!("base_asset_type=credit_alphanum12")); | ||
query.push(format!("&base_asset_code={}", asset.asset_code)); | ||
query.push(format!("&base_asset_issuer={}", asset.asset_issuer)); | ||
} | ||
} | ||
} | ||
|
||
if let Some(base_asset) = &self.base_asset { | ||
match &base_asset.0 { | ||
AssetType::Native => { | ||
query.push(format!("&counter_asset_type=native")); | ||
} | ||
AssetType::Alphanumeric4(asset) => { | ||
query.push(format!("&counter_asset_type=credit_alphanum4")); | ||
query.push(format!("&counter_asset_code={}", asset.asset_code)); | ||
query.push(format!("&counter_asset_issuer={}", asset.asset_issuer)); | ||
} | ||
AssetType::Alphanumeric12(asset) => { | ||
query.push(format!("&counter_asset_type=credit_alphanum12")); | ||
query.push(format!("&counter_asset_code={}", asset.asset_code)); | ||
query.push(format!("&counter_asset_issuer={}", asset.asset_issuer)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is deze code nu duplicaat? De check lijkt hetzelfde, maar de implementatie verschilt licht. Wellicht bedoelde je bij de 2e check geen base_asset
maar een counter_asset
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ja, klopt helemaal wat je zegt.
impl Request for AllTradesRequest { | ||
fn get_query_parameters(&self) -> String { | ||
let mut query: Vec<String> = Vec::new(); | ||
|
||
if let Some(base_asset) = &self.base_asset { | ||
match &base_asset.0 { | ||
AssetType::Native => { | ||
query.push(format!("base_asset_type=native")); | ||
} | ||
AssetType::Alphanumeric4(asset) => { | ||
query.push(format!("base_asset_type=credit_alphanum4")); | ||
query.push(format!("&base_asset_code={}", asset.asset_code)); | ||
query.push(format!("&base_asset_issuer={}", asset.asset_issuer)); | ||
} | ||
AssetType::Alphanumeric12(asset) => { | ||
query.push(format!("base_asset_type=credit_alphanum12")); | ||
query.push(format!("&base_asset_code={}", asset.asset_code)); | ||
query.push(format!("&base_asset_issuer={}", asset.asset_issuer)); | ||
} | ||
} | ||
} | ||
|
||
if let Some(base_asset) = &self.base_asset { | ||
match &base_asset.0 { | ||
AssetType::Native => { | ||
query.push(format!("&counter_asset_type=native")); | ||
} | ||
AssetType::Alphanumeric4(asset) => { | ||
query.push(format!("&counter_asset_type=credit_alphanum4")); | ||
query.push(format!("&counter_asset_code={}", asset.asset_code)); | ||
query.push(format!("&counter_asset_issuer={}", asset.asset_issuer)); | ||
} | ||
AssetType::Alphanumeric12(asset) => { | ||
query.push(format!("&counter_asset_type=credit_alphanum12")); | ||
query.push(format!("&counter_asset_code={}", asset.asset_code)); | ||
query.push(format!("&counter_asset_issuer={}", asset.asset_issuer)); | ||
} | ||
} | ||
} | ||
query.join("") | ||
} | ||
|
||
fn build_url(&self, base_url: &str) -> String { | ||
format!( | ||
"{}/{}?{}", | ||
base_url, | ||
super::TRADES_PATH, | ||
self.get_query_parameters() | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
De code voor het ophalen van de QueryString parameters is redelijk duplicaat, met uitzondering can de counter/base prefix. Dit kun je weer samenvoegen in 1 functie. Bijvoorbeeld zoiets:
impl Request for AllTradesRequest {
fn add_asset_query(&mut self, query: &mut Vec<String>, asset: &Asset, asset_prefix: &str) {
let asset_type = match &asset.0 {
AssetType::Native => "native".to_string(),
AssetType::Alphanumeric4(asset_data) | AssetType::Alphanumeric12(asset_data) => {
let asset_type_label = if matches!(asset.0, AssetType::Alphanumeric4(_)) {
"credit_alphanum4"
} else {
"credit_alphanum12"
};
query.push(format!("&{}_asset_code={}", asset_prefix, asset_data.asset_code));
query.push(format!("&{}_asset_issuer={}", asset_prefix, asset_data.asset_issuer));
asset_type_label.to_string()
}
};
query.push(format!("{}_asset_type={}", asset_prefix, asset_type));
}
fn get_query_parameters(&self) -> String {
let mut query = Vec::new();
if let Some(base_asset) = &self.base_asset {
self.add_asset_query(&mut query, base_asset, "base");
}
if let Some(counter_asset) = &self.counter_asset {
self.add_asset_query(&mut query, counter_asset, "counter");
}
query.join("&").trim_start_matches('&').to_string()
}
fn build_url(&self, base_url: &str) -> String {
format!("{}/{}?{}", base_url, super::TRADES_PATH, self.get_query_parameters())
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dit had ik inderdaad ook gezien. Het gebeurt ook elders in de code, dus misschien kunnen we een stapje verder gaan door er een algemeen iets van te maken?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dat klinkt als een goed idee :D
pub struct Links { | ||
#[serde(rename = "self")] | ||
self_link: Link, | ||
base: Link, | ||
counter: Link, | ||
operation: Link, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gaat dit goed met de andere preludes?
Neem bijv AccountResponseLinks. Door een dedicated naam te gebruiken weten we zeker dat we niet meerdere public structs hebben met dezelfde naam (wat via een prelude voor conflicten kan zorgen).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tot nu toe gaat het goed, maar ik kan me voorstellen dat het inderdaad problemen gaat opleveren; ik ga het aanpassen. Misschien is het goed om te kijken of de andere endpoints ook van deze conventie gebuik maken. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wellicht nog wel mooi om je voorstel mee te nemen om die ene match lus voor base_asset en counter_asset generiek te maken als die elders gebruikt wordt. Mag ook buiten deze PR.
Vergeet niet deze branch te rebasen op |
ed65d80
to
d82ec46
Compare
✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)
Begins the implementation of the Trades endpoint group, starting with the All Trades endpoint.
Includes some minor test value updates in the offers endpoint group, in order for the tests to succeed.
💥 Does this PR introduce a breaking change?
No.
🤔 Checklist before submitting