Skip to content

Commit 53b6ef3

Browse files
committed
Refine Tardis symbol and venue parsing
1 parent 36328fd commit 53b6ef3

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

nautilus_core/adapters/src/tardis/enums.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
// limitations under the License.
1414
// -------------------------------------------------------------------------------------------------
1515

16+
use nautilus_model::identifiers::Venue;
1617
use serde::{Deserialize, Serialize};
1718
use strum::{AsRefStr, Display, EnumIter, EnumString, FromRepr};
19+
use ustr::Ustr;
1820

1921
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Display)]
2022
#[serde(rename_all = "lowercase")]
@@ -242,4 +244,9 @@ impl Exchange {
242244
Self::WooX => "WOOX",
243245
}
244246
}
247+
248+
#[must_use]
249+
pub fn as_venue(&self) -> Venue {
250+
Venue::from_ustr_unchecked(Ustr::from(self.as_venue_str()))
251+
}
245252
}

nautilus_core/adapters/src/tardis/parse.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@ use nautilus_core::{datetime::NANOSECONDS_IN_MICROSECOND, nanos::UnixNanos};
1717
use nautilus_model::{
1818
data::bar::BarSpecification,
1919
enums::{AggressorSide, BarAggregation, BookAction, OptionKind, OrderSide, PriceType},
20-
identifiers::{InstrumentId, Symbol, Venue},
20+
identifiers::{InstrumentId, Symbol},
2121
};
2222

2323
use super::enums::{Exchange, OptionType};
2424

2525
#[must_use]
26+
#[inline]
2627
pub fn parse_symbol_str(symbol: &str) -> String {
28+
// TODO: Implement symbol standardization for Binance, Bybit and dYdX
2729
symbol.to_uppercase()
2830
}
2931

3032
/// Parses a Nautilus instrument ID from the given Tardis `exchange` and `symbol` values.
3133
#[must_use]
3234
pub fn parse_instrument_id(exchange: &Exchange, symbol: &str) -> InstrumentId {
33-
let symbol = Symbol::from(parse_symbol_str(symbol));
34-
let venue = Venue::from(exchange.as_venue_str());
35-
InstrumentId::new(symbol, venue)
35+
let symbol = Symbol::from_str_unchecked(parse_symbol_str(symbol));
36+
InstrumentId::new(symbol, exchange.as_venue())
3637
}
3738

3839
/// Parses a Nautilus order side from the given Tardis string `value`.

0 commit comments

Comments
 (0)