Skip to main content

TradingInstrumentSpec

Struct TradingInstrumentSpec 

Source
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: i128

1.0 表示现货;合约可为 0.001 BTC/contract 或 1 USD/contract。

§linear: bool§inverse: bool§price_tick: i128§qty_step: i128§min_qty: i128§min_notional_raw: i128

Minimum 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

Source

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.

Source

pub fn validate(&self) -> Result<(), QxError>

Source

pub fn margin_mode_default(&self) -> MarginMode

Source

pub fn notional(&self, qty: i128, price: i128) -> Result<i128, QxError>

返回结算币种定点原始值的名义额。

Source

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.

Source

pub fn initial_margin( &self, qty: i128, price: i128, leverage: u32, ) -> Result<i128, QxError>

Source

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.

Source

pub fn validate_order( &self, qty: i128, price: Option<i128>, ) -> Result<(), QxError>

在进入 OMS/交易所适配器前校验数量和价格的交易所规格约束。

这里不做静默截断或四舍五入;策略目标若无法精确落在 lot/tick 上, 必须显式调整目标或由上层按业务规则拆单,避免回测与实盘产生不同语义。

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn quantity_step_exact(&self) -> Result<ExactDecimal, QxError>

Source

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.

Source

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.

Source

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.

Source

pub fn validate_fill(&self, qty: i128, price: i128) -> Result<(), QxError>

校验交易所成交回报的精度约束(tick/step 对齐)。

与 validate_order 的差别是刻意的:min_qty 只约束下单数量,一笔合规订单可以被 拆成多笔小于最小下单量的成交,因此回报侧不套用该下限;落在 tick/step 之外的回报 意味着事实与冻结产品规格冲突,上层必须按未知结果处理而不是静默记账或截断。

Source

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.

Source

pub fn maintenance_margin( &self, qty: i128, price: i128, ) -> Result<i128, QxError>

Source

pub fn unrealized_pnl( &self, qty: i128, entry_price: i128, mark_price: i128, ) -> Result<i128, QxError>

线性合约按价格差计算,反向合约按 1/price 计算;qty 可为负表示空头。

Source

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.

Source

pub fn funding_payment( &self, qty: i128, mark_price: i128, funding_rate_bps: i64, ) -> Result<i128, QxError>

Source

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

Source§

fn clone(&self) -> TradingInstrumentSpec

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TradingInstrumentSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for TradingInstrumentSpec

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<TradingInstrumentSpec, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for TradingInstrumentSpec

Source§

impl PartialEq for TradingInstrumentSpec

Source§

fn eq(&self, other: &TradingInstrumentSpec) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for TradingInstrumentSpec

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for TradingInstrumentSpec

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.