SDK Reference
Official SDKs for Titan Direct — TypeScript (high-level client) and Rust (types + codec).
Titan provides official SDKs for TypeScript and Rust. Both connect to Titan Direct over WebSocket using MessagePack encoding with optional compression.
TypeScript SDK
A high-level client with built-in connection management, compression negotiation, and full type safety.
Package:
@titanexchange/sdk-tsNode.js: >=18.19
Installation
npm install @titanexchange/sdk-tsConnecting
import { V1Client } from '@titanexchange/sdk-ts';
// The SDK automatically negotiates compression (zstd, brotli, gzip, or none)
const url = `wss://${process.env.TITAN_ENDPOINT}/ws?auth=${process.env.TITAN_API_KEY}`;
const client = await V1Client.connect(url);Connection state:
client.closed—boolean,trueif the connection is closed.client.listen_closed()— Returns aPromisethat resolves with the close event.client.close()— Gracefully closes the connection.
API methods
client.getInfo()→ServerInfo— Protocol version and server settings.client.newSwapQuoteStream(params)→{ response, stream, streamId }— Opens a streaming quote.client.stopStream(streamId)→StopStreamResponse— Stops a stream by ID.client.getVenues(params?)→VenueInfo— Lists available on-chain venues.client.listProviders(params?)→ProviderInfo[]— Lists active quote providers.client.getSwapPrice(params)→SwapPrice— One-shot price check without streaming.
Streaming quotes
Stopping a stream
Types
Selecting a transaction format
transactionFormat selects the Solana transaction wire format Titan uses when sizing candidate routes. It is separate from titanSwapVersion, which selects the Titan swap instruction version.
TransactionFormat.V0 (0) is the default. TransactionFormat.V1 (1) enables Transaction V1 route sizing, uses a 4096-byte maximum, does not support ALTs, and requires Titan Swap V3. You may omit titanSwapVersion and let the server resolve V1 requests to V3; explicitly combining Transaction V1 with Swap V2 is rejected.
Transaction V1 requires the Agave 4.2 feature set to be active on the cluster where you submit. Titan does not verify activation; continue using V0 until activation is confirmed.
Error handling
All error classes are exported from the SDK:
ConnectionClosed— WebSocket connection closed. Properties:code,reason,wasClean.ConnectionError— WebSocket error event. Property:cause.ErrorResponse— Server rejected a request. Property:response(withcode,message,requestId).StreamError— Stream ended with an error. Properties:streamId,errorCode,errorMessage.ProtocolError— Implementation bug — report to Titan. Properties:reason,data.
Reconnection
The SDK does not include built-in reconnect logic. Handle reconnection manually:
See Error Handling & Reconnect for backoff strategies.
Browser usage
Do not expose your API key in client-side code. Use a middleware proxy that accepts user connections, validates authentication, and forwards to Titan with the API key server-side. See examples/middleware.ts in the SDK repository.
Key details
BigInt amounts — Pass
amountasBigInt(e.g.1_000_000_000n). Numbers >= 2^32 may be encoded as float64, which the server rejects.quotesis a map —SwapQuotes.quotesisRecord<string, SwapRoute>, keyed by provider ID. Not every provider appears in every update.num_quotesuses snake_case — InQuoteUpdateParams, the field isnum_quotes(notnumQuotes).
Logging BigInt values:
Rust SDK
Low-level type definitions and MessagePack codec — you manage the WebSocket connection yourself.
titan-api-types— Type definitions for all WebSocket request and response messages.titan-api-codec— MessagePack encoding/decoding with compression support (zstd, brotli, gzip).
Installation
Connecting
Sending requests
Streaming quotes
Processing responses
Field naming
The Rust SDK uses standard snake_case field names. Serde handles the conversion to camelCase on the wire:
input_mint→inputMintoutput_mint→outputMintslippage_bps→slippageBpsuser_public_key→userPublicKeyonly_direct_routes→onlyDirectRoutes
Reconnection
No built-in reconnect logic. Handle connection drops and re-establish streams manually, same as the TypeScript SDK.
Dependencies
tokio-tungstenite— Async WebSocket client.rmp-serde— MessagePack serialization.zstd— Zstandard compression.brotli— Brotli compression.flate2— Gzip compression.five8/five8_const— Base58 pubkey encoding.
Related pages
Quickstart — End-to-end integration example
Stream & Execute a Swap — Full guide with transaction building
Wire Protocol — Encoding rules and message envelopes
Error Codes — Error codes and SDK error classes
Last updated

