Skip to content

Commit

Permalink
external-api: add get_quote_amount helper
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Dec 16, 2024
1 parent e26c7a6 commit 58b3211
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 58b3211

Please sign in to comment.