Skip to main content

SDK for building trading bots on the0 platform

Project description

the0-sdk (Python)

SDK for building trading bots on the0 platform.

Installation

pip install the0-sdk

Or copy the the0/ directory to your project.

Quick Start

from the0 import parse, success, error, metric, log

# Parse bot configuration from environment
bot_id, config = parse()

log(f"Bot {bot_id} starting...")

# Access configuration
symbol = config.get("symbol", "BTC/USDT")
amount = config.get("amount", 100.0)

try:
    # Your trading logic here
    log(f"Trading {symbol} with amount {amount}")

    # Emit metrics for the dashboard
    metric("price", {
        "symbol": symbol,
        "value": 45000.50,
        "change_pct": 2.5
    })

    # Signal success
    success("Trade executed", {
        "symbol": symbol,
        "amount": amount
    })

except Exception as e:
    error(f"Trade failed: {e}")

API Reference

parse() -> Tuple[str, Dict]

Parse bot configuration from environment variables.

bot_id, config = parse()
# bot_id: Value of BOT_ID env var
# config: Parsed JSON from BOT_CONFIG env var

success(message: str, data: dict = None)

Output a success result.

success("Trade completed")
success("Trade completed", {"trade_id": "12345"})

error(message: str, data: dict = None)

Output an error result and exit with code 1.

if amount <= 0:
    error("Amount must be positive")
    # Program exits here

result(data: dict)

Output a custom JSON result.

result({
    "status": "success",
    "trade_id": "abc123",
    "filled_amount": 0.5,
    "average_price": 45123.50
})

metric(type: str, data: dict)

Emit a metric for the platform dashboard.

# Price metric
metric("price", {"symbol": "BTC/USD", "value": 45000})

# Trading signal
metric("signal", {"symbol": "ETH/USD", "direction": "long", "confidence": 0.85})

# Alert
metric("alert", {"type": "price_spike", "severity": "high"})

log(message: str, data: dict = None)

Log a message to the bot's logs.

log("Starting trade...")
log("Order placed", {"order_id": "12345"})

sleep(seconds: float)

Sleep utility.

sleep(5)  # Wait 5 seconds

Publishing (Maintainers)

This package is published to PyPI.

Prerequisites

  1. Install build tools:

    pip install build twine
    
  2. Create a PyPI API token at https://pypi.org/manage/account/token/

Publish

# Build the package
python -m build

# Upload to PyPI
twine upload dist/*

Version Bump

Update the version in pyproject.toml:

version = "0.2.0"

Then rebuild and publish.

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

the0_sdk-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

the0_sdk-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file the0_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: the0_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for the0_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2fa1b1fb2de0e8f4e067b83ce0d368c8d16ebebb93b0133f5ae6a25bd2eefa0d
MD5 3cf52f067ef9e501bc096f08cf9b31b1
BLAKE2b-256 f81f49a4c43b7711d877bb4a1029df8ba11b769675ccac3c12f3cb707c6dc087

See more details on using hashes here.

File details

Details for the file the0_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: the0_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for the0_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78f46eeb6bc4fe13015073ec645b26a4dfceb498401e87f25af27404a346fc2d
MD5 fef0e9a1ac1aecf98861b9cb6f073f58
BLAKE2b-256 e4fa6ae1a362d482eb96715fc37637b0f7de8be1a9a1960d233b11fb00e6f9b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page