Rust Examples
This directory contains example Rust programs demonstrating how to use the BinaryOptionsTools library.
Prerequisitesโ
- Rust and Cargo installed (Install Rust)
- Add
binary_options_toolsto yourCargo.toml:
[dependencies]
binary_options_tools = "0.1"
tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1"
Getting Your SSIDโ
- Go to PocketOption
- Open Developer Tools (F12)
- Go to Application/Storage โ Cookies
- Find the cookie named
ssid - Copy its value and replace
"your-session-id"in the examples
Running the Examplesโ
Each example can be run using:
cargo run --example <example_name>
For example:
cargo run --example balance
cargo run --example buy
cargo run --example subscribe_symbol
Or compile and run them directly:
rustc basic.rs && ./basic
Available Examplesโ
basic.rsโ
Basic example showing:
- Client initialization
- Getting account balance
- Getting server time
- Checking if account is demo
Run:
cargo run --example basic
balance.rsโ
Simple example showing how to get your account balance.
Run:
cargo run --example balance
buy.rsโ
Example demonstrating:
- Placing a buy trade
- Checking balance before and after
- Calculating profit/loss
Run:
cargo run --example buy
sell.rsโ
Example demonstrating:
- Placing a sell trade
- Checking balance before and after
- Calculating profit/loss
Run:
cargo run --example sell
check_win.rsโ
Example showing:
- Placing trades
- Checking trade results manually
- Using automatic result checking with timeout
Run:
cargo run --example check_win
subscribe_symbol.rsโ
Example demonstrating:
- Subscribing to real-time candle data
- Processing candle streams
- Displaying OHLC (Open, High, Low, Close) data
Run:
cargo run --example subscribe_symbol
Important Notesโ
Connection Initializationโ
Always wait 5 seconds after creating the client to allow the WebSocket connection to establish:
let client = PocketOption::new("your-session-id").await?;
tokio::time::sleep(Duration::from_secs(5)).await; // Critical!
Error Handlingโ
All examples use proper error handling with Result<(), Box<dyn std::error::Error>>. Make sure to handle errors appropriately in production code.
Async Runtimeโ
All examples use the Tokio async runtime with the #[tokio::main] macro. Make sure your Cargo.toml includes:
[dependencies]
tokio = { version = "1", features = ["full"] }
Common Assetsโ
EURUSD_otc- Euro/US Dollar (OTC)GBPUSD_otc- British Pound/US Dollar (OTC)USDJPY_otc- US Dollar/Japanese Yen (OTC)AUDUSD_otc- Australian Dollar/US Dollar (OTC)
Use _otc suffix for over-the-counter (24/7 available) assets.
Additional Resourcesโ
- Crate Documentation: https://docs.rs/binary_options_tools
- Full Documentation: https://chipatrade.gitlab.io/chipadevorg/BinaryOptionsTools-v2/
- Discord Community: Join us
โ ๏ธ Risk Warningโ
Trading binary options involves substantial risk and may result in the loss of all invested capital. These examples are provided for educational purposes only. Always trade responsibly and never invest more than you can afford to lose.
Build strategies fasterโ
- โจ ChipaEditor โ AI-powered algorithmic trading strategy builder: describe your edge, get a working CHTL strategy, backtest it on historical data, deploy it to a live broker. Free tier, browser and Android. (A trading platform โ not a general-purpose code editor.)
- ๐ ChipaX โ hybrid crypto exchange: perpetuals, spot and margin, with demo mode.
- Chipa Ecosystem overview โ how these fit together with this library.