lighter-sdk 0.1.1

Rust SDK for interacting with the Lighter exchange over REST, WebSocket, and signer-backed transaction flows.
Documentation
use std::collections::HashMap;

use lighter_sdk::client::SignerClient;
use lighter_sdk::config::Config;
use lighter_sdk::nonce::NonceManagerType;

fn required_env(name: &str) -> String {
    std::env::var(name).unwrap_or_else(|_| panic!("missing env var `{name}`"))
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let host = required_env("LIGHTER_HOST");
    let signer_path = required_env("LIGHTER_SIGNER_LIB_PATH");
    let account_index = required_env("LIGHTER_ACCOUNT_INDEX").parse::<i64>()?;
    let api_key_index = required_env("LIGHTER_API_KEY_INDEX").parse::<u8>()?;
    let api_private_key = required_env("LIGHTER_API_PRIVATE_KEY");

    let config = Config::new(host).with_signer_lib_path(signer_path);

    let mut api_private_keys = HashMap::new();
    api_private_keys.insert(api_key_index, api_private_key);

    let client = SignerClient::new(
        config,
        account_index,
        api_private_keys,
        NonceManagerType::Api,
    )
    .await?;
    client.check_client()?;
    println!("Signer client is ready for account {account_index}.");
    Ok(())
}