Browse Source
Chose announcement time based on cfd term
compile-for-aarch64
Daniel Karzel
3 years ago
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
2 changed files with
22 additions and
9 deletions
-
daemon/src/maker_cfd.rs
-
daemon/src/oracle.rs
|
|
@ -176,15 +176,8 @@ impl Actor { |
|
|
|
min_quantity: Usd, |
|
|
|
max_quantity: Usd, |
|
|
|
) -> Result<()> { |
|
|
|
let oracle_event_id = self |
|
|
|
.latest_announcements |
|
|
|
.clone() |
|
|
|
.context("Cannot create order because no announcement from oracle")? |
|
|
|
.iter() |
|
|
|
.next_back() |
|
|
|
.context("Empty list of announcements")? |
|
|
|
.0 |
|
|
|
.clone(); |
|
|
|
let oracle_event_id = |
|
|
|
oracle::next_announcement_after(time::OffsetDateTime::now_utc() + Order::TERM); |
|
|
|
|
|
|
|
let order = Order::new( |
|
|
|
price, |
|
|
|
|
|
@ -224,6 +224,16 @@ fn next_24_hours(datetime: OffsetDateTime) -> Vec<OffsetDateTime> { |
|
|
|
(1..=24).map(|i| adjusted + Duration::hours(i)).collect() |
|
|
|
} |
|
|
|
|
|
|
|
#[allow(dead_code)] |
|
|
|
pub fn next_announcement_after(timestamp: OffsetDateTime) -> OracleEventId { |
|
|
|
// always ceil to next hour
|
|
|
|
let adjusted = |
|
|
|
timestamp.replace_time(Time::from_hms(timestamp.hour() + 1, 0, 0).expect("in_range")); |
|
|
|
let event_id = event_url(adjusted); |
|
|
|
|
|
|
|
OracleEventId(event_id) |
|
|
|
} |
|
|
|
|
|
|
|
/// Construct the URL of `olivia`'s `BitMEX/BXBT` event to be attested
|
|
|
|
/// for at the time indicated by the argument `datetime`.
|
|
|
|
fn event_url(datetime: OffsetDateTime) -> String { |
|
|
@ -559,6 +569,16 @@ mod tests { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
#[test] |
|
|
|
fn next_event_url_after_timestamp() { |
|
|
|
let url = next_announcement_after(datetime!(2021-09-23 10:40:00).assume_utc()); |
|
|
|
|
|
|
|
assert_eq!( |
|
|
|
url.0, |
|
|
|
"https://h00.ooo/x/BitMEX/BXBT/2021-09-23T11:00:00.price[n:20]" |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
#[test] |
|
|
|
fn next_24() { |
|
|
|
let datetime = datetime!(2021-09-23 10:43:12); |
|
|
|