High-performance Rust implementation with type safety, async runtime, and zero-cost abstractions
Add to your Cargo.toml:
[dependencies]
binary-options-tools = "2.0"
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"Requires Rust 1.70 or higher
use binary_options_tools::PocketOption;
use tokio;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize connection
let api = PocketOption::new("your-session-id").await?;
// Wait for connection
tokio::time::sleep(Duration::from_secs(5)).await;
// Get balance
let balance = api.balance().await?;
println!("Balance: ${}", balance);
// Place a trade
let (trade_id, trade_data) = api.buy(
"EURUSD_otc",
1.0,
60,
Some("call")
).await?;
println!("Trade ID: {}", trade_id);
// Wait and check result
tokio::time::sleep(Duration::from_secs(65)).await;
let won = api.check_win(trade_id).await?;
println!("Won: {}", won);
Ok(())
}Compile-time type checking prevents runtime errors. All API responses are strongly typed.
High-level API with no performance overhead. As fast as hand-written low-level code.
Rust's ownership system guarantees memory safety without garbage collection.
Built on Tokio for efficient async I/O and concurrent operations.
async fn buy(&self, asset: &str, amount: f64, time: u32, action: Option<&str>)Returns: Result<(i64, TradeData)>
async fn sell(&self, asset: &str, amount: f64, time: u32)Returns: Result<(i64, TradeData)>
async fn check_win(&self, trade_id: i64)Returns: Result<bool>
async fn balance(&self)Returns: Result<f64>
async fn profile(&self)Returns: Result<ProfileData>
use binary_options_tools::{PocketOption, Error};
match api.balance().await {
Ok(balance) => println!("Balance: ${}", balance),
Err(Error::Unauthorized) => eprintln!("Invalid SSID"),
Err(Error::ConnectionError(e)) => eprintln!("Connection failed: {}", e),
Err(e) => eprintln!("Error: {}", e),
}
// Or use the ? operator
let balance = api.balance().await?;