Browse Source

Allow term to be configurable on the maker's commandline

The default value is still 24 hours but now we can configure it to
be any number of hours between 0 and 127.
contact-taker-before-changing-cfd-state
Thomas Eizinger 3 years ago
committed by Philipp Hoenisch
parent
commit
d2f0d0be9f
No known key found for this signature in database GPG Key ID: E5F8E74C672BC666
  1. 1
      daemon/src/db.rs
  2. 8
      daemon/src/maker.rs
  3. 7
      daemon/src/maker_cfd.rs
  4. 5
      daemon/src/model/cfd.rs

1
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()
}

8
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<maker_inc_connections::BroadcastOrder>
+ xtra::Handler<maker_inc_connections::ListenerMessage>,
{
#[allow(clippy::too_many_arguments)]
pub async fn new<F>(
db: SqlitePool,
wallet: Wallet,
@ -276,6 +282,7 @@ where
Box<dyn MessageChannel<FromTaker>>,
) -> T,
listener: TcpListener,
term: time::Duration,
) -> Result<Self>
where
F: Future<Output = Result<M>>,
@ -296,6 +303,7 @@ where
let cfd_actor_addr = maker_cfd::Actor::new(
db,
wallet,
term,
oracle_pk,
cfd_feed_sender,
order_feed_sender,

7
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<O, M, T> {
db: sqlx::SqlitePool,
wallet: Wallet,
term: Duration,
oracle_pk: schnorrsig::PublicKey,
cfd_feed_actor_inbox: watch::Sender<Vec<Cfd>>,
order_feed_sender: watch::Sender<Option<Order>>,
@ -98,6 +100,7 @@ impl<O, M, T> Actor<O, M, T> {
pub fn new(
db: sqlx::SqlitePool,
wallet: Wallet,
term: Duration,
oracle_pk: schnorrsig::PublicKey,
cfd_feed_actor_inbox: watch::Sender<Vec<Cfd>>,
order_feed_sender: watch::Sender<Option<Order>>,
@ -109,6 +112,7 @@ impl<O, M, T> Actor<O, M, T> {
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

5
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<Self> {
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,
})

Loading…
Cancel
Save