purpletrader
A lightweight Python client for the Live Trading Engine HTTP API.
Installation
pip install purpletrader
Usage
from purpletrader import TradingEngineClient, Order, Timeframe
# Optionally set a default user_id so you don't have to provide it per order
client = TradingEngineClient(base_url="http://localhost:8080", user_id="trader_123")
# Submit order
resp = client.submit_order(Order(
id="order_001",
symbol="AAPL",
type="LIMIT",
side="BUY",
quantity=100,
price=150.25,
))
print(resp)
# Fetch data
print(client.get_orderbook("AAPL"))
print(client.get_stats("AAPL"))
print(client.get_stats_timeframe("AAPL", Timeframe.ONE_MINUTE))
print(client.get_all_stats())
print(client.get_stats_summary())
print(client.get_leaderboard())
print(client.health())
Example Bots (for quick engine testing)
This repo also includes simple example bots under bots/ to exercise the live trading engine:
- Market maker: continuously quotes around mid.
- Momentum: buys breakouts, sells breakdowns.
- Random: sends random buy/sell orders.
Each bot is a CLI that targets one or more symbols and a user id. They use the purpletrader client to interact with the engine's HTTP API.
Quick start:
# Set the engine base URL (adjust host/port for your deployment)
export ENGINE_URL="http://localhost:8080"
# Market maker on AAPL, user trader_mm
python -m bots.market_maker --base-url "$ENGINE_URL" --user-id trader_mm --symbol AAPL \
--spread-bps 5 --qty 10 --tick-sec 1.0
# Momentum on AAPL, user trader_momo
python -m bots.momentum --base-url "$ENGINE_URL" --user-id trader_momo --symbol AAPL \
--lookback 20 --threshold-bps 10 --qty 5 --tick-sec 1.0
# Random bot on AAPL and MSFT
python -m bots.random_bot --base-url "$ENGINE_URL" --user-id trader_rand --symbol AAPL --symbol MSFT \
--qty-min 1 --qty-max 20 --tick-sec 0.5
# Run multiple bots concurrently from a config file
python -m bots.runner --base-url "$ENGINE_URL" --config bots/examples/bots.yaml
HPC/Slurm example
See bots/examples/slurm_job.sbatch for a minimal Slurm job that launches two bots. Submit via:
sbatch bots/examples/slurm_job.sbatch
Notes
- Raises
HTTPErroron non-2xx responses withstatus_code,message, andbody. - Default timeout is 30s; override via
TradingEngineClient(timeout=...). - You can still override
userIdper order by passing it in theOrder.
Metadata
Release files for purpletrader 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| purpletrader-0.1.1.tar.gz | 11.3 kB | Without provenance | Details for purpletrader-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| purpletrader-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for purpletrader-0.1.1-py3-none-any.whl |
Total release size: 16.8 kB
Release files / purpletrader-0.1.1.tar.gz
| Download URL | purpletrader-0.1.1.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1863a4741f2736b6d13df021f857a07dddc1007f5ff4c99ccc5c87024de5a1d7
|
|
BLAKE2b-256 checksum How to use checksums |
22edb03fa77b44fa596512e5e808c082c31ea63f951a7d5138dc9c9249f3b799
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / purpletrader-0.1.1-py3-none-any.whl
| Download URL | purpletrader-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f45a651b10e0df7909b66e7ee8a5967145daf2a146e71b48069659bd6aa2c051
|
|
BLAKE2b-256 checksum How to use checksums |
5840b52a9d4ffa1d8b9d8d3fb9cc201b7e39c99cfcd9998d66c03b515dd9d733
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for purpletrader 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.