pair managers implemented
This commit is contained in:
parent
f3cb051535
commit
3512dce35b
@ -230,6 +230,8 @@ impl PositionManager {
|
||||
}
|
||||
|
||||
pub async fn update(&mut self, tick: u64) -> Result<OptionUpdate, BoxError> {
|
||||
debug!("Updating {}", self.pair);
|
||||
|
||||
let opt_active_positions = self.client.active_positions(&self.pair).await?;
|
||||
let mut events = vec![];
|
||||
|
||||
@ -431,44 +433,52 @@ impl OrderManager {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PairManager {
|
||||
pair: SymbolPair,
|
||||
price_manager: PriceManagerHandle,
|
||||
order_manager: OrderManagerHandle,
|
||||
position_manager: PositionManagerHandle,
|
||||
dispatcher: Dispatcher,
|
||||
}
|
||||
|
||||
impl PairManager {
|
||||
pub fn new(pair: SymbolPair, client: Client) -> Self {
|
||||
Self {
|
||||
pair: pair.clone(),
|
||||
price_manager: PriceManagerHandle::new(pair.clone(), client.clone()),
|
||||
order_manager: OrderManagerHandle::new(
|
||||
pair.clone(),
|
||||
client.clone(),
|
||||
Box::new(FastOrderStrategy {}),
|
||||
),
|
||||
position_manager: PositionManagerHandle::new(
|
||||
pair.clone(),
|
||||
client.clone(),
|
||||
Box::new(TrailingStop::new()),
|
||||
),
|
||||
dispatcher: Dispatcher::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ExchangeManager {
|
||||
kind: ExchangeKind,
|
||||
price_managers: Vec<PriceManagerHandle>,
|
||||
order_managers: Vec<OrderManagerHandle>,
|
||||
position_managers: Vec<PositionManagerHandle>,
|
||||
dispatcher: Dispatcher,
|
||||
pair_managers: Vec<PairManager>,
|
||||
client: Client,
|
||||
}
|
||||
|
||||
impl ExchangeManager {
|
||||
pub fn new(kind: &ExchangeKind, pairs: &Vec<SymbolPair>) -> Self {
|
||||
let client = Client::new(kind);
|
||||
let pair_managers = pairs
|
||||
.into_iter()
|
||||
.map(|x| PairManager::new(x.clone(), client.clone()))
|
||||
.collect();
|
||||
|
||||
let mut position_managers = Vec::new();
|
||||
let mut order_managers = Vec::new();
|
||||
let mut price_managers = Vec::new();
|
||||
|
||||
for p in pairs {
|
||||
position_managers.push(PositionManagerHandle::new(
|
||||
p.clone(),
|
||||
client.clone(),
|
||||
Box::new(TrailingStop::new()),
|
||||
));
|
||||
order_managers.push(OrderManagerHandle::new(
|
||||
p.clone(),
|
||||
client.clone(),
|
||||
Box::new(FastOrderStrategy {}),
|
||||
));
|
||||
price_managers.push(PriceManagerHandle::new(p.clone(), client.clone()));
|
||||
}
|
||||
|
||||
ExchangeManager {
|
||||
Self {
|
||||
kind: kind.clone(),
|
||||
position_managers,
|
||||
order_managers,
|
||||
price_managers,
|
||||
pair_managers,
|
||||
client,
|
||||
dispatcher: Dispatcher::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,9 +493,9 @@ impl ExchangeManager {
|
||||
|
||||
async fn update_position_managers(&mut self, tick: u64) -> Result<OptionUpdate, BoxError> {
|
||||
let mut futures: FuturesUnordered<_> = self
|
||||
.position_managers
|
||||
.pair_managers
|
||||
.iter_mut()
|
||||
.map(|x| x.update(tick))
|
||||
.map(|x| x.position_manager.update(tick))
|
||||
.collect();
|
||||
|
||||
while let Some(x) = futures.next().await {}
|
||||
@ -495,9 +505,9 @@ impl ExchangeManager {
|
||||
|
||||
async fn update_price_managers(&mut self, tick: u64) -> Result<OptionUpdate, BoxError> {
|
||||
let mut futures: FuturesUnordered<_> = self
|
||||
.price_managers
|
||||
.pair_managers
|
||||
.iter_mut()
|
||||
.map(|x| x.update(tick))
|
||||
.map(|x| x.price_manager.update(tick))
|
||||
.collect();
|
||||
|
||||
while let Some(x) = futures.next().await {}
|
||||
|
Loading…
Reference in New Issue
Block a user