the0-sdk

Crates.iothe0-sdk
lib.rsthe0-sdk
version0.3.1
created_at2025-12-26 12:30:35.167678+00
updated_at2026-01-09 15:07:24.514635+00
descriptionthe0 trading bot SDK for Rust
homepagehttps://the0.dev
repositoryhttps://github.com/alexanderwanyoike/the0
max_upload_size
id2005657
size85,856
Alexander Wanyoike (alexanderwanyoike)

documentation

https://docs.the0.dev

README

the0-sdk (Rust)

Optional SDK for building trading bots on the0 platform.

Note: This SDK is optional. The the0 runtime automatically wraps your bot's output:

  • Exit code 0 → {"status":"success","message":"Bot executed successfully"}
  • Exit code non-zero → {"status":"error","message":"Bot execution failed"}
  • If you output JSON with a "status" field, it's passed through as-is

Minimal Example (No SDK)

use std::env;

fn main() {
    // No SDK needed - just run your code and exit normally
    let bot_id = env::var("BOT_ID").unwrap_or_default();
    let config_str = env::var("BOT_CONFIG").unwrap_or_default();

    eprintln!("Bot {} running...", bot_id);

    // Your trading logic here

    // Exit normally - runtime outputs {"status":"success",...}
}

With SDK (Optional)

The SDK provides convenience methods for parsing config and outputting custom results.

Installation

Add to your Cargo.toml:

[dependencies]
the0-sdk = "0.1"
serde_json = "1.0"  # Required for config access

Or from git:

[dependencies]
the0-sdk = { git = "https://github.com/alexanderwanyoike/the0", subdirectory = "sdk/rust" }

Usage

use the0_sdk::input;

fn main() {
    // Parse bot configuration
    let (bot_id, config) = input::parse();

    eprintln!("Bot {} starting", bot_id);

    // Access config values
    if let Some(symbol) = config.get("symbol") {
        eprintln!("Trading symbol: {}", symbol);
    }

    // Your trading logic here

    // Optionally output custom result (otherwise runtime generates it)
    input::success("Bot executed successfully");
}

API Reference

input::parse() -> (String, Value)

Parse bot configuration from environment. Returns (bot_id, config).

input::parse_as_map() -> (String, HashMap<String, Value>)

Parse configuration as a HashMap for easier access.

input::success(message: &str)

Output success result and continue execution.

input::error(message: &str) -> !

Output error result and exit with code 1.

input::result(data: &Value)

Output custom JSON result.

Example Bot

See the Rust Quick Start Guide for a complete example.

Publishing (Maintainers)

This package is published to crates.io.

Prerequisites

  1. Login to crates.io:

    cargo login
    
  2. Ensure you have ownership of the crate on crates.io

Publish

# Verify the package
cargo publish --dry-run

# Publish to crates.io
cargo publish

Version Bump

Update the version in Cargo.toml:

version = "0.2.0"

Then publish.

License

Apache-2.0

Commit count: 447

cargo fmt