pub struct TradingInstrumentSpec {Show 17 fields
pub instrument: InstrumentId,
pub product: TradingProduct,
pub base_currency: String,
pub quote_currency: String,
pub settlement_currency: String,
pub contract_size: i128,
pub linear: bool,
pub inverse: bool,
pub price_tick: i128,
pub qty_step: i128,
pub min_qty: i128,
pub min_notional_raw: i128,
pub max_leverage: u32,
pub maintenance_margin_bps: u32,
pub valid_from: u64,
pub valid_to: Option<u64>,
pub exact_rules: Option<ExactTradingRules>,
}Fields§
§instrument: InstrumentId§product: TradingProduct§base_currency: String§quote_currency: String§settlement_currency: String§contract_size: i1281.0 表示现货;合约可为 0.001 BTC/contract 或 1 USD/contract。
linear: bool§inverse: bool§price_tick: i128§qty_step: i128§min_qty: i128§min_notional_raw: i128Minimum order notional in quote-currency raw units; zero means the venue did not publish a usable minimum. Kept optional at the JSON boundary for older frozen specs.
max_leverage: u32§maintenance_margin_bps: u32§valid_from: u64§valid_to: Option<u64>§exact_rules: Option<ExactTradingRules>Versioned decimal venue rules. Absent on historical 1e9 specifications.
Implementations§
Source§impl TradingInstrumentSpec
impl TradingInstrumentSpec
Sourcepub fn spot_default(
instrument: &InstrumentId,
settlement_currency: &str,
) -> TradingInstrumentSpec
pub fn spot_default( instrument: &InstrumentId, settlement_currency: &str, ) -> TradingInstrumentSpec
Canonical spot fallback used only when a caller explicitly permits an absent market specification. Keep the fallback definition in the domain contract so report verifiers can reproduce the exact specification used by execution.
pub fn validate(&self) -> Result<(), QxError>
pub fn margin_mode_default(&self) -> MarginMode
Sourcepub fn quote_notional(&self, qty: i128, price: i128) -> Result<i128, QxError>
pub fn quote_notional(&self, qty: i128, price: i128) -> Result<i128, QxError>
Venue order-cost amount in quote-currency raw units. Inverse contracts quote their fixed contract value directly; linear products multiply base quantity by price.
pub fn initial_margin( &self, qty: i128, price: i128, leverage: u32, ) -> Result<i128, QxError>
Sourcepub fn initial_margin_exact(
&self,
quantity: ExactDecimal,
price: ExactDecimal,
leverage: u32,
) -> Result<ExactDecimal, QxError>
pub fn initial_margin_exact( &self, quantity: ExactDecimal, price: ExactDecimal, leverage: u32, ) -> Result<ExactDecimal, QxError>
Exact initial margin for high-precision order and account risk paths. Notional is rounded upward before division, and the resulting required margin is rounded upward again so a sub-nano amount cannot be understated at either step.
Sourcepub fn validate_order(
&self,
qty: i128,
price: Option<i128>,
) -> Result<(), QxError>
pub fn validate_order( &self, qty: i128, price: Option<i128>, ) -> Result<(), QxError>
在进入 OMS/交易所适配器前校验数量和价格的交易所规格约束。
这里不做静默截断或四舍五入;策略目标若无法精确落在 lot/tick 上, 必须显式调整目标或由上层按业务规则拆单,避免回测与实盘产生不同语义。
Sourcepub fn validate_order_with_reference(
&self,
qty: i128,
limit_price: Option<i128>,
reference_price: Option<i128>,
) -> Result<(), QxError>
pub fn validate_order_with_reference( &self, qty: i128, limit_price: Option<i128>, reference_price: Option<i128>, ) -> Result<(), QxError>
Validate a market order against an observed price without treating that reference as a submitted limit price. This checks minimum quote cost while applying the tick rule only to actual limit prices.
Sourcepub fn validate_exact_order_with_reference(
&self,
quantity: ExactDecimal,
limit_price: Option<ExactDecimal>,
reference_price: Option<ExactDecimal>,
) -> Result<(), QxError>
pub fn validate_exact_order_with_reference( &self, quantity: ExactDecimal, limit_price: Option<ExactDecimal>, reference_price: Option<ExactDecimal>, ) -> Result<(), QxError>
Validate high-precision quantity/price values against the frozen venue rules. Amount filters use exact decimal multiples; minimum notional is rounded down so a value below the exchange floor cannot pass due to local rounding.
Sourcepub fn validate_exact_order_precision(
&self,
quantity: ExactDecimal,
limit_price: Option<ExactDecimal>,
) -> Result<(), QxError>
pub fn validate_exact_order_precision( &self, quantity: ExactDecimal, limit_price: Option<ExactDecimal>, ) -> Result<(), QxError>
Validate exact lot/tick/minimum quantity rules without a market-order reference price. The execution boundary uses this before risk evaluation; risk and the venue adapter then check notional using their fresh reference price.
Sourcepub fn validate_exact_quote_budget(
&self,
budget: ExactDecimal,
) -> Result<(), QxError>
pub fn validate_exact_quote_budget( &self, budget: ExactDecimal, ) -> Result<(), QxError>
Validate a quote-currency-sized Spot market buy. This path has no base quantity or limit price to pass through the ordinary lot/tick validator; its exact budget is the order notional and must satisfy the frozen quote-currency minimum.
Sourcepub fn base_quantity_for_quote_budget(
&self,
budget: ExactDecimal,
price: ExactDecimal,
) -> Result<ExactDecimal, QxError>
pub fn base_quantity_for_quote_budget( &self, budget: ExactDecimal, price: ExactDecimal, ) -> Result<ExactDecimal, QxError>
Convert a remaining quote-currency budget into the largest base quantity that fits
the frozen quantity step at price. This is a sizing helper, not a substitute for
validating the original quote budget or the resulting fill.
Sourcepub fn floor_exact_quantity_to_step(
&self,
quantity: ExactDecimal,
) -> Result<ExactDecimal, QxError>
pub fn floor_exact_quantity_to_step( &self, quantity: ExactDecimal, ) -> Result<ExactDecimal, QxError>
Round a non-negative exact quantity down to this instrument’s frozen quantity step.
pub fn quantity_step_exact(&self) -> Result<ExactDecimal, QxError>
Sourcepub fn quote_notional_exact(
&self,
quantity: ExactDecimal,
price: ExactDecimal,
) -> Result<ExactDecimal, QxError>
pub fn quote_notional_exact( &self, quantity: ExactDecimal, price: ExactDecimal, ) -> Result<ExactDecimal, QxError>
Quote-currency order value at a declared 18-place arithmetic scale, rounded down.
Sourcepub fn quote_cash_exact(
&self,
quantity: ExactDecimal,
price: ExactDecimal,
rounding: DecimalRounding,
) -> Result<ExactDecimal, QxError>
pub fn quote_cash_exact( &self, quantity: ExactDecimal, price: ExactDecimal, rounding: DecimalRounding, ) -> Result<ExactDecimal, QxError>
Quote-currency cash flow at the declared exact scale. The caller chooses a conservative rounding direction: round a buy debit away from zero and a sell credit toward zero.
Sourcepub fn notional_exact(
&self,
quantity: ExactDecimal,
price: ExactDecimal,
) -> Result<ExactDecimal, QxError>
pub fn notional_exact( &self, quantity: ExactDecimal, price: ExactDecimal, ) -> Result<ExactDecimal, QxError>
Settlement-currency exposure using exact quantity, price, and contract size. Positive exposure is rounded up so a limit check cannot understate risk.
Sourcepub fn validate_fill(&self, qty: i128, price: i128) -> Result<(), QxError>
pub fn validate_fill(&self, qty: i128, price: i128) -> Result<(), QxError>
校验交易所成交回报的精度约束(tick/step 对齐)。
与 validate_order 的差别是刻意的:min_qty 只约束下单数量,一笔合规订单可以被
拆成多笔小于最小下单量的成交,因此回报侧不套用该下限;落在 tick/step 之外的回报
意味着事实与冻结产品规格冲突,上层必须按未知结果处理而不是静默记账或截断。
Sourcepub fn validate_exact_fill(
&self,
quantity: ExactDecimal,
price: ExactDecimal,
) -> Result<(), QxError>
pub fn validate_exact_fill( &self, quantity: ExactDecimal, price: ExactDecimal, ) -> Result<(), QxError>
Validate exchange execution values at their original decimal precision. Fill quantity is checked against the lot step but not the order minimum, since one accepted order can produce multiple smaller partial fills.
pub fn maintenance_margin( &self, qty: i128, price: i128, ) -> Result<i128, QxError>
Sourcepub fn unrealized_pnl(
&self,
qty: i128,
entry_price: i128,
mark_price: i128,
) -> Result<i128, QxError>
pub fn unrealized_pnl( &self, qty: i128, entry_price: i128, mark_price: i128, ) -> Result<i128, QxError>
线性合约按价格差计算,反向合约按 1/price 计算;qty 可为负表示空头。
Sourcepub fn unrealized_pnl_exact(
&self,
signed_quantity: ExactDecimal,
entry_price: ExactDecimal,
mark_price: ExactDecimal,
) -> Result<ExactDecimal, QxError>
pub fn unrealized_pnl_exact( &self, signed_quantity: ExactDecimal, entry_price: ExactDecimal, mark_price: ExactDecimal, ) -> Result<ExactDecimal, QxError>
Compute derivative PnL in settlement currency without projecting quantity or prices onto the legacy 1e-9 grid. A signed quantity is positive for a long and negative for a short. Positive PnL rounds down and losses round toward negative infinity so accounting never overstates gains or understates losses.
pub fn funding_payment( &self, qty: i128, mark_price: i128, funding_rate_bps: i64, ) -> Result<i128, QxError>
Sourcepub fn funding_payment_exact(
&self,
signed_quantity: ExactDecimal,
mark_price: ExactDecimal,
funding_rate_bps: i64,
) -> Result<ExactDecimal, QxError>
pub fn funding_payment_exact( &self, signed_quantity: ExactDecimal, mark_price: ExactDecimal, funding_rate_bps: i64, ) -> Result<ExactDecimal, QxError>
Scale-aware funding amount before applying the cashflow sign. Positive values mean the position pays the venue when the rate is positive; negative quantities reverse that direction. This keeps sub-1e-9 quantities and prices intact for small contracts.
Trait Implementations§
Source§impl Clone for TradingInstrumentSpec
impl Clone for TradingInstrumentSpec
Source§fn clone(&self) -> TradingInstrumentSpec
fn clone(&self) -> TradingInstrumentSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more