SDK for building trading bots on the0 platform.
pip install the0-sdkOr copy the the0/ directory to your project.
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}")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 varOutput a success result.
success("Trade completed")
success("Trade completed", {"trade_id": "12345"})Output an error result and exit with code 1.
if amount <= 0:
error("Amount must be positive")
# Program exits hereOutput a custom JSON result.
result({
"status": "success",
"trade_id": "abc123",
"filled_amount": 0.5,
"average_price": 45123.50
})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 a message to the bot's logs.
log("Starting trade...")
log("Order placed", {"order_id": "12345"})Sleep utility.
sleep(5) # Wait 5 secondsThis package is published to PyPI.
-
Install build tools:
pip install build twine
-
Create a PyPI API token at https://pypi.org/manage/account/token/
# Build the package
python -m build
# Upload to PyPI
twine upload dist/*Update the version in pyproject.toml:
version = "0.2.0"Then rebuild and publish.
Apache-2.0