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
-
Install build tools:
pip install build twine
-
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file the0_sdk-0.3.1.tar.gz.
File metadata
- Download URL: the0_sdk-0.3.1.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
202162e9c8b370d3af666a4614eb3fcd06a9d6475f1d65d8888bc85af203ba69
|
|
| MD5 |
391bb368522dd0c4b4084009b109af04
|
|
| BLAKE2b-256 |
eba8e5d0c2c73e2f118fafb07e51ceb2f33d7b957adf78338080829305e538ca
|
File details
Details for the file the0_sdk-0.3.1-py3-none-any.whl.
File metadata
- Download URL: the0_sdk-0.3.1-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9ec7a0dcd1b38fe8342e0e89d82752dc537d5208855116b3f895339d9386da8
|
|
| MD5 |
0848bdf20da291a1ab52cb4d118b92ca
|
|
| BLAKE2b-256 |
bb271825e049237be5246b63ba49c6f59ea7f98b7b9f35fd57836212eaebdc6c
|