Skip to main content
Trading instructions read live spot prices from Pyth and baseline Historical Volatility from Market Data (MarketDataAccount). SOS-SDK also includes a bit-exact Black-Scholes mirror and collateral estimators for UI previews.

Pyth Spot Feed and Freshness

Trading builders take priceUpdateAccount, which must be the shard-0 Pyth price feed account for the underlying asset’s feed ID. Resolve the feed ID from MarketDataAccount, derive the shard-0 feed address, and check freshness before submitting a trade:
The onchain program rejects spot prices older than 20 seconds (StaleOraclePrice, 6016). Pass maxAgeSeconds strictly below 20 (for example 15) to evaluatePythPriceUpdate so the price stays fresh while your transaction is in flight.

Historical Volatility

Baseline Historical Volatility is stored directly on MarketDataAccount.historicalVolatilityPpm in parts per million (1_000_000 equals 100%). An offchain volatility worker computes 90-day realized volatility and writes it onchain through update_market_data. Pricing instructions do not read an external volatility oracle account. Read the stored baseline volatility and risk-free rate from MarketDataAccount for display pricing or opening margin estimates:
The onchain program enforces a 6-hour freshness limit (21,600 seconds) on MarketDataAccount.lastUpdated. Pricing instructions fail with StaleMarketData (6011) if stored Historical Volatility is older than 6 hours, or VolatilityQuoteUnavailable (6019) if historicalVolatilityPpm is outside [0, 4_000_000].
All trading and series-initialization builders populate the unused legacy volatility_quote_account instruction ABI slot internally.

Black-Scholes Display Pricing

priceOption is a fixed-point Black-Scholes mirror of the onchain model. Its premiumNanoUsd and thetaNanoUsd match the program bit for bit, and it also returns client-side Greeks (deltaNano, gammaNano, vegaNanoUsd, rhoNanoUsd).
priceOption prices one unit of the underlying. One listed contract covers UNDERLYING_UNITS_PER_CONTRACT (100) units. Use the high-level buy and close builders for executable premiums that include pool size adjustments and slippage caps.

Estimating Writer Collateral

Use calculateRequiredCollateral to estimate Writer collateral in Collateral Mint base units before minting a Short:
calculateRequiredCollateral defaults to "physical" when the fifth argument is omitted. Every Option Series on this program is cash-settled, so always pass "cash" and the Collateral Mint’s decimals.

Estimating Opening Margin

Every minted Short leg must clear the program’s conservative post-fill opening margin check (OpeningMarginNotMet, 6171). Use computeMinimumOpeningOwnCollateralBaseUnits to compute the exact minimum own collateral in Collateral Mint base units that satisfies both the opening margin check and the OMLP vault leverage floor: