# SYMMIO Trading-SDK > SDK for building perps trading UIs on SYMMIO. Two layers: @symmio/trading-core (framework-agnostic actions, query-option factories, typed errors) and @symmio/trading-react (hooks + SymmioProvider on wagmi + TanStack Query). Supported trading chains: Arbitrum (42161) and Base (8453). ## Which package The SDK ships several packages. The two that matter are `@symmio/trading-react` and `@symmio/trading-core`; pick by stack: - **Building with React? Use `@symmio/trading-react`.** Hooks plus `SymmioProvider` on wagmi + TanStack Query, with the stores, cache invalidation, and WebSocket wiring a trading UI needs already built in. Do NOT rebuild that layer on core inside a React app. Also add `@symmio/trading-core` as a direct dependency for the types that live only in core (see "Some types live only in core" below). Start here: https://doc.trading-sdk.symm.io/react/getting-started - **Plain JavaScript / TypeScript (Node.js, bots, scripts) or another framework (Vue, Solid, Svelte)? Use `@symmio/trading-core`.** Framework-agnostic actions and query-option factories over viem; you own state, caching, and sockets. Start here: https://doc.trading-sdk.symm.io/core/getting-started - Optional companions: `@symmio/utils` (amount formatting, input parsing, address helpers; the most-used ones are re-exported from `@symmio/trading-react`) and `@symmio/session-key` (local session-key manager for promptless trading). ## Read these first - Getting started (React): https://doc.trading-sdk.symm.io/react/getting-started - Build a Perps DEX (the end-to-end guide): https://doc.trading-sdk.symm.io/guides/build-a-dex/react - Balance Model: https://doc.trading-sdk.symm.io/core/concepts/balance-model - Solvers & Chains (lowcap vs majors): https://doc.trading-sdk.symm.io/core/concepts/solvers-and-chains - Config: https://doc.trading-sdk.symm.io/core/concepts/config ## Facts agents most often get wrong 1. **Affiliate is optional for trading, but never an arbitrary address.** Every chain you key in `symmioConfig` (`createConfig` / `SymmioProvider`) must set `addresses.affiliatesAddress`, or config creation throws `AFFILIATE_ADDRESS_REQUIRED`. The **zero address is a valid placeholder**: trades open, you just earn no fee share. A **non-zero, unregistered** address (e.g. the user's own wallet) reverts every open on-chain with `PartyAFacet: Invalid affiliate`. Registrations are per chain. Do NOT make users register before trading; register only to earn fees: https://doc.trading-sdk.symm.io/guides/affiliate-registration 2. **Pass only your affiliate; the SDK ships every other address.** Contract addresses (`symmioAddress`, `instantLayerAddress`, `accountLayerAddress`, `collateralAddress`, `collateralDecimals`) and endpoints (solvers, subgraphs, price service, Muon, gasless) are built in for each supported chain. The minimal config is `symmioConfig: { [SymmioSupportedChainId.ARBITRUM]: { addresses: { affiliatesAddress } } }`. Overrides deep-merge field by field, so to point at a different deployment pass only the fields that differ. Do NOT copy the full address block from the docs or registry into your config: a hardcoded copy goes stale when the SDK ships updated deployments. 3. **The margin model follows the sub-account's isolation type, not the chain.** Read it with `useSubAccount({ account }).data.isolationType` and branch on `SubAccountIsolationType.CUSTOM`, never on a chain id. - **VA isolations** (`POSITION` / `MARKET` / `MARKET_DIRECTION`; lowcap, Arbitrum): instant opens spend the **available** balance and move it into a Virtual Account. Fund with `useDeposit` / `depositForAccount` and trade; there is **no allocate step**, and allocating *removes* funds an open can spend. Display `useAccountBalanceOf`. - **`CUSTOM` (cross-margin; majors, Base)**: trades run on the sub-account itself (**no Virtual Account**, so never select or predict one) and spend the **allocated** balance. Fund with `useDepositAndAllocate` / `depositAndAllocateForAccount`. Display `useAccountBalanceInfo().data.allocatedBalance`. 4. **Two decimal scales.** Token units (`collateralDecimals`, 6 for USDC): deposit, deposit-and-allocate, and withdraw amounts; wallet collateral balance; gasless-wallet balances and deposit fees. Core units (18 decimals): every account balance (available, allocated, locks), allocate / deallocate / addMargin / removeMargin amounts, quote values, operational-fee allowances and `GaslessFeeQuote` amounts. Parse deposit input with `parseUnits(input, collateralDecimals)`, never `parseEther`. Convert with `collateralToCore18` / `core18ToCollateral`; the latter rounds **up** by default, so pass `{ rounding: "down" }` when turning an 18-decimal balance into a withdraw max. 5. **Trade-form Max is not the raw balance.** Use `useAvailableInstantOpenMargin({ account, symbolId, leverage, positionType, slippage })` and gate submit on it. On VA isolations it is the available balance minus the open fee and, for SHORT only, a worst-case slippage fill (the close fee is charged at close, not reserved). On `CUSTOM` it is allocated + uPnL − locked margin − pending opens, clamped at zero, and only 90% of that on the Rasa solver. 6. **Grant the session key the chain's selector set, and gate every write on it.** Grant `useSessionKeySelectors()` / `getSessionKeySelectors(config, { chainId })`; check with `useAreDelegationsActive({ account, delegate, selectors })` using the same set. Do NOT hardcode `INSTANT_TRADE_REQUIRED_SELECTORS`: Base runs contracts 0.8.5, whose open leg is the legacy `sendQuoteWithAffiliateAndData`. On a chain without gasless (`supportsGaslessService(config, { chainId })` is `false`, Base today) request `{ account: false }`, or the call throws `SESSION_KEY_SELECTORS_UNSUPPORTED_CHAIN`. Gate open, close, AND TP/SL: the solver accepts the POST and the on-chain call reverts later, which looks like a silent failure. Persist the session key in durable storage and reload it (`manager.initialize(owner)`); minting a new key per page load drops every delegation. 7. **TP/SL needs a second delegation and is not on every chain.** Check `supportsTpSl(config, { chainId, solverId })` (from core) first; Base has no TP/SL today. Where supported, the solver's COH wallet executes the trigger, so the sub-account must also delegate `REQUEST_TO_CLOSE_POSITION_SELECTOR` to `config.getSolver({ chainId }).tpsl.cohWalletAddress`. Without it the trigger reverts when it fires. 8. **WebSocket is authoritative, not the POST.** Instant open/close/TP-SL success responses mean "accepted", not "done". Drive UI state from `useManagedQuotes` lifecycles and `useQuoteTpSl` states (`"confirming"` = accepted, still processing), never from `mutation.isSuccess`. 9. **Some types live only in core.** `@symmio/trading-react` re-exports common enums and constants (`PositionType`, `OrderType`, `QuoteStatus`, `SubAccountIsolationType`, the selector constants), but **not** `SymmioSupportedChainId`, `UnifiedQuote`, `QuoteLifecycle`, `SymmioChainConfig`, `SolverId`, `supportsTpSl`, `collateralToCore18` / `core18ToCollateral`. Import those from `@symmio/trading-core`. 10. **Stack.** Peer deps: `react` / `react-dom` ^19, `wagmi` ^3.4.2, `viem` ^2.49. Use Next 16; on Next 15, add `wagmi` to `transpilePackages` or the build fails with `Actions.wallet.send is not exported from 'viem/tempo'`. Keep exactly one wagmi copy (otherwise `useConfig must be used within WagmiProvider`). Any package manager works. ## Reference - Core catalog: https://doc.trading-sdk.symm.io/core - React hook catalog: https://doc.trading-sdk.symm.io/react - Core-only DEX guide (no React): https://doc.trading-sdk.symm.io/guides/build-a-dex/core - Errors: https://doc.trading-sdk.symm.io/core/concepts/errors - Session keys: https://doc.trading-sdk.symm.io/session-key ## Complete pending withdrawals across accounts Use `usePendingWithdrawRequestsBatch({ users, chainId, pageSize: 200n })` in React to read all pages for multiple subaccounts. It normalizes user ordering, case and duplicates; an empty list disables automatic reads, and any failed page rejects the whole query. Requests are grouped by user. Raw core: `getPendingWithdrawRequestsBatch`. Reference: https://doc.trading-sdk.symm.io/core/symmio-contract/get-pending-withdraw-requests-batch and https://doc.trading-sdk.symm.io/react/withdraw#usependingwithdrawrequestsbatch ## Withdraw and deallocate timing `useWithdrawableTime({ user })` tells when a withdrawal initiated now could finalize; use it for readiness. `useWithdrawCooldownOf({ user })` is the raw `deallocateTimestamp` in Unix seconds, a timestamp and not a duration. `useDeallocateDebounceTime()` is the protocol's minimum gap between two deallocations of one account, so the next deallocate succeeds once `withdrawCooldownOf + debounce` has passed. There is no hook for `executeAccountCalls` (arbitrary core writes run atomically): use `useWithdraw` for an atomic deallocate plus initiate, or wrap `executeAccountCallsMutationOptions` in `useMutation` and refresh the reads your calls change. Reference: https://doc.trading-sdk.symm.io/react/withdraw#usewithdrawcooldownof and https://doc.trading-sdk.symm.io/core/symmio-contract/execute-account-calls