diff --git a/daemon/src/db.rs b/daemon/src/db.rs index 0d96ddf..e4d444d 100644 --- a/daemon/src/db.rs +++ b/daemon/src/db.rs @@ -812,6 +812,7 @@ mod tests { Usd::new(dec!(1000)), Origin::Theirs, BitMexPriceEventId::with_20_digits(OffsetDateTime::now_utc()), + time::Duration::hours(24), ) .unwrap() } diff --git a/daemon/src/maker.rs b/daemon/src/maker.rs index 7b3e158..eac861e 100644 --- a/daemon/src/maker.rs +++ b/daemon/src/maker.rs @@ -53,6 +53,10 @@ struct Opts { #[clap(short, long)] json: bool, + /// The term length of each CFD in hours. + #[clap(long, default_value = "24")] + term: u8, + #[clap(subcommand)] network: Network, } @@ -203,6 +207,7 @@ async fn main() -> Result<()> { }, |channel0, channel1| maker_inc_connections::Actor::new(channel0, channel1), listener, + time::Duration::hours(opts.term as i64), ) .await?; @@ -265,6 +270,7 @@ where + xtra::Handler + xtra::Handler, { + #[allow(clippy::too_many_arguments)] pub async fn new( db: SqlitePool, wallet: Wallet, @@ -276,6 +282,7 @@ where Box>, ) -> T, listener: TcpListener, + term: time::Duration, ) -> Result where F: Future>, @@ -296,6 +303,7 @@ where let cfd_actor_addr = maker_cfd::Actor::new( db, wallet, + term, oracle_pk, cfd_feed_sender, order_feed_sender, diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 2941202..f4e212b 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -21,6 +21,7 @@ use sqlx::pool::PoolConnection; use sqlx::Sqlite; use std::collections::HashMap; use std::time::SystemTime; +use time::Duration; use tokio::sync::watch; use xtra::prelude::*; @@ -62,6 +63,7 @@ pub struct FromTaker { pub struct Actor { db: sqlx::SqlitePool, wallet: Wallet, + term: Duration, oracle_pk: schnorrsig::PublicKey, cfd_feed_actor_inbox: watch::Sender>, order_feed_sender: watch::Sender>, @@ -98,6 +100,7 @@ impl Actor { pub fn new( db: sqlx::SqlitePool, wallet: Wallet, + term: Duration, oracle_pk: schnorrsig::PublicKey, cfd_feed_actor_inbox: watch::Sender>, order_feed_sender: watch::Sender>, @@ -109,6 +112,7 @@ impl Actor { Self { db, wallet, + term, oracle_pk, cfd_feed_actor_inbox, order_feed_sender, @@ -637,7 +641,7 @@ where max_quantity: Usd, ) -> Result<()> { let oracle_event_id = - oracle::next_announcement_after(time::OffsetDateTime::now_utc() + Order::TERM)?; + oracle::next_announcement_after(time::OffsetDateTime::now_utc() + self.term)?; self.oracle_actor .do_send_async(oracle::FetchAnnouncement(oracle_event_id)) @@ -649,6 +653,7 @@ where max_quantity, Origin::Ours, oracle_event_id, + self.term, )?; // 1. Save to DB diff --git a/daemon/src/model/cfd.rs b/daemon/src/model/cfd.rs index 34ce357..a6af4e0 100644 --- a/daemon/src/model/cfd.rs +++ b/daemon/src/model/cfd.rs @@ -125,14 +125,13 @@ pub struct Order { } impl Order { - pub const TERM: Duration = Duration::hours(24); - pub fn new( price: Usd, min_quantity: Usd, max_quantity: Usd, origin: Origin, oracle_event_id: BitMexPriceEventId, + term: Duration, ) -> Result { let leverage = Leverage(2); let maintenance_margin_rate = dec!(0.005); @@ -149,7 +148,7 @@ impl Order { liquidation_price, position: Position::Sell, creation_timestamp: SystemTime::now(), - term: Self::TERM, + term, origin, oracle_event_id, })