pub struct ExpiryManager {
pub expiry_schedules: BTreeMap<u64, Vec<String>>,
}Expand description
Manages instrument expiry schedules and settlement.
Owns the expiry schedules. The canonical expired_instruments map lives in
EngineCtx, and reference_prices lives in EngineDeps to avoid duplication.
Fields§
§expiry_schedules: BTreeMap<u64, Vec<String>>expiry_timestamp → list of symbols
Implementations§
Source§impl ExpiryManager
impl ExpiryManager
Sourcepub fn is_instrument_expired(
&self,
symbol: &str,
orderbooks: &HashMap<String, OrderBook>,
) -> bool
pub fn is_instrument_expired( &self, symbol: &str, orderbooks: &HashMap<String, OrderBook>, ) -> bool
Check if an instrument is expired using canonical orderbook expiry.
Sourcepub fn schedule_expiry(&mut self, symbol: String, expiry_timestamp: u64)
pub fn schedule_expiry(&mut self, symbol: String, expiry_timestamp: u64)
Schedule an expiry for a symbol.
Sourcepub async fn get_settlement_price(
&self,
deps: &EngineDeps,
underlying: &str,
expiry_ts: i64,
) -> Option<Decimal>
pub async fn get_settlement_price( &self, deps: &EngineDeps, underlying: &str, expiry_ts: i64, ) -> Option<Decimal>
Get settlement price from oracle for a specific expiry.
Sourcepub fn transition_to_pending_settlement(
&mut self,
symbols: &[String],
now_ms: u64,
ctx: &mut EngineCtx,
)
pub fn transition_to_pending_settlement( &mut self, symbols: &[String], now_ms: u64, ctx: &mut EngineCtx, )
Transition instruments to EXPIRED_PENDING_PRICE status.
Blocks new orders, cancels open orders, removes orderbooks.
Sourcepub fn update_instrument_status(
&self,
symbols: &[String],
status: &str,
db: Option<&DatabaseHandler>,
)
pub fn update_instrument_status( &self, symbols: &[String], status: &str, db: Option<&DatabaseHandler>, )
Update instrument status in database.
Sourcepub fn get_pending_settlement_instruments(
&self,
db: Option<&DatabaseHandler>,
) -> Vec<(String, i64, Vec<String>)>
pub fn get_pending_settlement_instruments( &self, db: Option<&DatabaseHandler>, ) -> Vec<(String, i64, Vec<String>)>
Get all instruments pending settlement.
Sourcepub async fn prepare_tick_expiry_context(
&self,
now_ms: u64,
ctx: &EngineCtx,
margin_manager: &MarginManager,
) -> Result<TickExpiryContext, String>
pub async fn prepare_tick_expiry_context( &self, now_ms: u64, ctx: &EngineCtx, margin_manager: &MarginManager, ) -> Result<TickExpiryContext, String>
Prepare deterministic context for a TickExpiry command.
This is the runtime side of the TickExpiry boundary. It may read DB state and settlement oracles; apply() must only consume the returned context.
pub(crate) fn prepare_pm_settlements( &self, due_expiries: &[TickExpiryDueGroup], pending_settlements: &[TickExpiryPendingGroup], settlement_prices: &[TickExpirySettlementPrice], margin_modes: &[TickExpiryWalletMarginMode], now_ms: u64, ctx: &EngineCtx, margin_manager: &MarginManager, ) -> Result<Vec<TickExpiryPmSettlement>, String>
fn ordered_due_group_symbols(group: &TickExpiryDueGroup) -> Vec<String>
fn prepare_pm_settlement_fact_bundle( &self, wallet: WalletAddress, underlying: &str, liquid_usdc: Decimal, pool: Option<&PmSettlementPoolState>, now_ms: u64, ctx: &EngineCtx, margin_manager: &MarginManager, ) -> (Option<PmAccountSettlementFacts>, Option<PmSettlementPoolSnapshot>, u32, Option<String>)
fn collect_due_expiries( &self, current_time: u64, db: Option<&DatabaseHandler>, ) -> Result<Vec<TickExpiryDueGroup>, String>
Sourcepub fn apply_tick_expiry(
&mut self,
now_ms: u64,
context: TickExpiryContext,
ctx: &mut EngineCtx,
margin_manager: &MarginManager,
output: &mut ApplyOutput,
) -> Result<(), String>
pub fn apply_tick_expiry( &mut self, now_ms: u64, context: TickExpiryContext, ctx: &mut EngineCtx, margin_manager: &MarginManager, output: &mut ApplyOutput, ) -> Result<(), String>
Apply a TickExpiry command using only explicit command context.
fn validate_tick_expiry_pm_settlements( &self, now_ms: u64, context: &TickExpiryContext, ctx: &EngineCtx, margin_manager: &MarginManager, ) -> Result<(), String>
fn effective_tick_expiry_margin_modes( &self, context: &TickExpiryContext, ctx: &EngineCtx, ) -> Result<HashMap<WalletAddress, MarginMode>, String>
fn priced_symbols_for_context( due_expiries: &[TickExpiryDueGroup], pending_settlements: &[TickExpiryPendingGroup], settlement_prices: &[TickExpirySettlementPrice], ) -> HashSet<String>
fn apply_transition_to_pending_settlement( &mut self, symbols: &[String], now_ms: u64, ctx: &mut EngineCtx, output: &mut ApplyOutput, )
fn apply_expire_instrument( &mut self, symbol: &str, reference_price: Decimal, now_ms: u64, ctx: &mut EngineCtx, output: &mut ApplyOutput, margin_modes: &HashMap<WalletAddress, MarginMode>, pm_settlement_required_wallets: &HashSet<WalletAddress>, pm_settlements: &HashMap<(WalletAddress, String), TickExpiryPmSettlement>, next_pm_settlement_sequence: &mut u64, ) -> Result<ExpireInstrumentApplyResult, String>
Sourcepub async fn check_and_process_expiries(
&mut self,
now_ms: u64,
ctx: &mut EngineCtx,
)
pub async fn check_and_process_expiries( &mut self, now_ms: u64, ctx: &mut EngineCtx, )
Check for expired instruments and process expiries.
Sourcepub async fn expire_instrument(
&mut self,
symbol: &str,
reference_price: Decimal,
now_ms: u64,
ctx: &mut EngineCtx,
) -> Result<(), String>
pub async fn expire_instrument( &mut self, symbol: &str, reference_price: Decimal, now_ms: u64, ctx: &mut EngineCtx, ) -> Result<(), String>
Expire a specific instrument and settle all positions.
Sourcepub fn register_settlements_for_existing_instruments(
&self,
deps: &EngineDeps,
orderbooks: &HashMap<String, OrderBook>,
)
pub fn register_settlements_for_existing_instruments( &self, deps: &EngineDeps, orderbooks: &HashMap<String, OrderBook>, )
Register TWAP settlement windows for all active instruments.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ExpiryManager
impl RefUnwindSafe for ExpiryManager
impl Send for ExpiryManager
impl Sync for ExpiryManager
impl Unpin for ExpiryManager
impl UnsafeUnpin for ExpiryManager
impl UnwindSafe for ExpiryManager
Blanket Implementations§
§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read more§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read more§fn aggregate_filter<P>(self, f: P) -> Self::Outputwhere
P: AsExpression<Bool>,
Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,
fn aggregate_filter<P>(self, f: P) -> Self::Outputwhere
P: AsExpression<Bool>,
Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,
§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> IntoSql for T
impl<T> IntoSql for T
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T, Conn> RunQueryDsl<Conn> for T
impl<T, Conn> RunQueryDsl<Conn> for T
§fn execute<'conn, 'query>(
self,
conn: &'conn mut Conn,
) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>where
Conn: AsyncConnectionCore + Send,
Self: ExecuteDsl<Conn> + 'query,
fn execute<'conn, 'query>(
self,
conn: &'conn mut Conn,
) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>where
Conn: AsyncConnectionCore + Send,
Self: ExecuteDsl<Conn> + 'query,
§fn load<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>where
U: Send,
Conn: AsyncConnectionCore,
Self: LoadQuery<'query, Conn, U> + 'query,
fn load<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>where
U: Send,
Conn: AsyncConnectionCore,
Self: LoadQuery<'query, Conn, U> + 'query,
§fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
Stream] with the returned rows. Read more§fn get_result<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>where
U: Send + 'conn,
Conn: AsyncConnectionCore,
Self: LoadQuery<'query, Conn, U> + 'query,
fn get_result<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>where
U: Send + 'conn,
Conn: AsyncConnectionCore,
Self: LoadQuery<'query, Conn, U> + 'query,
§fn get_results<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>where
U: Send,
Conn: AsyncConnectionCore,
Self: LoadQuery<'query, Conn, U> + 'query,
fn get_results<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>where
U: Send,
Conn: AsyncConnectionCore,
Self: LoadQuery<'query, Conn, U> + 'query,
Vec with the affected rows. Read more§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.