#trading #async #api #api-bindings #market-data #deriv

deriv-api

Unofficial Rust client for Deriv API with auto-generated types

1 unstable release

0.1.0 Jan 1, 2025

#112 in WebSocket

Download history 135/week @ 2024-12-31 9/week @ 2025-01-07

144 downloads per month

MIT license

1MB
19K SLoC

Deriv API Rust Client

Crates.io Documentation License: MIT

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.

Features

  • 🔄 Automatic code generation from official API schema
  • 🔐 Type-safe API requests and responses
  • 📈 Real-time market data streaming
  • 🚀 Async/await support
  • 📦 Zero-copy deserialization
  • 🛡️ Comprehensive error handling

Installation

Add this to your Cargo.toml:

[dependencies]
deriv-api = "0.1.0"

Quick Start

Subscribing to Tick Stream

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(())
}

Buying a Contract

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(())
}

API Coverage

The client supports all endpoints from the official Deriv API, including but not limited to:

  • Market data streaming (ticks, candles)
  • Contract purchasing and management
  • Account management
  • Portfolio operations
  • Payment operations

Development

Building

make build

Running Tests

make test

Generating Schema Types

make generate

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This is an unofficial library and is not affiliated with Deriv.com.

Dependencies

~10–24MB
~346K SLoC