Create a new PerpetualsMarket wrapper from raw market data.
Snapshot of market configuration and state.
Optionalconfig: CallerConfig
Optional CallerConfig (network, base URL, etc.).
Optionalapi: AftermathApi
Optional shared AftermathApi provider instance.
Optionalmetadata: PerpetualsMarketMetadata | null
Optional display metadata for the market.
This class extends Caller with the "perpetuals" route prefix, meaning
all HTTP requests resolve under /perpetuals/....
Optional ReadonlyapiOptional shared AftermathApi provider instance.
ReadonlycollateralSui type of the collateral coin (e.g. "0x2::sui::SUI").
ReadonlycollateralCurrent price of the collateral asset in USD (or the platform's base pricing unit).
The mutable configuration used for subsequent requests.
ReadonlyindexCurrent oracle/index price for the market's underlying asset, quoted in the index unit (typically USD).
Snapshot of market configuration and state.
ReadonlymarketUnique identifier for this perpetuals market (object ID on chain).
ReadonlymarketStatic market configuration parameters (lot size, tick size, margins, etc.).
ReadonlymarketDynamic market state (funding rates, open interest, etc.).
ReadonlymetadataDisplay metadata (symbol, label, artwork, category) for this market, or
null when none is available.
Calculate the collateral required to support an order given leverage and prices.
The computed collateral is based on the remaining unfilled size:
remaining = initialSize - filledSize.
USD requirement:
remainingBase * indexPrice * initialMarginRatio
where initialMarginRatio = 1 / leverage (or 1 if leverage is falsy).
Price of the collateral asset.
Index/oracle price of the base asset.
Target leverage for the order (>= 1).
Order data containing initialSize and filledSize.
Object with:
collateralUsd: required collateral in USDcollateral: required collateral in collateral coin unitsConstruct an "empty" position object for this market.
Useful when an account has no open position but downstream UI/calculations expect a PerpetualsPosition-shaped object.
A zeroed-out PerpetualsPosition for this.marketId.
Estimated funding rate per period for this market.
This is read directly from marketData.estimatedFundingRate.
Estimated funding rate as a fraction (e.g. 0.01 = 1%).
Fetch the 24-hour volume and price change statistics for this market.
Under the hood, this calls Perpetuals.getMarkets24hrStats and returns the first (and only) entry.
PerpetualsMarket24hrStats.
This method creates a new Perpetuals instance using this.config.
If you need shared api behavior, prefer calling perps.getMarkets24hrStats
directly with the same api you initialized.
Compute the maximum order size that can be placed by a given account in this market, under optional leverage and price assumptions.
This is a common frontend helper for:
Note: This is routed through the account namespace because it depends on
the account's collateral and positions.
Perpetuals account ID.
Order side (Bid/Ask).
Optional assumed leverage.
Optional assumed price (e.g. for limit orders).
{ maxOrderSize } in base units (scaled integer as bigint).
Fetch the full orderbook snapshot for this market.
Object containing orderbook.
Fetch paginated order history for this market.
This is market-wide (public) history, not scoped to any account.
Optional pagination cursor.
Optional page size.
ApiPerpetualsMarketOrderHistoryResponse containing:
ordersnextBeforeTimestampCursorMarket-level preview of placing a limit order.
Similar to getPlaceMarketOrderPreview, this uses:
account/previews/place-limit-orderaccountId: undefinedOptionalabortSignal: AbortSignal
Optional abort signal to cancel the request.
Either { error } or a preview describing the simulated post-order state.
Market-level preview of placing a market order.
Unlike PerpetualsAccount.getPlaceMarketOrderPreview, this version:
account/previews/place-market-orderaccountId: undefined, allowing a “generic” preview that
doesn’t rely on a specific account’s on-chain positions/collateral.OptionalabortSignal: AbortSignal
Optional abort signal to cancel the request.
Either { error } or a preview containing the simulated updated position,
slippage, filled/posted sizes, collateral change, and execution price.
Market-level preview of placing a scale order.
Similar to getPlaceLimitOrderPreview, this uses:
account/previews/place-scale-orderaccountId: undefinedOptionalabortSignal: AbortSignal
Optional abort signal to cancel the request.
Either { error } or a preview describing the simulated post-order state.
Fetch the current prices for this market.
Internally calls Perpetuals.getPrices and returns the first result.
{ marketId, basePrice, collateralPrice, midPrice, markPrice }.
This method instantiates a new Perpetuals client using this.config.
If you rely on a shared api, call perps.getPrices(...) directly instead.
Get the initial margin ratio for this market.
This is the minimum margin required when opening a position.
Initial margin ratio as a fraction (e.g. 0.05 = 20x).
Get the base-asset lot size for this market as a number.
Order sizes must be multiples of this lot size.
Lot size in base asset units.
Get the maintenance margin ratio for this market.
Falling below this ratio may trigger liquidation.
Maintenance margin ratio as a fraction.
Get the maximum theoretical leverage for this market.
Computed as:
1 / marginRatioInitial
Maximum leverage.
Get the scheduled timestamp for the next funding event, in milliseconds.
Safety behavior:
marketData.nextFundingTimestampMs exceeds Number.MAX_SAFE_INTEGER,
this returns Number.MAX_SAFE_INTEGER.Next funding timestamp (ms) as a JS number.
Round a price to the nearest valid tick for this market.
Rounding mode:
floor: true => round downceil: true => round upMath.round)Optionalceil?: booleanForce ceil rounding.
Optionalfloor?: booleanForce floor rounding.
Raw price to round.
Price snapped to the market tick size.
Round a price to the nearest valid tick as a fixed-point bigint (1e9 precision).
This is helpful when you need the on-chain representation directly (e.g. order price fields stored in 9-decimal fixed).
Optionalceil?: booleanForce ceil rounding.
Optionalfloor?: booleanForce floor rounding.
Raw price as a JS number.
Tick-snapped price scaled by 1e9.
Round a base-asset size to the nearest valid lot size for this market.
Rounding mode:
floor: true => round downceil: true => round upMath.round)Optionalceil?: booleanForce ceil rounding.
Optionalfloor?: booleanForce floor rounding.
Raw size in base asset units.
Size snapped to the market lot size.
Round a base-asset size to the nearest valid lot as a fixed-point bigint (1e9 precision).
Optionalceil?: booleanForce ceil rounding.
Optionalfloor?: booleanForce floor rounding.
Raw base size as a JS number.
Lot-snapped size scaled by 1e9.
Get the minimal price tick size for this market as a number.
Limit prices must be multiples of this tick size.
Tick size in quote units (e.g. USD).
Compute the remaining time until the next funding event, in milliseconds.
nextFundingTimeMs() - Date.now().
If the next funding timestamp does not fit safely into a JS number,
nextFundingTimeMs returns Number.MAX_SAFE_INTEGER, and the
difference may be very large.
StaticapiReturns the canonical Aftermath API host for a Sui network.
To target a custom or local host, pass baseUrl in CallerConfig to the
constructor instead.
The Sui network whose host to return.
The network's HTTPS or local HTTP API host.
StaticdefaultReturns the canonical Sui fullnode URL for a network.
The network whose fullnode URL to return. undefined
defaults to mainnet.
The network's fullnode URL.
High-level wrapper around a single perpetuals market.
This class provides:
marketId,indexPrice,collateralPrice,collateralCoinTypemarketParams,marketStateTypical usage: