Skip to content

Commit

Permalink
Change tags type to list[str]
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Apr 21, 2024
1 parent 5f4e484 commit 30e964b
Show file tree
Hide file tree
Showing 53 changed files with 308 additions and 303 deletions.
2 changes: 1 addition & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Released on TBD (UTC).
None

### Breaking Changes
None
- Changed `tags` param and return type from `str` to `list[str]` (more naturally expresses multiple tags)

### Fixes
- Fixed `ParquetDataCatalog` bar queries by `instrument_id` which were no longer returning data (the intent is to use `bar_type`, however using `instrument_id` now returns all matching bars)
Expand Down
10 changes: 5 additions & 5 deletions docs/concepts/orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ order: MarketOrder = self.order_factory.market(
quantity=Quantity.from_int(100_000),
time_in_force=TimeInForce.IOC, # <-- optional (default GTC)
reduce_only=False, # <-- optional (default False)
tags="ENTRY", # <-- optional (default None)
tags=["ENTRY"], # <-- optional (default None)
)
```
[API Reference](https://docs.nautilustrader.io/api_reference/model/orders.html#module-nautilus_trader.model.orders.market)
Expand Down Expand Up @@ -324,7 +324,7 @@ order: MarketIfTouchedOrder = self.order_factory.market_if_touched(
time_in_force=TimeInForce.GTC, # <-- optional (default GTC)
expire_time=None, # <-- optional (default None)
reduce_only=False, # <-- optional (default False)
tags="ENTRY", # <-- optional (default None)
tags=["ENTRY"], # <-- optional (default None)
)
```

Expand Down Expand Up @@ -359,7 +359,7 @@ order: StopLimitOrder = self.order_factory.limit_if_touched(
expire_time=pd.Timestamp("2022-06-06T12:00"),
post_only=True, # <-- optional (default False)
reduce_only=False, # <-- optional (default False)
tags="TAKE_PROFIT", # <-- optional (default None)
tags=["TAKE_PROFIT"], # <-- optional (default None)
)
```

Expand Down Expand Up @@ -396,7 +396,7 @@ order: TrailingStopMarketOrder = self.order_factory.trailing_stop_market(
time_in_force=TimeInForce.GTC, # <-- optional (default GTC)
expire_time=None, # <-- optional (default None)
reduce_only=True, # <-- optional (default False)
tags="TRAILING_STOP-1", # <-- optional (default None)
tags=["TRAILING_STOP-1"], # <-- optional (default None)
)
```

