Add remaining RQAlpha extension helpers
This commit is contained in:
@@ -4,6 +4,11 @@ use crate::events::{ProcessEvent, ProcessEventKind};
|
||||
|
||||
type ProcessEventListener = Box<dyn FnMut(&ProcessEvent)>;
|
||||
|
||||
pub trait BacktestProcessMod {
|
||||
fn name(&self) -> &str;
|
||||
fn install(&mut self, bus: &mut ProcessEventBus);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ProcessEventBus {
|
||||
listeners: BTreeMap<ProcessEventKind, Vec<ProcessEventListener>>,
|
||||
@@ -42,6 +47,13 @@ impl ProcessEventBus {
|
||||
self.any_listeners.push(Box::new(listener));
|
||||
}
|
||||
|
||||
pub fn install_mod<M>(&mut self, module: &mut M)
|
||||
where
|
||||
M: BacktestProcessMod,
|
||||
{
|
||||
module.install(self);
|
||||
}
|
||||
|
||||
pub fn publish(&mut self, event: &ProcessEvent) {
|
||||
if let Some(listeners) = self.listeners.get_mut(&event.kind) {
|
||||
for listener in listeners {
|
||||
|
||||
Reference in New Issue
Block a user