titan-rust-client
A Rust client library for the Titan Exchange WebSocket API, enabling real-time swap quote streaming and execution on Solana.
Features
- Real-time Quote Streaming - Stream live swap quotes with automatic updates
- One-shot Queries - Get server info, venues, providers, and instant price checks
- Full Swap Execution - Build, sign, and submit swap transactions to Solana
- Auto-reconnect - Automatic reconnection with exponential backoff
- Stream Resumption - Resume quote streams after reconnection
- Connection State Observable - Monitor connection state changes
- TLS Support - Secure WebSocket connections via rustls
Installation
Add to your Cargo.toml:
[]
= "0.1"
For the CLI binary:
[]
= { = "0.1", = ["cli"] }
Quick Start
Library Usage
use ;
use ;
async
Executing a Swap
use TitanInstructions;
use RpcClient;
use ;
// Get a quote with instructions
let mut stream = client.new_swap_quote_stream.await?;
let quotes = stream.recv.await.unwrap;
stream.stop.await?;
// Pick the best route
let = quotes.quotes
.iter
.max_by_key
.unwrap;
// Prepare instructions (fetches ALTs from chain)
let rpc = new;
let prepared = prepare_instructions.await?;
// Build transaction
let mut instructions = vec!;
if let Some = prepared.compute_units_safe
instructions.extend;
let blockhash = rpc.get_latest_blockhash.await?;
let message = try_compile?;
let transaction = try_new?;
// Send transaction
let signature = rpc.send_and_confirm_transaction.await?;
println!;
CLI Usage
The crate includes a CLI for testing and quick swaps.
Installation
Configuration
Create a .env file or set environment variables:
TITAN_TOKEN=your-api-token
TITAN_URL=wss://us1.api.demo.titan.exchange/api/v1/ws
KEYPAIR_PATH=/path/to/keypair.json
SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
Commands
# Get server info
# List available venues
# List liquidity providers
# Get swap price
# Stream live quotes
# Execute a swap (interactive)
# Execute a swap (automated, no confirmation)
# Watch connection state
Token Shortcuts
The CLI supports these token shortcuts:
SOL/WSOL- Wrapped SOLUSDC- USD CoinUSDT- Tether
Or use full mint addresses:
API Reference
TitanClient
| Method | Description |
|---|---|
new(config) |
Create and connect a new client |
get_info() |
Get server info and settings |
get_venues() |
Get available trading venues |
list_providers() |
List liquidity providers |
get_swap_price(request) |
Get instant swap price |
new_swap_quote_stream(request) |
Start streaming quotes |
state_receiver() |
Get connection state observable |
close() |
Gracefully disconnect |
TitanInstructions
| Method | Description |
|---|---|
prepare_instructions(route, rpc) |
Convert route to Solana instructions |
fetch_address_lookup_tables(addresses, rpc) |
Fetch ALT accounts |
convert_instructions(instructions) |
Convert Titan instructions to Solana SDK |
Connection States
Features
| Feature | Description |
|---|---|
default |
Core library only |
cli |
Include CLI binary and dependencies |
Requirements
- Rust 1.75+
- Titan API token (get from titan.exchange)
License
MIT License - see LICENSE for details.
Related
- Titan Exchange - DEX aggregator for Solana
- titan-api-types - API type definitions
- titan-api-codec - Message encoding/decoding