For the complete documentation index, see llms.txt. This page is also available as Markdown.

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.

Installation

npm install @titanexchange/sdk-ts

Connecting

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.closedboolean, true if the connection is closed.

  • client.listen_closed() — Returns a Promise that 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.

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 (with code, 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

Key details

  • BigInt amounts — Pass amount as BigInt (e.g. 1_000_000_000n). Numbers >= 2^32 may be encoded as float64, which the server rejects.

  • quotes is a mapSwapQuotes.quotes is Record<string, SwapRoute>, keyed by provider ID. Not every provider appears in every update.

  • num_quotes uses snake_case — In QuoteUpdateParams, the field is num_quotes (not numQuotes).

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

There is no high-level client in the Rust SDK. You manage the WebSocket connection using tokio-tungstenite (or any async WebSocket library) and use the codec for serialization.

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_mintinputMint

  • output_mintoutputMint

  • slippage_bpsslippageBps

  • user_public_keyuserPublicKey

  • only_direct_routesonlyDirectRoutes

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.


Last updated