started moving logic from close position to update in order manager

This commit is contained in:
Giulio De Pasquale 2021-01-24 20:50:54 +00:00
parent 7d639d1b4c
commit 64a687445d

View File

@ -3,8 +3,10 @@ use std::ops::{Deref, Neg};
use bitfinex::ticker::TradingPairTicker; use bitfinex::ticker::TradingPairTicker;
use futures_util::stream::FuturesUnordered; use futures_util::stream::FuturesUnordered;
use log::{debug, error, info}; use log::{debug, error, info, trace};
use merge::Merge;
use tokio::signal::unix::Signal; use tokio::signal::unix::Signal;
use tokio::stream::StreamExt;
use tokio::sync::mpsc::channel; use tokio::sync::mpsc::channel;
use tokio::sync::mpsc::{Receiver, Sender}; use tokio::sync::mpsc::{Receiver, Sender};
use tokio::sync::{oneshot, RwLock}; use tokio::sync::{oneshot, RwLock};
@ -17,15 +19,9 @@ use crate::models::{
}; };
use crate::strategy::{FastOrderStrategy, OrderStrategy, PositionStrategy, TrailingStop}; use crate::strategy::{FastOrderStrategy, OrderStrategy, PositionStrategy, TrailingStop};
use crate::BoxError; use crate::BoxError;
use merge::Merge;
use tokio::stream::StreamExt;
pub type OptionUpdate = (Option<Vec<Event>>, Option<Vec<Message>>); pub type OptionUpdate = (Option<Vec<Event>>, Option<Vec<Message>>);
pub struct EventManager {
events: Vec<Event>,
}
/****************** /******************
* PRICES * PRICES
******************/ ******************/
@ -108,20 +104,9 @@ impl PriceManager {
current_prices, current_prices,
self.pair.clone(), self.pair.clone(),
None, None,
// None,
)) ))
} }
// fn add_event(&mut self, event: Event) {
// self.events.push(event);
//
// self.dispatcher.call_event_handlers(&event, &self);
// }
//
// fn add_signal(&mut self, signal: SignalKind) {
// self.signals.insert(self.current_tick(), signal);
// }
pub fn pair(&self) -> &SymbolPair { pub fn pair(&self) -> &SymbolPair {
&self.pair &self.pair
} }
@ -133,7 +118,6 @@ pub struct PriceEntry {
pair: SymbolPair, pair: SymbolPair,
price: PriceTicker, price: PriceTicker,
events: Option<Vec<Event>>, events: Option<Vec<Event>>,
// signals: Option<Vec<SignalKind>>,
} }
impl PriceEntry { impl PriceEntry {
@ -142,14 +126,12 @@ impl PriceEntry {
price: PriceTicker, price: PriceTicker,
pair: SymbolPair, pair: SymbolPair,
events: Option<Vec<Event>>, events: Option<Vec<Event>>,
// signals: Option<Vec<SignalKind>>,
) -> Self { ) -> Self {
PriceEntry { PriceEntry {
tick, tick,
pair, pair,
price, price,
events, events,
// signals,
} }
} }
@ -165,9 +147,6 @@ impl PriceEntry {
pub fn events(&self) -> &Option<Vec<Event>> { pub fn events(&self) -> &Option<Vec<Event>> {
&self.events &self.events
} }
// pub fn signals(&self) -> &Option<Vec<SignalKind>> {
// &self.signals
// }
} }
/****************** /******************
@ -510,7 +489,7 @@ impl OrderManager {
let (_, strat_messages) = let (_, strat_messages) =
self.strategy self.strategy
.on_position_close(active_order, &position, &order_book)?; .on_position_order(active_order, &position, &order_book)?;
if let Some(messages) = strat_messages { if let Some(messages) = strat_messages {
for m in messages { for m in messages {
@ -535,8 +514,16 @@ impl OrderManager {
Ok(()) Ok(())
} }
// TODO: finish me
pub async fn update(&self) -> Result<OptionUpdate, BoxError> { pub async fn update(&self) -> Result<OptionUpdate, BoxError> {
// TODO: implement me trace!("\tUpdating {} order manager.", self.pair);
let (open_orders, opt_open_positions) = tokio::join!(
self.client.active_orders(&self.pair),
self.client.active_positions(&self.pair)
);
let (open_orders, opt_open_positions) = (open_orders?, opt_open_positions?);
Ok((None, None)) Ok((None, None))
} }