@coldbell/decidash-ts-sdk
v1.17.1
Published
TypeScript SDK for the decidash
Readme
Decidash TS SDK
Package Install
pnpm add @coldbell/decidash-ts-sdkInstall & Build
pnpm install
pnpm buildRun Example
npx tsx example/account.ts
npx tsx example/contract.ts
npx tsx example/market.ts
npx tsx example/websocket.ts
npx tsx example/traders.tsSDK Structure (excluding /src/contract)
src/config.ts: defines theDeciDashConfiginterface plus ready-to-use presets (e.g.,DeciDashConfig.DEVNET) and theMARKET_LISThelper. OverridefetchFnorWebSocketCtorhere to adapt to SSR/React Native environments.src/api/index.ts: re-exports every public helper so consumers can import from the package root (import { getMarkets } from "decidash-ts-sdk").src/api/utils.ts: typedget/postwrappers that honor the injectedfetchFnand raise on non-OK responses.src/api/types.ts: source of truth for all DTOs covering markets, orders, asset contexts, funding history, leaderboard entries, portfolio charts, plus WebSocket payloads. Keep these synced with backend schema to preserve type safety across the app.
HTTP API Clients (src/api)
market.tsexposes REST helpers such asgetMarkets,getMarketPrices,getMarketDepth,getMarketCandlesticks,getAssetContexts,getDexRegistration, andgetLeaderboard. Query strings are built via a shared utility, and legacy aliases (getMarket,getMarketPrice,getAssetContext) remain for backwards compatibility.account.tsprovides account-centric endpoints:getAccountOverviews,getAccountPositions,getUserOpenOrders,getOrderDetail,getUserTradeHistory,getUserFundingRateHistory, andgetPortfolioChart.traders.tstargets the DeciDash dashboard:getTradersDashboard,getTraders,getTraderDetail,getTraderStats, andgetTraderAssetStats.
WebSocket Session (src/api/websocket.ts)
WSAPISessionmanages the lifecycle of a trading WebSocket connection. It exposes typed subscription helpers for every documented topic (market depth, individual/all market prices, market candlesticks, user open orders, order history, positions, users with positions, user/market trade history, user funding history, and account overview). Returns async iterables so you can bridge to RxJS, React hooks, or custom stream handlers.
Root Barrel (src/index.ts)
- Aggregates config, API helpers, WebSocket tools, and types for convenient consumption. Import from here in your frontend to avoid deep relative paths.
Example Scripts (/example)
account.ts,market.ts, andtraders.tsdemonstrate the REST helpers in realistic flows (filtering, pagination, data formatting).websocket.tsshows how to subscribe and gracefully tear down multiple topics in sequence.contract.tscovers on-chain helpers and lives alongside the others for parity, but the SDK description above focuses on non-contract modules per this guide.
Frontend Integration Notes
- Always pass a
DeciDashConfigwhen calling helpers; the SDK will fall back to the preset’sfetchFn/WebSocketCtorif provided. - Wrap promise-returning helpers with SWR/React Query or your preferred data layer. The method signatures are uniform:
{ decidashConfig, ...params }. - Convert WebSocket async iterables into your state management system (e.g.,
for awaitloops,ReadableStreamreaders, or custom adapters). - Leverage the exported types in
src/api/types.tsfor component props, stores, or validation to stay aligned with the backend contract.
