fix(data): return None for unsupported DBN event types instead of placeholder trades

The catch-all match arm in convert_to_common_event was creating synthetic
TradeEvent objects with symbol "UNKNOWN", price zero, and trade_id "placeholder"
for any MarketDataEvent variant not explicitly handled (Bar, OrderBook, News, etc.).
These fake trades corrupt downstream analytics pipelines. Now returns None and
logs at debug level instead, allowing callers to filter unsupported types cleanly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-02-21 15:32:02 +01:00
parent 4069eb473c
commit 58d2d8ddee

View File

@@ -136,7 +136,6 @@ use crate::types::TimeRange;
use async_trait::async_trait;
use chrono::Utc;
use common::{MarketDataEvent, QuoteEvent, Symbol, TradeEvent};
use rust_decimal::Decimal;
use std::pin::Pin;
use std::sync::Arc;
use tokio_stream::Stream;
@@ -414,7 +413,10 @@ impl DatabentoHistoricalProvider {
}
/// Convert types::MarketDataEvent to providers::common::MarketDataEvent
fn convert_to_common_event(&self, event: MarketDataEvent) -> MarketDataEvent {
///
/// Returns `None` for unsupported event types (e.g., Bar, OrderBook, News)
/// rather than synthesizing placeholder trades that would corrupt downstream analytics.
fn convert_to_common_event(&self, event: MarketDataEvent) -> Option<MarketDataEvent> {
match event {
MarketDataEvent::Trade(trade) => {
let common_trade = TradeEvent {
@@ -427,7 +429,7 @@ impl DatabentoHistoricalProvider {
conditions: vec![],
sequence: 0,
};
MarketDataEvent::Trade(common_trade)
Some(MarketDataEvent::Trade(common_trade))
},
MarketDataEvent::Quote(quote) => {
let common_quote = QuoteEvent {
@@ -443,22 +445,11 @@ impl DatabentoHistoricalProvider {
conditions: vec![],
sequence: 0,
};
MarketDataEvent::Quote(common_quote)
Some(MarketDataEvent::Quote(common_quote))
},
// Add other event types as needed
_ => {
// For unsupported event types, create a placeholder trade event
let placeholder_trade = TradeEvent {
symbol: "UNKNOWN".into(),
price: Decimal::ZERO,
size: Decimal::ZERO,
timestamp: Utc::now(),
trade_id: Some("placeholder".to_string()),
exchange: Some("UNKNOWN".to_string()),
conditions: vec![],
sequence: 0,
};
MarketDataEvent::Trade(placeholder_trade)
debug!("Unsupported DBN record type encountered, skipping conversion");
None
},
}
}