| Crates.io | titan-rust-client |
| lib.rs | titan-rust-client |
| version | 0.1.4 |
| created_at | 2026-01-05 14:11:11.488345+00 |
| updated_at | 2026-01-12 09:50:13.963667+00 |
| description | Rust client for Titan Exchange WebSocket API |
| homepage | https://github.com/ohaddahan/titan-rust-client |
| repository | https://github.com/ohaddahan/titan-rust-client.git |
| max_upload_size | |
| id | 2023935 |
| size | 294,134 |
A Rust client library for the Titan Exchange WebSocket API, enabling real-time swap quote streaming and execution on Solana.
Add to your Cargo.toml:
[dependencies]
titan-rust-client = "0.1"
For the CLI binary:
[dependencies]
titan-rust-client = { version = "0.1", features = ["cli"] }
use titan_rust_client::{TitanClient, TitanConfig};
use titan_rust_client::types::{SwapMode, SwapParams, SwapQuoteRequest, TransactionParams};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize rustls crypto provider (required once at startup)
let _ = rustls::crypto::ring::default_provider().install_default();
// Connect to Titan
let config = TitanConfig::new(
"wss://us1.api.demo.titan.exchange/api/v1/ws",
"your-api-token",
);
let client = TitanClient::new(config).await?;
// Get server info
let info = client.get_info().await?;
println!("Protocol: {}.{}.{}",
info.protocol_version.major,
info.protocol_version.minor,
info.protocol_version.patch
);
// Get available venues
let venues = client.get_venues().await?;
println!("Available venues: {}", venues.labels.len());
// Get a price quote
let price = client.get_swap_price(SwapPriceRequest {
input_mint: sol_mint(),
output_mint: usdc_mint(),
amount: 1_000_000_000, // 1 SOL in lamports
dexes: None,
exclude_dexes: None,
}).await?;
println!("1 SOL = {} USDC", price.amount_out as f64 / 1_000_000.0);
// Stream live quotes
let request = SwapQuoteRequest {
swap: SwapParams {
input_mint: sol_mint(),
output_mint: usdc_mint(),
amount: 1_000_000_000,
swap_mode: Some(SwapMode::ExactIn),
slippage_bps: Some(50),
..Default::default()
},
transaction: TransactionParams {
user_public_key: your_pubkey(),
..Default::default()
},
update: None,
};
let mut stream = client.new_swap_quote_stream(request).await?;
// Receive quotes
while let Some(quotes) = stream.recv().await {
for (provider, route) in "es.quotes {
println!("{}: {} -> {}", provider, route.in_amount, route.out_amount);
}
}
client.close().await?;
Ok(())
}
use titan_rust_client::TitanInstructions;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::{
signature::Keypair,
signer::Signer,
transaction::VersionedTransaction,
message::{v0::Message, VersionedMessage},
compute_budget::ComputeBudgetInstruction,
};
// Get a quote with instructions
let mut stream = client.new_swap_quote_stream(request).await?;
let quotes = stream.recv().await.unwrap();
stream.stop().await?;
// Pick the best route
let (_, best_route) = quotes.quotes
.iter()
.max_by_key(|(_, r)| r.out_amount)
.unwrap();
// Prepare instructions (fetches ALTs from chain)
let rpc = RpcClient::new("https://api.mainnet-beta.solana.com".to_string());
let prepared = TitanInstructions::prepare_instructions(best_route, &rpc).await?;
// Build transaction
let mut instructions = vec![];
if let Some(units) = prepared.compute_units_safe {
instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(units as u32));
}
instructions.extend(prepared.instructions);
let blockhash = rpc.get_latest_blockhash().await?;
let message = Message::try_compile(
&keypair.pubkey(),
&instructions,
&prepared.address_lookup_table_accounts,
blockhash,
)?;
let transaction = VersionedTransaction::try_new(
VersionedMessage::V0(message),
&[&keypair],
)?;
// Send transaction
let signature = rpc.send_and_confirm_transaction(&transaction).await?;
println!("Swap executed: {}", signature);
The crate includes a CLI for testing and quick swaps.
cargo install titan-rust-client --features cli
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
# Get server info
titan-cli info
# List available venues
titan-cli venues
# List liquidity providers
titan-cli providers
# Get swap price
titan-cli price SOL USDC 1000000000
# Stream live quotes
titan-cli stream SOL USDC 1000000000
# Execute a swap (interactive)
titan-cli swap --keypair ~/.config/solana/id.json SOL USDC 100000000
# Execute a swap (automated, no confirmation)
titan-cli swap --keypair ~/.config/solana/id.json --yes SOL USDC 100000000
# Watch connection state
titan-cli watch
The CLI supports these token shortcuts:
SOL / WSOL - Wrapped SOLUSDC - USD CoinUSDT - TetherOr use full mint addresses:
titan-cli price So11111111111111111111111111111111111111112 EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v 1000000000
| 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 |
| 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 |
pub enum ConnectionState {
Disconnected,
Connecting,
Connected,
Reconnecting { attempt: u32 },
Failed { error: String },
}
| Feature | Description |
|---|---|
default |
Core library only |
cli |
Include CLI binary and dependencies |
MIT License - see LICENSE for details.