Expand Down Expand Up @@ -436,7 +436,7 @@ order: TrailingStopLimitOrder = self.order_factory.trailing_stop_limit(
time_in_force=TimeInForce.GTC, # <-- optional (default GTC)
expire_time=None, # <-- optional (default None)
reduce_only=True, # <-- optional (default False)
tags="TRAILING_STOP", # <-- optional (default None)
tags=["TRAILING_STOP"], # <-- optional (default None)
)
```

Expand Down
2 changes: 1 addition & 1 deletion nautilus_core/common/src/factories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl OrderFactory {
quote_quantity: Option<bool>,
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
) -> MarketOrder {
let client_order_id = self.generate_client_order_id();
let exec_spawn_id: Option<ClientOrderId> = if exec_algorithm_id.is_none() {
Expand Down
12 changes: 7 additions & 5 deletions nautilus_core/model/src/events/order/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub struct OrderInitialized {
pub exec_algorithm_id: Option<ExecAlgorithmId>,
pub exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
pub exec_spawn_id: Option<ClientOrderId>,
pub tags: Option<Ustr>,
pub tags: Option<Vec<Ustr>>,
}

impl Default for OrderInitialized {
Expand Down Expand Up @@ -152,7 +152,7 @@ impl OrderInitialized {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
) -> anyhow::Result<Self> {
Ok(Self {
trader_id,
Expand Down Expand Up @@ -266,9 +266,11 @@ impl Display for OrderInitialized {
.map_or("None".to_string(), |exec_spawn_id| format!(
"{exec_spawn_id}"
)),
self.tags
.as_ref()
.map_or("None".to_string(), |tags| format!("{tags}")),
self.tags.as_ref().map_or("None".to_string(), |tags| tags
.iter()
.map(|s| s.to_string())
.collect::<Vec<String>>()
.join(", ")),
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions nautilus_core/model/src/orders/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ pub trait Order {
fn exec_algorithm_id(&self) -> Option<ExecAlgorithmId>;
fn exec_algorithm_params(&self) -> Option<HashMap<Ustr, Ustr>>;
fn exec_spawn_id(&self) -> Option<ClientOrderId>;
fn tags(&self) -> Option<Ustr>;
fn tags(&self) -> Option<Vec<Ustr>>;
fn filled_qty(&self) -> Quantity;
fn leaves_qty(&self) -> Quantity;
fn avg_px(&self) -> Option<f64>;
Expand Down Expand Up @@ -832,7 +832,7 @@ pub struct OrderCore {
pub exec_algorithm_id: Option<ExecAlgorithmId>,
pub exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
pub exec_spawn_id: Option<ClientOrderId>,
pub tags: Option<Ustr>,
pub tags: Option<Vec<Ustr>>,
pub filled_qty: Quantity,
pub leaves_qty: Quantity,
pub avg_px: Option<f64>,
Expand Down
6 changes: 3 additions & 3 deletions nautilus_core/model/src/orders/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl LimitOrder {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
init_id: UUID4,
ts_init: UnixNanos,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -314,8 +314,8 @@ impl Order for LimitOrder {
self.exec_spawn_id
}

fn tags(&self) -> Option<Ustr> {
self.tags
fn tags(&self) -> Option<Vec<Ustr>> {
self.tags.clone()
}

fn filled_qty(&self) -> Quantity {
Expand Down
6 changes: 3 additions & 3 deletions nautilus_core/model/src/orders/limit_if_touched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl LimitIfTouchedOrder {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
init_id: UUID4,
ts_init: UnixNanos,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -301,8 +301,8 @@ impl Order for LimitIfTouchedOrder {
self.exec_spawn_id
}

fn tags(&self) -> Option<Ustr> {
self.tags
fn tags(&self) -> Option<Vec<Ustr>> {
self.tags.clone()
}

fn filled_qty(&self) -> Quantity {
Expand Down
6 changes: 3 additions & 3 deletions nautilus_core/model/src/orders/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl MarketOrder {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
) -> anyhow::Result<Self> {
check_quantity_positive(quantity)?;
if time_in_force == TimeInForce::Gtd {
Expand Down Expand Up @@ -291,8 +291,8 @@ impl Order for MarketOrder {
self.exec_spawn_id
}

fn tags(&self) -> Option<Ustr> {
self.tags
fn tags(&self) -> Option<Vec<Ustr>> {
self.tags.clone()
}

fn filled_qty(&self) -> Quantity {
Expand Down
6 changes: 3 additions & 3 deletions nautilus_core/model/src/orders/market_if_touched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl MarketIfTouchedOrder {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
init_id: UUID4,
ts_init: UnixNanos,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -295,8 +295,8 @@ impl Order for MarketIfTouchedOrder {
self.exec_spawn_id
}

fn tags(&self) -> Option<Ustr> {
self.tags
fn tags(&self) -> Option<Vec<Ustr>> {
self.tags.clone()
}

fn filled_qty(&self) -> Quantity {
Expand Down
6 changes: 3 additions & 3 deletions nautilus_core/model/src/orders/market_to_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl MarketToLimitOrder {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
init_id: UUID4,
ts_init: UnixNanos,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -287,8 +287,8 @@ impl Order for MarketToLimitOrder {
self.exec_spawn_id
}

fn tags(&self) -> Option<Ustr> {
self.tags
fn tags(&self) -> Option<Vec<Ustr>> {
self.tags.clone()
}

fn filled_qty(&self) -> Quantity {
Expand Down
12 changes: 6 additions & 6 deletions nautilus_core/model/src/orders/stop_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl StopLimitOrder {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
init_id: UUID4,
ts_init: UnixNanos,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -308,8 +308,8 @@ impl Order for StopLimitOrder {
self.exec_spawn_id
}

fn tags(&self) -> Option<Ustr> {
self.tags
fn tags(&self) -> Option<Vec<Ustr>> {
self.tags.clone()
}

fn filled_qty(&self) -> Quantity {
Expand Down Expand Up @@ -439,9 +439,9 @@ impl Display for StopLimitOrder {
self.time_in_force,
self.status,
self.client_order_id,
self.venue_order_id.map_or_else(|| "None".to_string(), |venue_order_id| format!("{venue_order_id}") ),
self.position_id.map_or_else(|| "None".to_string(), |position_id| format!("{position_id}")),
self.tags.map_or_else(|| "None".to_string(), |tags| format!("{tags}"))
self.venue_order_id.map_or("None".to_string(), |venue_order_id| format!("{venue_order_id}")),
self.position_id.map_or("None".to_string(), |position_id| format!("{position_id}")),
self.tags.clone().map_or("None".to_string(), |tags| tags.iter().map(|s| s.to_string()).collect::<Vec<String>>().join(", ")),
)
}
}
6 changes: 3 additions & 3 deletions nautilus_core/model/src/orders/stop_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl StopMarketOrder {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
init_id: UUID4,
ts_init: UnixNanos,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -296,8 +296,8 @@ impl Order for StopMarketOrder {
self.exec_spawn_id
}

fn tags(&self) -> Option<Ustr> {
self.tags
fn tags(&self) -> Option<Vec<Ustr>> {
self.tags.clone()
}

fn filled_qty(&self) -> Quantity {
Expand Down
6 changes: 3 additions & 3 deletions nautilus_core/model/src/orders/trailing_stop_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl TrailingStopLimitOrder {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
init_id: UUID4,
ts_init: UnixNanos,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -310,8 +310,8 @@ impl Order for TrailingStopLimitOrder {
self.exec_spawn_id
}

fn tags(&self) -> Option<Ustr> {
self.tags
fn tags(&self) -> Option<Vec<Ustr>> {
self.tags.clone()
}

fn filled_qty(&self) -> Quantity {
Expand Down
6 changes: 3 additions & 3 deletions nautilus_core/model/src/orders/trailing_stop_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl TrailingStopMarketOrder {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<Ustr, Ustr>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<Ustr>,
tags: Option<Vec<Ustr>>,
init_id: UUID4,
ts_init: UnixNanos,
) -> anyhow::Result<Self> {
Expand Down Expand Up @@ -302,8 +302,8 @@ impl Order for TrailingStopMarketOrder {
self.exec_spawn_id
}

fn tags(&self) -> Option<Ustr> {
self.tags
fn tags(&self) -> Option<Vec<Ustr>> {
self.tags.clone()
}

fn filled_qty(&self) -> Quantity {
Expand Down
17 changes: 11 additions & 6 deletions nautilus_core/model/src/python/events/order/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl OrderInitialized {
exec_algorithm_id: Option<ExecAlgorithmId>,
exec_algorithm_params: Option<HashMap<String, String>>,
exec_spawn_id: Option<ClientOrderId>,
tags: Option<String>,
tags: Option<Vec<String>>,
) -> PyResult<Self> {
Self::new(
trader_id,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl OrderInitialized {
exec_algorithm_id,
exec_algorithm_params.map(str_hashmap_to_ustr),
exec_spawn_id,
tags.map(|s| Ustr::from(&s)),
tags.map(|vec| vec.iter().map(|s| Ustr::from(&s)).collect()),
)
.map_err(to_pyvalue_err)
}
Expand Down Expand Up @@ -201,9 +201,11 @@ impl OrderInitialized {
.map_or("None".to_string(), |exec_spawn_id| format!(
"{exec_spawn_id}"
)),
self.tags
.as_ref()
.map_or("None".to_string(), |tags| format!("{tags}")),
self.tags.as_ref().map_or("None".to_string(), |tags| tags
.iter()
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join(", ")),
self.event_id,
self.ts_init
)
Expand Down Expand Up @@ -338,7 +340,10 @@ impl OrderInitialized {
None => dict.set_item("exec_spawn_id", py.None())?,
}
match &self.tags {
Some(tags) => dict.set_item("tags", tags.to_string())?,
Some(tags) => dict.set_item(
"tags",
tags.iter().map(|x| x.to_string()).collect::<Vec<String>>(),
)?,
None => dict.set_item("tags", py.None())?,
}
Ok(dict.into())
Expand Down
Loading

0 comments on commit 30e964b

Please sign in to comment.