use chrono::{DateTime, Utc};
use derive_more::Constructor;
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, Constructor)]
pub struct FillRecoveryGap<InstrumentKey> {
pub scope: FillRecoveryScope<InstrumentKey>,
pub start: DateTime<Utc>,
pub end: DateTime<Utc>,
pub attempts: u32,
pub reason: FillRecoveryFailure,
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub enum FillRecoveryScope<InstrumentKey> {
Instruments(Vec<InstrumentKey>),
AllInstruments,
}
impl<InstrumentKey> FillRecoveryScope<InstrumentKey> {
pub fn instrument_filter(&self) -> &[InstrumentKey] {
match self {
Self::Instruments(instruments) => instruments,
Self::AllInstruments => &[],
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, Error)]
pub enum FillRecoveryFailure {
#[error("request failed: {0}")]
Request(String),
#[error("timed out after {timeout_secs}s")]
TimedOut {
timeout_secs: u64,
},
#[error("truncated after {fills_read} fills")]
Truncated {
fills_read: usize,
},
#[error("the venue holds fills only from {held_since}")]
VenueRetention {
held_since: DateTime<Utc>,
},
#[error("older than the maximum span of {max_span_secs}s")]
SpanLimit {
max_span_secs: u64,
},
#[error("stopped after {max_pages} reads")]
PageLimit {
max_pages: u32,
},
}