Ecosystem Builders
This section is for teams building apps, analytics, or integrations on top of Velocity. Beyond the core @velocity-exchange/sdk (VelocityClient, User, and DLOB classes), Velocity publishes @velocity-exchange/common for shared order/auction math and swift-order construction, and @velocity-exchange/react for React hooks/providers/wallet glue. Ecosystem apps can build directly against the SDK, or pull in these packages for the same building blocks the Velocity UI uses.
Setup
Every app starts by creating a VelocityClient, subscribing to on-chain data, and reading from its caches.
Initialize and subscribe
import { Connection } from "@solana/web3.js";
import { VelocityClient, Wallet, loadKeypair } from "@velocity-exchange/sdk";
const connection = new Connection("<RPC_URL>", "confirmed");
const wallet = new Wallet(loadKeypair("<KEYPAIR_PATH>")); // or a connected wallet-adapter wallet
const velocityClient = new VelocityClient({
connection,
wallet,
env: "mainnet-beta",
});
await velocityClient.subscribe();See SDK Setup for the full VelocityClientConfig reference, including polling vs. websocket subscription modes and market/oracle subsets.
Read account and market caches
Once subscribed, VelocityClient exposes account and market data synchronously from its subscriber caches: no additional RPC round-trip per read:
const state = velocityClient.getStateAccount();
const perpMarket = velocityClient.getPerpMarketAccount(0); // SOL-PERP
const user = velocityClient.getUser(); // active subaccount's User wrapper
const health = user.getHealth(); // 0-100
const totalCollateral = user.getTotalCollateral();
const perpPosition = user.getPerpPosition(0);See Reading Data for the full set of account/market/orderbook read paths, and PnL & Risk for margin/health calculations.
React apps
@velocity-exchange/react provides hooks, providers, and Zustand stores for wallet and client lifecycle. If you’d rather not depend on it, wrap VelocityClient construction and subscription lifecycle in your own hook/provider (e.g. a useEffect that constructs the client on wallet connect and calls subscribe()/unsubscribe()), and store the derived state (positions, orders, margin) in your own state manager (Zustand, Redux, React context, etc). See Reading Data for the read APIs to wire up.
Next steps
- Reading data: Account data (positions, orders, balances, collateral), market data (oracle/mark prices, orderbook, candles), and Data API REST endpoints
- Sending actions:
VelocityClientmethods (orders, cancel, settle PnL, deposit, withdraw) and statelessVelocityCoreinstruction builders - Orderbook + DLOB websocket: L2/L3 REST snapshots and real-time DLOB websocket streaming
- SDK Setup: Full
VelocityClientinitialization reference
Staying up to date
- GitHub: velocity-v1 : the monorepo containing the program, SDK, vaults, and keeper bots; watch releases for SDK breaking changes
- Migration guide: full list of behavioral and SDK differences to check when porting an existing integration
- Data API playground