@ -15,7 +15,7 @@ use std::borrow::Cow;
use std ::path ::PathBuf ;
use std ::path ::PathBuf ;
use tokio ::select ;
use tokio ::select ;
use tokio ::sync ::watch ;
use tokio ::sync ::watch ;
use xtra ::Address ;
use xtra ::prelude ::MessageChannel ;
#[ rocket::get( " /feed " ) ]
#[ rocket::get( " /feed " ) ]
pub async fn feed (
pub async fn feed (
@ -104,14 +104,13 @@ pub struct CfdOrderRequest {
#[ rocket::post( " /cfd/order " , data = " <cfd_order_request> " ) ]
#[ rocket::post( " /cfd/order " , data = " <cfd_order_request> " ) ]
pub async fn post_order_request (
pub async fn post_order_request (
cfd_order_request : Json < CfdOrderRequest > ,
cfd_order_request : Json < CfdOrderRequest > ,
cfd_actor_inbox : & State < Address < taker_cfd ::Actor > > ,
take_offer_channel : & State < Box < dyn MessageChannel < taker_cfd ::TakeOffer > > > ,
) {
) {
cfd_actor_inbox
take_offer_channel
. do_send_async ( taker_cfd ::TakeOffer {
. do_send ( taker_cfd ::TakeOffer {
order_id : cfd_order_request . order_id ,
order_id : cfd_order_request . order_id ,
quantity : cfd_order_request . quantity ,
quantity : cfd_order_request . quantity ,
} )
} )
. await
. expect ( "actor to always be available" ) ;
. expect ( "actor to always be available" ) ;
}
}
@ -119,9 +118,10 @@ pub async fn post_order_request(
pub async fn post_cfd_action (
pub async fn post_cfd_action (
id : OrderId ,
id : OrderId ,
action : CfdAction ,
action : CfdAction ,
cfd_actor_address : & State < Address < taker_cfd ::Actor > > ,
cfd_action_channel : & State < Box < dyn MessageChannel < taker_cfd ::CfdAction > > > ,
quote_updates : & State < watch ::Receiver < bitmex_price_feed ::Quote > > ,
quote_updates : & State < watch ::Receiver < bitmex_price_feed ::Quote > > ,
) -> Result < status ::Accepted < ( ) > , status ::BadRequest < String > > {
) -> Result < status ::Accepted < ( ) > , status ::BadRequest < String > > {
use taker_cfd ::CfdAction ::* ;
match action {
match action {
CfdAction ::AcceptOrder
CfdAction ::AcceptOrder
| CfdAction ::RejectOrder
| CfdAction ::RejectOrder
@ -132,25 +132,22 @@ pub async fn post_cfd_action(
return Err ( status ::BadRequest ( None ) ) ;
return Err ( status ::BadRequest ( None ) ) ;
}
}
CfdAction ::Commit = > {
CfdAction ::Commit = > {
cfd_actor_address
cfd_action_channel
. do_send_async ( taker_cfd ::Commit { order_id : id } )
. do_send ( Commit { order_id : id } )
. await
. map_err ( | e | status ::BadRequest ( Some ( e . to_string ( ) ) ) ) ? ;
. map_err ( | e | status ::BadRequest ( Some ( e . to_string ( ) ) ) ) ? ;
}
}
CfdAction ::Settle = > {
CfdAction ::Settle = > {
let current_price = quote_updates . borrow ( ) . for_taker ( ) ;
let current_price = quote_updates . borrow ( ) . for_taker ( ) ;
cfd_actor_address
cfd_action_channel
. do_send_async ( taker_cfd ::ProposeSettlement {
. do_send ( ProposeSettlement {
order_id : id ,
order_id : id ,
current_price ,
current_price ,
} )
} )
. await
. expect ( "actor to always be available" ) ;
. expect ( "actor to always be available" ) ;
}
}
CfdAction ::RollOver = > {
CfdAction ::RollOver = > {
cfd_actor_address
cfd_action_channel
. do_send_async ( taker_cfd ::ProposeRollOver { order_id : id } )
. do_send ( ProposeRollOver { order_id : id } )
. await
. expect ( "actor to always be available" ) ;
. expect ( "actor to always be available" ) ;
}
}
}
}