Skip to main content

nautilus_strategy

Macro nautilus_strategy 

Source
macro_rules! nautilus_strategy {
    ($ty:ty) => { ... };
    ($ty:ty, $field:ident) => { ... };
    ($ty:ty, { $($extra:item)* }) => { ... };
    ($ty:ty, $field:ident, { $($extra:item)* }) => { ... };
}
Expand description

Implements Deref<Target = DataActorCore>, DerefMut, 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.

An optional brace-delimited block adds extra methods to the generated impl Strategy. Do not redefine core or core_mut inside the block; they are already generated by the macro and duplicates will cause a compile error.

ยง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
    }
});