@ -6,7 +6,7 @@ use daemon::bitmex_price_feed::Quote;
use daemon ::connection ::{ connect , ConnectionStatus } ;
use daemon ::connection ::{ connect , ConnectionStatus } ;
use daemon ::maker_cfd ::CfdAction ;
use daemon ::maker_cfd ::CfdAction ;
use daemon ::model ::cfd ::{ Cfd , Order , Origin , UpdateCfdProposals } ;
use daemon ::model ::cfd ::{ Cfd , Order , Origin , UpdateCfdProposals } ;
use daemon ::model ::{ Price , Timestamp , Usd } ;
use daemon ::model ::{ Price , TakerId , T imestamp , Usd } ;
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 ,
@ -20,7 +20,6 @@ use std::task::Poll;
use std ::time ::Duration ;
use std ::time ::Duration ;
use tokio ::net ::TcpListener ;
use tokio ::net ::TcpListener ;
use tokio ::sync ::watch ;
use tokio ::sync ::watch ;
use tokio ::sync ::watch ::channel ;
use tracing ::subscriber ::DefaultGuard ;
use tracing ::subscriber ::DefaultGuard ;
use tracing_subscriber ::filter ::LevelFilter ;
use tracing_subscriber ::filter ::LevelFilter ;
use tracing_subscriber ::util ::SubscriberInitExt ;
use tracing_subscriber ::util ::SubscriberInitExt ;
@ -59,6 +58,7 @@ pub struct Maker {
pub identity_pk : x25519_dalek ::PublicKey ,
pub identity_pk : x25519_dalek ::PublicKey ,
cfd_feed_receiver : watch ::Receiver < Vec < Cfd > > ,
cfd_feed_receiver : watch ::Receiver < Vec < Cfd > > ,
order_feed_receiver : watch ::Receiver < Option < Order > > ,
order_feed_receiver : watch ::Receiver < Option < Order > > ,
connected_takers_feed_receiver : watch ::Receiver < Vec < TakerId > > ,
_tasks : Tasks ,
_tasks : Tasks ,
}
}
@ -71,6 +71,10 @@ impl Maker {
& mut self . order_feed_receiver
& mut self . order_feed_receiver
}
}
pub fn connected_takers_feed ( & mut self ) -> & mut watch ::Receiver < Vec < TakerId > > {
& mut self . connected_takers_feed_receiver
}
pub async fn start (
pub async fn start (
oracle_pk : schnorrsig ::PublicKey ,
oracle_pk : schnorrsig ::PublicKey ,
seed : Seed ,
seed : Seed ,
@ -100,10 +104,11 @@ impl Maker {
oracle_pk ,
oracle_pk ,
| _ , _ | oracle ,
| _ , _ | oracle ,
| _ , _ | async { Ok ( monitor ) } ,
| _ , _ | async { Ok ( monitor ) } ,
| channel0 , channel1 | {
| channel0 , channel1 , channel2 | {
maker_inc_connections ::Actor ::new (
maker_inc_connections ::Actor ::new (
channel0 ,
channel0 ,
channel1 ,
channel1 ,
channel2 ,
identity_sk ,
identity_sk ,
HEARTBEAT_INTERVAL_FOR_TEST ,
HEARTBEAT_INTERVAL_FOR_TEST ,
)
)
@ -121,17 +126,20 @@ impl Maker {
ask : Price ::new ( dec ! ( 10000 ) ) . unwrap ( ) ,
ask : Price ::new ( dec ! ( 10000 ) ) . unwrap ( ) ,
} ;
} ;
let ( cfd_feed_sender , cfd_feed_receiver ) = channel ( vec ! [ ] ) ;
let ( cfd_feed_sender , cfd_feed_receiver ) = watch ::channel ( vec ! [ ] ) ;
let ( order_feed_sender , order_feed_receiver ) = channel ::< Option < Order > > ( None ) ;
let ( order_feed_sender , order_feed_receiver ) = watch ::channel ::< Option < Order > > ( None ) ;
let ( update_cfd_feed_sender , _update_cfd_feed_receiver ) =
let ( update_cfd_feed_sender , _update_cfd_feed_receiver ) =
channel ::< UpdateCfdProposals > ( HashMap ::new ( ) ) ;
watch ::channel ::< UpdateCfdProposals > ( HashMap ::new ( ) ) ;
let ( quote_sender , _ ) = channel ::< Quote > ( dummy_quote ) ;
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 (
tasks . add ( projection_context . run ( projection ::Actor ::new (
cfd_feed_sender ,
cfd_feed_sender ,
order_feed_sender ,
order_feed_sender ,
quote_sender ,
quote_sender ,
update_cfd_feed_sender ,
update_cfd_feed_sender ,
connected_takers_feed_sender ,
) ) ) ;
) ) ) ;
let address = listener . local_addr ( ) . unwrap ( ) ;
let address = listener . local_addr ( ) . unwrap ( ) ;
@ -157,6 +165,7 @@ impl Maker {
_tasks : tasks ,
_tasks : tasks ,
cfd_feed_receiver ,
cfd_feed_receiver ,
order_feed_receiver ,
order_feed_receiver ,
connected_takers_feed_receiver ,
}
}
}
}
@ -192,6 +201,7 @@ impl Maker {
/// Taker Test Setup
/// Taker Test Setup
pub struct Taker {
pub struct Taker {
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 > > ,
cfd_feed_receiver : watch ::Receiver < Vec < Cfd > > ,
@ -219,7 +229,7 @@ impl Taker {
) -> Self {
) -> Self {
let seed = Seed ::default ( ) ;
let seed = Seed ::default ( ) ;
let ( _ , identity_sk ) = seed . derive_identity ( ) ;
let ( identity _pk , identity_sk ) = seed . derive_identity ( ) ;
let db = in_memory_db ( ) . await ;
let db = in_memory_db ( ) . await ;
@ -255,16 +265,20 @@ impl Taker {
ask : Price ::new ( dec ! ( 10000 ) ) . unwrap ( ) ,
ask : Price ::new ( dec ! ( 10000 ) ) . unwrap ( ) ,
} ;
} ;
let ( cfd_feed_sender , cfd_feed_receiver ) = channel ( vec ! [ ] ) ;
let ( cfd_feed_sender , cfd_feed_receiver ) = watch ::channel ( vec ! [ ] ) ;
let ( order_feed_sender , order_feed_receiver ) = channel ::< Option < Order > > ( None ) ;
let ( order_feed_sender , order_feed_receiver ) = watch ::channel ::< Option < Order > > ( None ) ;
let ( update_cfd_feed_sender , _ ) = channel ::< UpdateCfdProposals > ( HashMap ::new ( ) ) ;
let ( update_cfd_feed_sender , _ ) = watch ::channel ::< UpdateCfdProposals > ( HashMap ::new ( ) ) ;
let ( quote_sender , _ ) = channel ::< Quote > ( dummy_quote ) ;
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 (
tasks . add ( projection_context . run ( projection ::Actor ::new (
cfd_feed_sender ,
cfd_feed_sender ,
order_feed_sender ,
order_feed_sender ,
quote_sender ,
quote_sender ,
update_cfd_feed_sender ,
update_cfd_feed_sender ,
connected_takers_feed_sender ,
) ) ) ;
) ) ) ;
tasks . add ( connect (
tasks . add ( connect (
@ -275,6 +289,7 @@ impl Taker {
) ) ;
) ) ;
Self {
Self {
id : TakerId ::new ( identity_pk ) ,
system : taker ,
system : taker ,
mocks ,
mocks ,
_tasks : tasks ,
_tasks : tasks ,