purpletrader


Namepurpletrader JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryA lightweight Python client for the Amherst College Quant Club Live Trading Engine.
upload_time2025-08-31 00:56:11
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords api client http trading
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # purpletrader

A lightweight Python client for the Live Trading Engine HTTP API.

## Installation

```bash
pip install purpletrader
```

## Usage

```python
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:

```bash
# 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:

```bash
sbatch bots/examples/slurm_job.sbatch
```

## Notes
- Raises `HTTPError` on non-2xx responses with `status_code`, `message`, and `body`.
- Default timeout is 30s; override via `TradingEngineClient(timeout=...)`.
- You can still override `userId` per order by passing it in the `Order`.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "purpletrader",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "api, client, http, trading",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/22/ed/b03fa77b44fa596512e5e808c082c31ea63f951a7d5138dc9c9249f3b799/purpletrader-0.1.1.tar.gz",
    "platform": null,
    "description": "# purpletrader\n\nA lightweight Python client for the Live Trading Engine HTTP API.\n\n## Installation\n\n```bash\npip install purpletrader\n```\n\n## Usage\n\n```python\nfrom purpletrader import TradingEngineClient, Order, Timeframe\n\n# Optionally set a default user_id so you don't have to provide it per order\nclient = TradingEngineClient(base_url=\"http://localhost:8080\", user_id=\"trader_123\")\n\n# Submit order\nresp = client.submit_order(Order(\n    id=\"order_001\",\n    symbol=\"AAPL\",\n    type=\"LIMIT\",\n    side=\"BUY\",\n    quantity=100,\n    price=150.25,\n))\nprint(resp)\n\n# Fetch data\nprint(client.get_orderbook(\"AAPL\"))\nprint(client.get_stats(\"AAPL\"))\nprint(client.get_stats_timeframe(\"AAPL\", Timeframe.ONE_MINUTE))\nprint(client.get_all_stats())\nprint(client.get_stats_summary())\nprint(client.get_leaderboard())\nprint(client.health())\n```\n\n## Example Bots (for quick engine testing)\n\nThis repo also includes simple example bots under `bots/` to exercise the live trading engine:\n\n- Market maker: continuously quotes around mid.\n- Momentum: buys breakouts, sells breakdowns.\n- Random: sends random buy/sell orders.\n\nEach 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.\n\nQuick start:\n\n```bash\n# Set the engine base URL (adjust host/port for your deployment)\nexport ENGINE_URL=\"http://localhost:8080\"\n\n# Market maker on AAPL, user trader_mm\npython -m bots.market_maker --base-url \"$ENGINE_URL\" --user-id trader_mm --symbol AAPL \\\n  --spread-bps 5 --qty 10 --tick-sec 1.0\n\n# Momentum on AAPL, user trader_momo\npython -m bots.momentum --base-url \"$ENGINE_URL\" --user-id trader_momo --symbol AAPL \\\n  --lookback 20 --threshold-bps 10 --qty 5 --tick-sec 1.0\n\n# Random bot on AAPL and MSFT\npython -m bots.random_bot --base-url \"$ENGINE_URL\" --user-id trader_rand --symbol AAPL --symbol MSFT \\\n  --qty-min 1 --qty-max 20 --tick-sec 0.5\n\n# Run multiple bots concurrently from a config file\npython -m bots.runner --base-url \"$ENGINE_URL\" --config bots/examples/bots.yaml\n```\n\n### HPC/Slurm example\n\nSee `bots/examples/slurm_job.sbatch` for a minimal Slurm job that launches two bots. Submit via:\n\n```bash\nsbatch bots/examples/slurm_job.sbatch\n```\n\n## Notes\n- Raises `HTTPError` on non-2xx responses with `status_code`, `message`, and `body`.\n- Default timeout is 30s; override via `TradingEngineClient(timeout=...)`.\n- You can still override `userId` per order by passing it in the `Order`.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightweight Python client for the Amherst College Quant Club Live Trading Engine.",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/ACquantclub/purpletrader"
    },
    "split_keywords": [
        "api",
        " client",
        " http",
        " trading"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5840b52a9d4ffa1d8b9d8d3fb9cc201b7e39c99cfcd9998d66c03b515dd9d733",
                "md5": "7925507439a6ed257b6440b23407a03b",
                "sha256": "f45a651b10e0df7909b66e7ee8a5967145daf2a146e71b48069659bd6aa2c051"
            },
            "downloads": -1,
            "filename": "purpletrader-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7925507439a6ed257b6440b23407a03b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 5527,
            "upload_time": "2025-08-31T00:56:11",
            "upload_time_iso_8601": "2025-08-31T00:56:11.039436Z",
            "url": "https://files.pythonhosted.org/packages/58/40/b52a9d4ffa1d8b9d8d3fb9cc201b7e39c99cfcd9998d66c03b515dd9d733/purpletrader-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "22edb03fa77b44fa596512e5e808c082c31ea63f951a7d5138dc9c9249f3b799",
                "md5": "13fcf539b77fd70f9e009c3c7ea16565",
                "sha256": "1863a4741f2736b6d13df021f857a07dddc1007f5ff4c99ccc5c87024de5a1d7"
            },
            "downloads": -1,
            "filename": "purpletrader-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "13fcf539b77fd70f9e009c3c7ea16565",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 11274,
            "upload_time": "2025-08-31T00:56:11",
            "upload_time_iso_8601": "2025-08-31T00:56:11.788889Z",
            "url": "https://files.pythonhosted.org/packages/22/ed/b03fa77b44fa596512e5e808c082c31ea63f951a7d5138dc9c9249f3b799/purpletrader-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-31 00:56:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ACquantclub",
    "github_project": "purpletrader",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "purpletrader"
}
        
Elapsed time: 0.53107s