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,
},
}