macro_rules! nautilus_strategy {
($ty:ty) => { ... };
($ty:ty, $field:ident) => { ... };
($ty:ty, { $($extra:item)* }) => { ... };
($ty:ty, $field:ident, { $($extra:item)* }) => { ... };
}Expand description
Implements DataActorNative, StrategyNative, and Strategy for a strategy type.
The struct must contain a field of type StrategyCore.
By default the macro expects the field to be named core; pass a second argument
to use a different name.
The macro also adds an inherent config() method on the strategy type which
returns the user-supplied StrategyConfig.
An optional brace-delimited block adds extra methods to the generated impl Strategy.
Native runtime core access is generated through StrategyNative; normal strategy
logic should use Strategy facade methods.
ยงExamples
โ
use nautilus_trading::{nautilus_strategy, strategy::StrategyCore};
pub struct MyStrategy {
core: StrategyCore,
// ...
}
// Simple form
nautilus_strategy!(MyStrategy);With Strategy hook overrides:
โ
nautilus_strategy!(MyStrategy, {
fn on_order_rejected(&mut self, event: OrderRejected) {
// custom handling
}
});With a custom field name and hooks:
โ
pub struct MyStrategy {
strat_core: StrategyCore,
// ...
}
nautilus_strategy!(MyStrategy, strat_core, {
fn external_order_claims(&self) -> Option<Vec<InstrumentId>> {
None
}
});