rustrade-execution 0.22.0

Stream private account data from financial venues, and execute (live or mock) orders.
Documentation
//! What a simulated venue holds against a short option.

use rust_decimal::Decimal;
use rustrade_instrument::asset::name::AssetNameExchange;
use serde::{Deserialize, Serialize};

/// How much quote a short put holds on the
/// [`SimulatedVenue`](crate::exchange::mock::SimulatedVenue), which takes only fully secured
/// shorts: a put written against cash set aside to buy the underlying at the strike if it is
/// assigned. See its `# How an option is accounted`.
///
/// Brokers differ on whether the premium the sale receives counts towards that cash. A short call
/// holds the underlying it would deliver, which the premium cannot pay for, so this setting does
/// not apply to it.
#[non_exhaustive]
#[derive(
    Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize,
)]
pub enum ShortPutCollateral {
    /// The account must hold `strike × quantity × contract_size` of quote before the sale, and
    /// the premium it receives does not count towards it. The default, and the stricter rule:
    /// a cash-secured put as the options clearing house's risk disclosure defines it, and as
    /// Interactive Brokers holds it in a cash account.
    #[default]
    Strike,
    /// The premium the sale receives counts towards the strike, so the account needs only
    /// `strike × quantity × contract_size` less that premium beforehand. Alpaca holds a
    /// cash-secured put this way. A limit sale resting on the book holds the strike less the
    /// premium at its limit price, and gives back what a better fill does not need.
    StrikeLessPremium,
}

/// What a short option position holds as collateral on the
/// [`SimulatedVenue`](crate::exchange::mock::SimulatedVenue): `amount` of `asset`, kept out of that
/// asset's `free` balance and still in its `total`. A put holds quote, the strike it would pay; a
/// call holds base, the underlying it would deliver.
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Collateral {
    /// The asset held.
    pub asset: AssetNameExchange,
    /// How much of it is held.
    pub amount: Decimal,
}