Rust SDK

Encrypted Rust client for the GoDark API. Crate name: godark.

Requirements: Rust 2021, tokio
Status: Beta — clone the public examples repo to get started.

Get the SDK

Clone gdx-rust-sdk-examples. The repo vendors the godark crate under sdk/ so no private crates registry is required:

git clone https://github.com/gq-godark/gdx-rust-sdk-examples.git
cd gdx-rust-sdk-examples
cp .env.example .env
# set GODARK_API_KEY_ID, GODARK_API_SECRET, GODARK_PASSPHRASE

cargo build --release --examples
cargo run --release --example quickstart
cargo run --release --example full_trader_example

You can also point an LLM / coding agent at the cloned repo and ask it to build a strategy using your credentials in .env. See the repo README for full setup, examples, and packaging details.

Public crates.io release is not yet available; until then this repo is the supported distribution.

Quickstart

Set credentials, then place a limit order over encrypted WebSocket (GodarkClient). Subscribe to orders before placing so book confirmation can wait on private updates. Limit prices must stay near the oracle or the venue rejects — see Error Codes.

use godark::{Environment, GodarkClient, OrderType, Side, TimeInForce};

const SYMBOL: &str = "BTC-USDC-PERP";

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut builder = GodarkClient::builder()
        .environment(Environment::Testnet)
        .api_key_id(std::env::var("GODARK_API_KEY_ID")?)
        .api_secret(std::env::var("GODARK_API_SECRET")?)
        .passphrase(std::env::var("GODARK_PASSPHRASE")?);
    if let Ok(base_url) = std::env::var("GODARK_EDGE_URL") {
        if !base_url.trim().is_empty() {
            builder = builder.base_url(base_url.trim());
        }
    }

    let mut client = GodarkClient::new(builder.build()?);
    client.connect().await?;
    client.subscribe(&["orders"]).await?;

    let ack = client
        .place_order(
            SYMBOL,
            Side::Sell,
            OrderType::Limit,
            0.01,
            Some(68_000.0), // within ~10% of oracle
            TimeInForce::Gtc,
            false,
            None,
            None,
        )
        .await?;
    println!("placed {}", ack.order_id);

    tokio::time::sleep(std::time::Duration::from_millis(500)).await;
    let cancel = client.cancel_order(&ack.order_id, SYMBOL).await?;
    println!("cancelled {}", cancel.order_id);

    client.disconnect().await;
    Ok(())
}

See WebSocket Trading and Place Order for request fields.

Clients

TypeDescription
GodarkClientWebSocket trading + order/position streams on /ws/v1
MarketDataClientExternal venue feeds on /ws/gomarket

Build GodarkClient with the builder pattern: .api_key_id(), .api_secret(), .passphrase(), .environment(). GodarkRestClient may still be exported for residual HTTP helpers; encrypted order place / cancel / modify is WebSocket-only.

GodarkClient methods

MethodDocs reference
connect() / disconnect()Authentication, Encryption
subscribe(...)WebSocket Trading
place_order(...)Place Order, WebSocket Trading
cancel_order(...)Cancel Order
modify_order(...)Modify Order
mass_quote(...)Mass Quote
batch_cancel(...)Cancel Order
Order update callbacksOrders Channel
Position update callbacksPositions Channel

Types and errors

Environment, Side, OrderType, TimeInForce, OrderStatus, OrderUpdateType, PositionUpdateType, CancelReason, plus OrderAck / OrderUpdate / PositionUpdate. Errors follow the same names as the overview (AuthenticationError, SessionError, OrderError, and similar).

Environment variables: OS GODARK_*, then OS GDX_*, then .env GODARK_*, then .env GDX_*. The process environment always wins over .env. Quickstart snippets use the canonical GODARK_* names.

Bundled examples

Runnable samples in the examples repo: quickstart (connect → subscribe → place → cancel) and full_trader_example (modify, mass quote, batch cancel) — cargo run --release --example <name>.

See also