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.
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.
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 onlastError.
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.
Related
- Math helpers — the same numbers, without a store
- streamPositionUpdates — re-price a payload you already have
- streamAccountUpdates — low-latency confirmations