Somnia Markets / TypeScript SDK
Documentation map
This page is the map of the @somnia-chain/markets-sdk documentation. The pages are grouped by what you need right now: to learn, to finish a task, to look something up, or to understand a design. Every TypeScript example has a compile-checked counterpart that uses the public package entrypoints and real dependency types. The tutorials were run on the testnet.
Start here
Two lessons take a newcomer from an empty directory to a cancelled order on the Somnia testnet. Follow them in order. Each one takes about 15 minutes.
- Stream a live order book. No wallet needed. Install the SDK, load the markets, read a book, and watch it change.
- Place and cancel your first order. Fund a testnet key, rest a limit order, see it in your open orders, and cancel it.
Do a task
Goal-shaped guides for a developer who already knows what they want.
- Configure the SDK for testnet, mainnet, or a local chain
- Get testnet funds
- Run a quoting loop: place, amend, and cancel orders from a bot
- Detect when an order fills
- Follow an account's open orders: one complete, live view of an account's orders and stops, its spot orders, its perp positions and its wallet balances
- Sign with a browser wallet
- Trade through a smart account: the accounts SDK's factory accounts as first-class actors
- Use the React hooks
- Handle errors and reverts
- Debug what the SDK is doing
Look something up
Neutral descriptions of the machinery. Facts, defaults, and constraints, without instruction.
- Configuration: every field of
SomniaMarketsConfig, with defaults - Networks and endpoints: chain ids, RPC and indexer URLs, address constants
- Symbols: the symbol grammar and how raw references resolve
- Units and scales: raw versus human values, decimals, basis points, ray, timestamps
- Read tiers: which methods read the live store, the chain, or the indexer
- Errors: the SDK error classes and the contract error names they decode
- The API reference, generated from the source, lists every method, hook, and type. On the docs site it sits in the sidebar under "TypeScript SDK".
Understand the design
Discussion for reading away from the keyboard.
- About the exchange instance: why one object owns the sockets, the store, and the signer
- About symbols and human units: why the exchange API speaks in symbols and decimal numbers, and what that costs
- Binary pool recycling: why one pool address can host successive markets and how to select safe reads
- Architecture: the watch seam, event routing, the local order book, reconnects, and the write path
Area guides
One guide per market family or module. Each one covers reading, trading, and background for its area.
- The exchange API, Spot markets, Binary markets, Perps
- Price feeds, SomniaLend, Smart accounts
- Chains, Bridge, Chains walkthrough
- Native RPC, Reactivity
- The engine: the raw client behind the exchange