ctrader-rs
Rust port of diegobernardes/ctrader — a strongly-typed, async client for the cTrader Open API.
Architecture
| Go module | Rust equivalent |
|---|---|
transportTCP |
src/transport.rs — async TLS TCP via tokio-native-tls |
Client struct |
src/client.rs — Client struct |
Command[A,B] |
Client::command::<Q,R>() generic method |
keepalive() goroutine |
Tokio task in client.rs |
Request registry (map[string]chan) |
HashMap<String, oneshot::Sender<ProtoMessage>> |
openapi/*.pb.go |
proto/*.proto → compiled by prost-build in build.rs |
Requirements
- Rust 1.75+
protocprotobuf compiler on$PATH
# macOS
# Ubuntu/Debian
Quick start
# 1. Clone / unzip the project
# 2. Fill in .env (credentials are already seeded from the Go project)
# 3. Run an example
Environment variables
| Variable | Description |
|---|---|
CTRADER_CLIENT_ID |
App client ID from openapi.ctrader.com |
CTRADER_SECRET |
App client secret |
CTRADER_TOKEN |
OAuth access token |
CTRADER_DEMO_ACCOUNT_ID |
Demo ctidTradingAccountId |
CTRADER_LIVE_ACCOUNT_ID |
Live ctidTradingAccountId |
Usage in your own code
use Duration;
use ;
async
Listening to events
Pass an event handler to receive unsolicited messages (spot prices, execution events, …):
let client = start_with_handler.await?;
Adding more API calls
Every cTrader request follows the same pattern — add a method to Client in src/client.rs:
pub async
Then add the corresponding message to proto/openapi.proto and build.rs will compile it automatically.