| Crates.io | deriv-api |
| lib.rs | deriv-api |
| version | 0.1.1 |
| created_at | 2025-01-01 16:18:00.629114+00 |
| updated_at | 2025-04-21 09:53:42.948828+00 |
| description | Unofficial Rust client for Deriv API with auto-generated types |
| homepage | |
| repository | https://github.com/ghayyem/deriv-api.git |
| max_upload_size | |
| id | 1500891 |
| size | 134,698 |
An unofficial Rust library for the Deriv API
This crate provides a strongly-typed client for the Deriv API, with automatically generated types from the official API schema. It supports both synchronous and asynchronous WebSocket connections, allowing you to interact with your Deriv account programmatically.
Add this to your Cargo.toml:
[dependencies]
deriv-api = "0.1.0"
use deriv_api::{DerivClient, Result};
use deriv_api_schema::*;
#[tokio::main]
async fn main() -> Result<()> {
// Create a new client
let client = DerivClient::new(
"wss://ws.binaryws.com/websockets/v3",
1234, // Your app_id
"en",
"https://your-app.com",
None,
)?;
// Connect to the WebSocket
client.connect().await?;
// Create tick request
let request = TicksRequest {
ticks: Value::String("R_50".to_string()),
subscribe: Some(SubscribeEnum::Value1),
..Default::default()
};
// Subscribe to ticks
let response = client.ticks(request).await?;
println!("Symbol: {}, Quote: {}", response.tick.symbol, response.tick.quote);
Ok(())
}
use deriv_api::{DerivClient, Result};
use deriv_api_schema::*;
#[tokio::main]
async fn main() -> Result<()> {
let client = DerivClient::new(
"wss://ws.binaryws.com/websockets/v3",
1234,
"en",
"https://your-app.com",
None,
)?;
client.connect().await?;
// Authorize
let auth_request = AuthorizeRequest {
authorize: "YOUR_API_TOKEN".to_string(),
..Default::default()
};
client.authorize(auth_request).await?;
// Create a proposal request
let proposal_request = ProposalRequest {
proposal: 1,
amount: 100.0,
barrier: Some("+0.001".to_string()),
contract_type: "CALL".to_string(),
currency: "USD".to_string(),
duration: 5,
duration_unit: "t".to_string(),
symbol: "R_50".to_string(),
..Default::default()
};
// Get proposal and buy contract
let proposal = client.proposal(proposal_request).await?;
Ok(())
}
The client supports all endpoints from the official Deriv API, including but not limited to:
make build
make test
make generate
Contributions are welcome! Please feel free to submit a Pull Request.
This project draws inspiration from and acknowledges the following projects:
This project is licensed under the MIT License - see the LICENSE file for details.
This is an unofficial library and is not affiliated with Deriv.com.