Features
- Quote API - Get swap quotes without transaction data
- Swap API - Get quotes with ready-to-execute transaction data
- Token List - Query supported tokens on each chain
- DEX List - Query available DEXs on each chain
- Reverse Quote - Calculate input amount for desired output
Installation
[dependencies]
openoc = "0.1"
tokio = { version = "1", features = ["full"] }
Quick Start
use openoc::{Client, Chain, QuoteRequest};
#[tokio::main]
async fn main() -> Result<(), openoc::Error> {
let client = Client::new()?;
let request = QuoteRequest::new(
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", "1", ).with_gas_price("30000000000");
let quote = client.get_quote(Chain::Eth, &request).await?;
println!("Output: {} USDC", quote.out_amount);
Ok(())
}
Getting Transaction Data
use openoc::{Client, Chain, SwapRequest};
#[tokio::main]
async fn main() -> Result<(), openoc::Error> {
let client = Client::new()?;
let request = SwapRequest::new(
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"1", "0xYourWalletAddress",
).with_slippage(1.0);
let swap = client.get_swap_quote(Chain::Eth, &request).await?;
println!("To: {}", swap.to);
println!("Data: {}", swap.data);
println!("Value: {}", swap.value);
Ok(())
}
Supported Chains
Ethereum, BSC, Polygon, Arbitrum, Optimism, Base, Avalanche, Fantom, Gnosis, zkSync Era, Linea, Scroll, Mantle, Blast, Solana, Sui
Terms of Service
This is an unofficial client. By using this library, you agree to comply with OpenOcean Terms of Service.
Disclaimer
This crate is not affiliated with or endorsed by OpenOcean.
License
MIT