|
@ -4,15 +4,15 @@ use crate::harness::mocks::wallet::WalletActor; |
|
|
use crate::schnorrsig; |
|
|
use crate::schnorrsig; |
|
|
use daemon::bitmex_price_feed::Quote; |
|
|
use daemon::bitmex_price_feed::Quote; |
|
|
use daemon::connection::{connect, ConnectionStatus}; |
|
|
use daemon::connection::{connect, ConnectionStatus}; |
|
|
use daemon::model::cfd::{Cfd, Order, Origin, UpdateCfdProposals}; |
|
|
use daemon::model::cfd::{Cfd, Order, Origin}; |
|
|
use daemon::model::{Price, TakerId, Timestamp, Usd}; |
|
|
use daemon::model::{Price, TakerId, Timestamp, Usd}; |
|
|
|
|
|
use daemon::projection::Feeds; |
|
|
use daemon::seed::Seed; |
|
|
use daemon::seed::Seed; |
|
|
use daemon::{ |
|
|
use daemon::{ |
|
|
db, maker_cfd, maker_inc_connections, projection, taker_cfd, MakerActorSystem, Tasks, |
|
|
db, maker_cfd, maker_inc_connections, projection, taker_cfd, MakerActorSystem, Tasks, |
|
|
}; |
|
|
}; |
|
|
use rust_decimal_macros::dec; |
|
|
use rust_decimal_macros::dec; |
|
|
use sqlx::SqlitePool; |
|
|
use sqlx::SqlitePool; |
|
|
use std::collections::HashMap; |
|
|
|
|
|
use std::net::SocketAddr; |
|
|
use std::net::SocketAddr; |
|
|
use std::str::FromStr; |
|
|
use std::str::FromStr; |
|
|
use std::task::Poll; |
|
|
use std::task::Poll; |
|
@ -94,25 +94,23 @@ pub struct Maker { |
|
|
pub system: |
|
|
pub system: |
|
|
MakerActorSystem<OracleActor, MonitorActor, maker_inc_connections::Actor, WalletActor>, |
|
|
MakerActorSystem<OracleActor, MonitorActor, maker_inc_connections::Actor, WalletActor>, |
|
|
pub mocks: mocks::Mocks, |
|
|
pub mocks: mocks::Mocks, |
|
|
|
|
|
pub feeds: Feeds, |
|
|
pub listen_addr: SocketAddr, |
|
|
pub listen_addr: SocketAddr, |
|
|
pub identity_pk: x25519_dalek::PublicKey, |
|
|
pub identity_pk: x25519_dalek::PublicKey, |
|
|
cfd_feed_receiver: watch::Receiver<Vec<Cfd>>, |
|
|
|
|
|
order_feed_receiver: watch::Receiver<Option<Order>>, |
|
|
|
|
|
connected_takers_feed_receiver: watch::Receiver<Vec<TakerId>>, |
|
|
|
|
|
_tasks: Tasks, |
|
|
_tasks: Tasks, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl Maker { |
|
|
impl Maker { |
|
|
pub fn cfd_feed(&mut self) -> &mut watch::Receiver<Vec<Cfd>> { |
|
|
pub fn cfd_feed(&mut self) -> &mut watch::Receiver<Vec<Cfd>> { |
|
|
&mut self.cfd_feed_receiver |
|
|
&mut self.feeds.cfds |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn order_feed(&mut self) -> &mut watch::Receiver<Option<Order>> { |
|
|
pub fn order_feed(&mut self) -> &mut watch::Receiver<Option<Order>> { |
|
|
&mut self.order_feed_receiver |
|
|
&mut self.feeds.order |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn connected_takers_feed(&mut self) -> &mut watch::Receiver<Vec<TakerId>> { |
|
|
pub fn connected_takers_feed(&mut self) -> &mut watch::Receiver<Vec<TakerId>> { |
|
|
&mut self.connected_takers_feed_receiver |
|
|
&mut self.feeds.connected_takers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub async fn start(config: &MakerConfig, listener: TcpListener) -> Self { |
|
|
pub async fn start(config: &MakerConfig, listener: TcpListener) -> Self { |
|
@ -162,21 +160,8 @@ impl Maker { |
|
|
ask: Price::new(dec!(10000)).unwrap(), |
|
|
ask: Price::new(dec!(10000)).unwrap(), |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
let (cfd_feed_sender, cfd_feed_receiver) = watch::channel(vec![]); |
|
|
let (proj_actor, feeds) = projection::Actor::new(vec![], dummy_quote); |
|
|
let (order_feed_sender, order_feed_receiver) = watch::channel::<Option<Order>>(None); |
|
|
tasks.add(projection_context.run(proj_actor)); |
|
|
let (update_cfd_feed_sender, _update_cfd_feed_receiver) = |
|
|
|
|
|
watch::channel::<UpdateCfdProposals>(HashMap::new()); |
|
|
|
|
|
let (quote_sender, _) = watch::channel::<Quote>(dummy_quote); |
|
|
|
|
|
let (connected_takers_feed_sender, connected_takers_feed_receiver) = |
|
|
|
|
|
watch::channel::<Vec<TakerId>>(vec![]); |
|
|
|
|
|
|
|
|
|
|
|
tasks.add(projection_context.run(projection::Actor::new( |
|
|
|
|
|
cfd_feed_sender, |
|
|
|
|
|
order_feed_sender, |
|
|
|
|
|
quote_sender, |
|
|
|
|
|
update_cfd_feed_sender, |
|
|
|
|
|
connected_takers_feed_sender, |
|
|
|
|
|
))); |
|
|
|
|
|
|
|
|
|
|
|
let address = listener.local_addr().unwrap(); |
|
|
let address = listener.local_addr().unwrap(); |
|
|
|
|
|
|
|
@ -195,13 +180,11 @@ impl Maker { |
|
|
|
|
|
|
|
|
Self { |
|
|
Self { |
|
|
system: maker, |
|
|
system: maker, |
|
|
|
|
|
feeds, |
|
|
identity_pk, |
|
|
identity_pk, |
|
|
listen_addr: address, |
|
|
listen_addr: address, |
|
|
mocks, |
|
|
mocks, |
|
|
_tasks: tasks, |
|
|
_tasks: tasks, |
|
|
cfd_feed_receiver, |
|
|
|
|
|
order_feed_receiver, |
|
|
|
|
|
connected_takers_feed_receiver, |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -240,18 +223,17 @@ pub struct Taker { |
|
|
pub id: TakerId, |
|
|
pub id: TakerId, |
|
|
pub system: daemon::TakerActorSystem<OracleActor, MonitorActor, WalletActor>, |
|
|
pub system: daemon::TakerActorSystem<OracleActor, MonitorActor, WalletActor>, |
|
|
pub mocks: mocks::Mocks, |
|
|
pub mocks: mocks::Mocks, |
|
|
cfd_feed_receiver: watch::Receiver<Vec<Cfd>>, |
|
|
pub feeds: Feeds, |
|
|
order_feed_receiver: watch::Receiver<Option<Order>>, |
|
|
|
|
|
_tasks: Tasks, |
|
|
_tasks: Tasks, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
impl Taker { |
|
|
impl Taker { |
|
|
pub fn cfd_feed(&mut self) -> &mut watch::Receiver<Vec<Cfd>> { |
|
|
pub fn cfd_feed(&mut self) -> &mut watch::Receiver<Vec<Cfd>> { |
|
|
&mut self.cfd_feed_receiver |
|
|
&mut self.feeds.cfds |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn order_feed(&mut self) -> &mut watch::Receiver<Option<Order>> { |
|
|
pub fn order_feed(&mut self) -> &mut watch::Receiver<Option<Order>> { |
|
|
&mut self.order_feed_receiver |
|
|
&mut self.feeds.order |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
pub fn maker_status_feed(&mut self) -> &mut watch::Receiver<ConnectionStatus> { |
|
|
pub fn maker_status_feed(&mut self) -> &mut watch::Receiver<ConnectionStatus> { |
|
@ -299,21 +281,8 @@ impl Taker { |
|
|
ask: Price::new(dec!(10000)).unwrap(), |
|
|
ask: Price::new(dec!(10000)).unwrap(), |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
let (cfd_feed_sender, cfd_feed_receiver) = watch::channel(vec![]); |
|
|
let (proj_actor, feeds) = projection::Actor::new(vec![], dummy_quote); |
|
|
let (order_feed_sender, order_feed_receiver) = watch::channel::<Option<Order>>(None); |
|
|
tasks.add(projection_context.run(proj_actor)); |
|
|
let (update_cfd_feed_sender, _) = watch::channel::<UpdateCfdProposals>(HashMap::new()); |
|
|
|
|
|
let (quote_sender, _) = watch::channel::<Quote>(dummy_quote); |
|
|
|
|
|
|
|
|
|
|
|
let (connected_takers_feed_sender, _connected_takers_feed_receiver) = |
|
|
|
|
|
watch::channel::<Vec<TakerId>>(vec![]); |
|
|
|
|
|
|
|
|
|
|
|
tasks.add(projection_context.run(projection::Actor::new( |
|
|
|
|
|
cfd_feed_sender, |
|
|
|
|
|
order_feed_sender, |
|
|
|
|
|
quote_sender, |
|
|
|
|
|
update_cfd_feed_sender, |
|
|
|
|
|
connected_takers_feed_sender, |
|
|
|
|
|
))); |
|
|
|
|
|
|
|
|
|
|
|
tasks.add(connect( |
|
|
tasks.add(connect( |
|
|
taker.maker_online_status_feed_receiver.clone(), |
|
|
taker.maker_online_status_feed_receiver.clone(), |
|
@ -325,10 +294,9 @@ impl Taker { |
|
|
Self { |
|
|
Self { |
|
|
id: TakerId::new(identity_pk), |
|
|
id: TakerId::new(identity_pk), |
|
|
system: taker, |
|
|
system: taker, |
|
|
|
|
|
feeds, |
|
|
mocks, |
|
|
mocks, |
|
|
_tasks: tasks, |
|
|
_tasks: tasks, |
|
|
order_feed_receiver, |
|
|
|
|
|
cfd_feed_receiver, |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|