use std::collections::HashMap; use bitfinex::positions::Position; use crate::events::{Event, EventDispatcher}; use crate::positions::PositionWrapper; use crate::strategy::Strategy; use crate::currency::SymbolPair; pub struct PairStatus { pair: SymbolPair, dispatcher: EventDispatcher, prices: HashMap, events: Vec, // orders: HashMap>, positions: HashMap>, current_tick: u64, strategy: Option>, } impl PairStatus { pub fn new(pair: SymbolPair, current_tick: u64, strategy: Option>) -> Self { PairStatus { pair, dispatcher: EventDispatcher::new(), prices: HashMap::new(), events: Vec::new(), positions: HashMap::new(), current_tick, strategy, } } pub fn add_position(&mut self, position: Position) { let (pw, events) = { match &self.strategy { Some(strategy) => { strategy.position_on_new_tick(position) }, None => (PositionWrapper::new(position.clone(), position.pl(), position.pl_perc(), None), vec![]) } }; self.positions .entry(self.current_tick) .or_default() .push(pw.clone()); // self.dispatcher.call_state_handlers(pw); for e in events { self.add_event(e); } } pub fn add_event(&mut self, event: Event) { self.events.push(event); // self.dispatcher.call_handler(&event); } }