mirror of
https://github.com/floor-licker/polyfill-rs.git
synced 2026-08-24 18:08:10 +00:00
chore(fmt): cargo fmt
This commit is contained in:
+3
-3
@@ -660,7 +660,7 @@ impl PolyfillDemo {
|
|||||||
sequence: book.timestamp,
|
sequence: book.timestamp,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
StreamMessage::Trade(trade) => {
|
StreamMessage::Trade(trade) => {
|
||||||
info!(
|
info!(
|
||||||
" Processing trade: {} {} @ {}",
|
" Processing trade: {} {} @ {}",
|
||||||
@@ -668,10 +668,10 @@ impl PolyfillDemo {
|
|||||||
trade.size,
|
trade.size,
|
||||||
trade.price
|
trade.price
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
_ => {
|
_ => {
|
||||||
info!(" Unhandled message type");
|
info!(" Unhandled message type");
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -1942,7 +1942,10 @@ mod tests {
|
|||||||
assert_eq!(book.min_order_size, Decimal::from_str("1").unwrap());
|
assert_eq!(book.min_order_size, Decimal::from_str("1").unwrap());
|
||||||
assert!(!book.neg_risk);
|
assert!(!book.neg_risk);
|
||||||
assert_eq!(book.tick_size, Decimal::from_str("0.01").unwrap());
|
assert_eq!(book.tick_size, Decimal::from_str("0.01").unwrap());
|
||||||
assert_eq!(book.last_trade_price, Some(Decimal::from_str("0.755").unwrap()));
|
assert_eq!(
|
||||||
|
book.last_trade_price,
|
||||||
|
Some(Decimal::from_str("0.755").unwrap())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
|||||||
+6
-13
@@ -141,7 +141,7 @@ pub mod deserializers {
|
|||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(serde::de::Error::custom)
|
.map_err(serde::de::Error::custom)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
serde_json::Value::Number(n) => Decimal::from_str(&n.to_string())
|
serde_json::Value::Number(n) => Decimal::from_str(&n.to_string())
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.map_err(serde::de::Error::custom),
|
.map_err(serde::de::Error::custom),
|
||||||
@@ -168,7 +168,7 @@ pub mod deserializers {
|
|||||||
} else {
|
} else {
|
||||||
Ok(s.parse::<Decimal>().ok())
|
Ok(s.parse::<Decimal>().ok())
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
serde_json::Value::Number(n) => Ok(Decimal::from_str(&n.to_string()).ok()),
|
serde_json::Value::Number(n) => Ok(Decimal::from_str(&n.to_string()).ok()),
|
||||||
_ => Ok(None),
|
_ => Ok(None),
|
||||||
}
|
}
|
||||||
@@ -457,9 +457,9 @@ pub fn parse_stream_messages_bytes(bytes: &[u8]) -> Result<Vec<StreamMessage>> {
|
|||||||
StreamMessage::Unknown => Ok(vec![]),
|
StreamMessage::Unknown => Ok(vec![]),
|
||||||
other => Ok(vec![other]),
|
other => Ok(vec![other]),
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
Value::Array(arr) => Ok(arr
|
Value::Array(arr) => Ok(arr
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|elem| {
|
.filter_map(|elem| {
|
||||||
@@ -467,15 +467,8 @@ pub fn parse_stream_messages_bytes(bytes: &[u8]) -> Result<Vec<StreamMessage>> {
|
|||||||
let event_type = obj.get("event_type").and_then(Value::as_str)?;
|
let event_type = obj.get("event_type").and_then(Value::as_str)?;
|
||||||
// Skip unknown event types early (forward compatibility).
|
// Skip unknown event types early (forward compatibility).
|
||||||
match event_type {
|
match event_type {
|
||||||
"book"
|
"book" | "price_change" | "tick_size_change" | "last_trade_price"
|
||||||
| "price_change"
|
| "best_bid_ask" | "new_market" | "market_resolved" | "trade" | "order" => {},
|
||||||
| "tick_size_change"
|
|
||||||
| "last_trade_price"
|
|
||||||
| "best_bid_ask"
|
|
||||||
| "new_market"
|
|
||||||
| "market_resolved"
|
|
||||||
| "trade"
|
|
||||||
| "order" => {}
|
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -393,22 +393,22 @@ impl Stream for WebSocketStream {
|
|||||||
self.stats.messages_received += 1;
|
self.stats.messages_received += 1;
|
||||||
self.stats.last_message_time = Some(Utc::now());
|
self.stats.last_message_time = Some(Utc::now());
|
||||||
continue;
|
continue;
|
||||||
}
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.stats.errors += 1;
|
self.stats.errors += 1;
|
||||||
return Poll::Ready(Some(Err(e)));
|
return Poll::Ready(Some(Err(e)));
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
tokio_tungstenite::tungstenite::Message::Close(_) => {
|
tokio_tungstenite::tungstenite::Message::Close(_) => {
|
||||||
info!("WebSocket connection closed by server");
|
info!("WebSocket connection closed by server");
|
||||||
self.connection = None;
|
self.connection = None;
|
||||||
return Poll::Ready(None);
|
return Poll::Ready(None);
|
||||||
}
|
},
|
||||||
tokio_tungstenite::tungstenite::Message::Ping(_) => {
|
tokio_tungstenite::tungstenite::Message::Ping(_) => {
|
||||||
// Best-effort: tokio-tungstenite/tungstenite may handle pings internally.
|
// Best-effort: tokio-tungstenite/tungstenite may handle pings internally.
|
||||||
continue;
|
continue;
|
||||||
}
|
},
|
||||||
tokio_tungstenite::tungstenite::Message::Pong(_) => continue,
|
tokio_tungstenite::tungstenite::Message::Pong(_) => continue,
|
||||||
tokio_tungstenite::tungstenite::Message::Binary(_) => continue,
|
tokio_tungstenite::tungstenite::Message::Binary(_) => continue,
|
||||||
tokio_tungstenite::tungstenite::Message::Frame(_) => continue,
|
tokio_tungstenite::tungstenite::Message::Frame(_) => continue,
|
||||||
@@ -417,11 +417,11 @@ impl Stream for WebSocketStream {
|
|||||||
error!("WebSocket error: {}", e);
|
error!("WebSocket error: {}", e);
|
||||||
self.stats.errors += 1;
|
self.stats.errors += 1;
|
||||||
return Poll::Ready(Some(Err(e.into())));
|
return Poll::Ready(Some(Err(e.into())));
|
||||||
}
|
},
|
||||||
Poll::Ready(None) => {
|
Poll::Ready(None) => {
|
||||||
info!("WebSocket stream ended");
|
info!("WebSocket stream ended");
|
||||||
return Poll::Ready(None);
|
return Poll::Ready(None);
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-7
@@ -735,9 +735,15 @@ pub struct BookUpdate {
|
|||||||
pub market: String,
|
pub market: String,
|
||||||
#[serde(deserialize_with = "crate::decode::deserializers::number_from_string")]
|
#[serde(deserialize_with = "crate::decode::deserializers::number_from_string")]
|
||||||
pub timestamp: u64,
|
pub timestamp: u64,
|
||||||
#[serde(default, deserialize_with = "crate::decode::deserializers::vec_from_null")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
deserialize_with = "crate::decode::deserializers::vec_from_null"
|
||||||
|
)]
|
||||||
pub bids: Vec<OrderSummary>,
|
pub bids: Vec<OrderSummary>,
|
||||||
#[serde(default, deserialize_with = "crate::decode::deserializers::vec_from_null")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
deserialize_with = "crate::decode::deserializers::vec_from_null"
|
||||||
|
)]
|
||||||
pub asks: Vec<OrderSummary>,
|
pub asks: Vec<OrderSummary>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub hash: Option<String>,
|
pub hash: Option<String>,
|
||||||
@@ -749,7 +755,10 @@ pub struct PriceChange {
|
|||||||
pub market: String,
|
pub market: String,
|
||||||
#[serde(deserialize_with = "crate::decode::deserializers::number_from_string")]
|
#[serde(deserialize_with = "crate::decode::deserializers::number_from_string")]
|
||||||
pub timestamp: u64,
|
pub timestamp: u64,
|
||||||
#[serde(default, deserialize_with = "crate::decode::deserializers::vec_from_null")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
deserialize_with = "crate::decode::deserializers::vec_from_null"
|
||||||
|
)]
|
||||||
pub price_changes: Vec<PriceChangeEntry>,
|
pub price_changes: Vec<PriceChangeEntry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -832,7 +841,10 @@ pub struct NewMarket {
|
|||||||
pub description: String,
|
pub description: String,
|
||||||
#[serde(rename = "assets_ids", alias = "asset_ids")]
|
#[serde(rename = "assets_ids", alias = "asset_ids")]
|
||||||
pub asset_ids: Vec<String>,
|
pub asset_ids: Vec<String>,
|
||||||
#[serde(default, deserialize_with = "crate::decode::deserializers::vec_from_null")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
deserialize_with = "crate::decode::deserializers::vec_from_null"
|
||||||
|
)]
|
||||||
pub outcomes: Vec<String>,
|
pub outcomes: Vec<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub event_message: Option<EventMessage>,
|
pub event_message: Option<EventMessage>,
|
||||||
@@ -853,7 +865,10 @@ pub struct MarketResolved {
|
|||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
#[serde(rename = "assets_ids", alias = "asset_ids")]
|
#[serde(rename = "assets_ids", alias = "asset_ids")]
|
||||||
pub asset_ids: Vec<String>,
|
pub asset_ids: Vec<String>,
|
||||||
#[serde(default, deserialize_with = "crate::decode::deserializers::vec_from_null")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
deserialize_with = "crate::decode::deserializers::vec_from_null"
|
||||||
|
)]
|
||||||
pub outcomes: Vec<String>,
|
pub outcomes: Vec<String>,
|
||||||
pub winning_asset_id: String,
|
pub winning_asset_id: String,
|
||||||
pub winning_outcome: String,
|
pub winning_outcome: String,
|
||||||
@@ -1240,9 +1255,15 @@ pub struct OrderBookSummary {
|
|||||||
pub hash: Option<String>,
|
pub hash: Option<String>,
|
||||||
#[serde(deserialize_with = "crate::decode::deserializers::number_from_string")]
|
#[serde(deserialize_with = "crate::decode::deserializers::number_from_string")]
|
||||||
pub timestamp: u64,
|
pub timestamp: u64,
|
||||||
#[serde(default, deserialize_with = "crate::decode::deserializers::vec_from_null")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
deserialize_with = "crate::decode::deserializers::vec_from_null"
|
||||||
|
)]
|
||||||
pub bids: Vec<OrderSummary>,
|
pub bids: Vec<OrderSummary>,
|
||||||
#[serde(default, deserialize_with = "crate::decode::deserializers::vec_from_null")]
|
#[serde(
|
||||||
|
default,
|
||||||
|
deserialize_with = "crate::decode::deserializers::vec_from_null"
|
||||||
|
)]
|
||||||
pub asks: Vec<OrderSummary>,
|
pub asks: Vec<OrderSummary>,
|
||||||
pub min_order_size: Decimal,
|
pub min_order_size: Decimal,
|
||||||
pub neg_risk: bool,
|
pub neg_risk: bool,
|
||||||
|
|||||||
Reference in New Issue
Block a user