Skip to main content
createStore(params?) returns a single object holding pairs, live prices and the trader’s positions, and keeps all three current — replacing the price socket, polls and recompute loop most integrations write by hand.
Each input moves at its own cadence: PnL, liquidation price and accrued rollover are recomputed locally on every tick, using the same math helpers you could call yourself — so a price tick costs no network request.

Parameters

Store interface

State schema

Rendering before the first fetch

pairMeta is populated synchronously from a snapshot shipped with the package, so a market list renders on the first getState() instead of after a round trip. Live data replaces it once getPairs() resolves.
It carries pair names, category, leverage caps and minimum notional only — never prices, open interest or rollover data, which are always fetched live. The same snapshot is exported as PAIR_SNAPSHOT if you want it without a store.

Selectors

Plain functions of state, for the lookups every UI writes by hand:

Using it in React

subscribe and getState already match the contract of React’s useSyncExternalStore, so there is nothing to wire up and React is not an SDK dependency:
memoSelector is required here: useSyncExternalStore needs getSnapshot to return a stable reference, and a selector that builds a fresh array on every call makes React loop. It does not suppress re-renders on unrelated ticks — the store emits a new state whenever any watched price moves. To keep a component still while another pair moves, select a primitive, or compare by content first.

Errors

A failed poll leaves a stale field, not a dead store: the store keeps running and reports the message on lastError.

Exported types

OstiumStore, OstiumStoreState and StorePosition are the shapes above. CreateStoreParams is the parameter object. PairSnapshotEntry is one entry of pairMeta. StoreBackend is the narrow interface the store reads through — subgraph, streamPrices and getBlockNumber. client.createStore() supplies it for you; it is exported so a test can hand the store a fake instead of a network.