Skip to content

Commit 5af2b5d

Browse files
committed
Refine Databento symbology inference
1 parent 7da9df0 commit 5af2b5d

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

nautilus_core/adapters/databento/src/python/historical.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{
2323
};
2424

2525
use databento::{
26-
dbn::{self, SType},
26+
dbn::{self},
2727
historical::timeseries::GetRangeParams,
2828
};
2929
use indexmap::IndexMap;
@@ -155,7 +155,7 @@ impl DatabentoHistoricalClient {
155155
.dataset(dataset)
156156
.date_time_range(time_range)
157157
.symbols(symbols)
158-
.stype_in(SType::from_str(&stype_in).map_err(to_pyvalue_err)?)
158+
.stype_in(stype_in)
159159
.schema(dbn::Schema::Definition)
160160
.limit(limit.and_then(NonZeroU64::new))
161161
.build();
@@ -254,7 +254,7 @@ impl DatabentoHistoricalClient {
254254
.dataset(dataset)
255255
.date_time_range(time_range)
256256
.symbols(symbols)
257-
.stype_in(SType::from_str(&stype_in).map_err(to_pyvalue_err)?)
257+
.stype_in(stype_in)
258258
.schema(dbn_schema)
259259
.limit(limit.and_then(NonZeroU64::new))
260260
.build();
@@ -356,7 +356,7 @@ impl DatabentoHistoricalClient {
356356
.dataset(dataset)
357357
.date_time_range(time_range)
358358
.symbols(symbols)
359-
.stype_in(SType::from_str(&stype_in).map_err(to_pyvalue_err)?)
359+
.stype_in(stype_in)
360360
.schema(dbn::Schema::Trades)
361361
.limit(limit.and_then(NonZeroU64::new))
362362
.build();
@@ -447,7 +447,7 @@ impl DatabentoHistoricalClient {
447447
.dataset(dataset)
448448
.date_time_range(time_range)
449449
.symbols(symbols)
450-
.stype_in(SType::from_str(&stype_in).map_err(to_pyvalue_err)?)
450+
.stype_in(stype_in)
451451
.schema(schema)
452452
.limit(limit.and_then(NonZeroU64::new))
453453
.build();
@@ -530,7 +530,7 @@ impl DatabentoHistoricalClient {
530530
.dataset(dataset)
531531
.date_time_range(time_range)
532532
.symbols(symbols)
533-
.stype_in(SType::from_str(&stype_in).map_err(to_pyvalue_err)?)
533+
.stype_in(stype_in)
534534
.schema(dbn::Schema::Imbalance)
535535
.limit(limit.and_then(NonZeroU64::new))
536536
.build();
@@ -602,7 +602,7 @@ impl DatabentoHistoricalClient {
602602
.dataset(dataset)
603603
.date_time_range(time_range)
604604
.symbols(symbols)
605-
.stype_in(SType::from_str(&stype_in).map_err(to_pyvalue_err)?)
605+
.stype_in(stype_in)
606606
.schema(dbn::Schema::Statistics)
607607
.limit(limit.and_then(NonZeroU64::new))
608608
.build();
@@ -674,7 +674,7 @@ impl DatabentoHistoricalClient {
674674
.dataset(dataset)
675675
.date_time_range(time_range)
676676
.symbols(symbols)
677-
.stype_in(SType::from_str(&stype_in).map_err(to_pyvalue_err)?)
677+
.stype_in(stype_in)
678678
.schema(dbn::Schema::Status)
679679
.limit(limit.and_then(NonZeroU64::new))
680680
.build();

nautilus_core/adapters/databento/src/python/live.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl DatabentoLiveClient {
186186
let mut sub = Subscription::builder()
187187
.symbols(symbols)
188188
.schema(dbn::Schema::from_str(&schema).map_err(to_pyvalue_err)?)
189-
.stype_in(dbn::SType::from_str(&stype_in).map_err(to_pyvalue_err)?)
189+
.stype_in(stype_in)
190190
.build();
191191

192192
if let Some(start) = start {

nautilus_core/adapters/databento/src/symbology.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use std::collections::HashMap;
1717

18-
use databento::dbn;
18+
use databento::dbn::{self, SType};
1919
use dbn::{Publisher, Record};
2020
use indexmap::IndexMap;
2121
use nautilus_core::correctness::check_slice_not_empty;
@@ -110,21 +110,21 @@ pub fn get_nautilus_instrument_id_for_record(
110110
}
111111

112112
#[must_use]
113-
pub fn infer_symbology_type(symbol: &str) -> String {
113+
pub fn infer_symbology_type(symbol: &str) -> SType {
114114
if symbol.ends_with(".FUT") || symbol.ends_with(".OPT") {
115-
return "parent".to_string();
115+
return SType::Parent;
116116
}
117117

118118
let parts: Vec<&str> = symbol.split('.').collect();
119119
if parts.len() == 3 && parts[2].chars().all(|c| c.is_ascii_digit()) {
120-
return "continuous".to_string();
120+
return SType::Continuous;
121121
}
122122

123123
if symbol.chars().all(|c| c.is_ascii_digit()) {
124-
return "instrument_id".to_string();
124+
return SType::InstrumentId;
125125
}
126126

127-
"raw_symbol".to_string()
127+
SType::RawSymbol
128128
}
129129

130130
pub fn check_consistent_symbology(symbols: &[&str]) -> anyhow::Result<()> {
@@ -173,7 +173,7 @@ mod tests {
173173
#[case("SPX.OPT", "parent")]
174174
#[case("ES.c.0", "continuous")]
175175
#[case("SPX.n.0", "continuous")]
176-
fn test_infer_symbology_type(#[case] symbol: String, #[case] expected: String) {
176+
fn test_infer_symbology_type(#[case] symbol: String, #[case] expected: SType) {
177177
let result = infer_symbology_type(&symbol);
178178
assert_eq!(result, expected);
179179
}

0 commit comments

Comments
 (0)