Skip to content

Commit

Permalink
auth-server: add order attrributes to bundle logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Jan 17, 2025
1 parent 809e954 commit 0baff09
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
41 changes: 37 additions & 4 deletions auth/auth-server/src/server/handle_external_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use renegade_common::types::{token::Token, TimestampedPrice};

use super::Server;
use crate::error::AuthServerError;
use crate::telemetry::helpers::calculate_implied_price;
use crate::telemetry::{
helpers::{
await_settlement, record_endpoint_metrics, record_external_match_metrics, record_fill_ratio,
Expand Down Expand Up @@ -157,9 +158,10 @@ impl Server {
let match_resp: ExternalMatchResponse =
serde_json::from_slice(resp).map_err(AuthServerError::serde)?;

let request_id = uuid::Uuid::new_v4().to_string();
let labels = vec![
(KEY_DESCRIPTION_METRIC_TAG.to_string(), key.clone()),
(REQUEST_ID_METRIC_TAG.to_string(), uuid::Uuid::new_v4().to_string()),
(REQUEST_ID_METRIC_TAG.to_string(), request_id.clone()),
(DECIMAL_CORRECTION_FIXED_METRIC_TAG.to_string(), "true".to_string()),
];

Expand All @@ -177,7 +179,7 @@ impl Server {
}

// Log the bundle and record metrics
self.log_bundle(resp)?;
self.log_bundle(&order, resp, &request_id)?;
record_external_match_metrics(&order, match_resp, key, did_settle).await?;

Ok(())
Expand All @@ -203,17 +205,48 @@ impl Server {
}

/// Log the bundle parameters
fn log_bundle(&self, bundle_bytes: &[u8]) -> Result<(), AuthServerError> {
fn log_bundle(
&self,
order: &ExternalOrder,
bundle_bytes: &[u8],
request_id: &str,
) -> Result<(), AuthServerError> {
let resp = serde_json::from_slice::<ExternalMatchResponse>(bundle_bytes)
.map_err(AuthServerError::serde)?;

// Get the decimal-corrected price
let price = calculate_implied_price(&resp.match_bundle, true /* decimal_correct */)?;
let price_fixed = FixedPoint::from_f64_round_down(price);

let match_result = resp.match_bundle.match_result;
let is_buy = match_result.direction;
let recv = resp.match_bundle.receive;
let send = resp.match_bundle.send;

// Get the base fill ratio
let requested_base_amount = order.get_base_amount(price_fixed);
let response_base_amount = match_result.base_amount;
let base_fill_ratio = response_base_amount as f64 / requested_base_amount as f64;

// Get the quote fill ratio
let requested_quote_amount = order.get_quote_amount(price_fixed);
let matched_quote_amount = match_result.quote_amount;
let quote_fill_ratio = matched_quote_amount as f64 / requested_quote_amount as f64;

info!(
requested_base_amount = requested_base_amount,
response_base_amount = response_base_amount,
requested_quote_amount = requested_quote_amount,
matched_quote_amount = matched_quote_amount,
base_fill_ratio = base_fill_ratio,
quote_fill_ratio = quote_fill_ratio,
request_id = request_id,
"Sending bundle(is_buy: {}, recv: {} ({}), send: {} ({})) to client",
is_buy, recv.amount, recv.mint, send.amount, send.mint
is_buy,
recv.amount,
recv.mint,
send.amount,
send.mint
);

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions auth/auth-server/src/telemetry/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ pub(crate) async fn record_external_match_metrics(

// Get decimal-corrected price
let price = calculate_implied_price(&match_resp.match_bundle, true /* decimal_correct */)?;
let price_fixed = FixedPoint::from_f64_round_down(price);
let price_fixed_f64 = price_fixed.to_f64();

// Record request metrics
if let Err(e) = record_external_match_request_metrics(order, price, &labels) {
Expand Down

0 comments on commit 0baff09

Please sign in to comment.