Skip to content
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

external-api: external_match: add get_quote_amount helper #862

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion external-api/src/http/external_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl ExternalOrder {
///
/// The price here is expected to be decimal corrected; i.e. multiplied by
/// the decimal diff for the two tokens
fn get_base_amount(&self, price: FixedPoint) -> Amount {
pub fn get_base_amount(&self, price: FixedPoint) -> Amount {
if self.base_amount != 0 {
return self.base_amount;
}
Expand All @@ -170,6 +170,20 @@ impl ExternalOrder {
scalar_to_u128(&implied_base_amount)
}

/// Get the quote amount of the order implied by the external order
///
/// The price here is expected to be decimal corrected; i.e. multiplied by
/// the decimal diff for the two tokens
pub fn get_quote_amount(&self, price: FixedPoint) -> Amount {
if self.quote_amount != 0 {
return self.quote_amount;
}

let base_amount_scalar = Scalar::from(self.base_amount);
let implied_quote_amount = price * base_amount_scalar;
scalar_to_u128(&implied_quote_amount.floor())
}

/// Get the min fill size in units of the base token
///
/// If the order size is specified in the `base_amount` field, this is
Expand Down
Loading