Skip to content

Commit 1dc51f5

Browse files
author
Stefan Jansen
committed
feat: harden live runtime operations and docs
1 parent d09eaec commit 1dc51f5

41 files changed

Lines changed: 3527 additions & 337 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.agents/shared-context.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Shared Project Context: ml4t-live
2+
3+
## Package
4+
5+
- Package name: `ml4t-live`
6+
- Import path: `ml4t.live`
7+
- Purpose: live trading with zero-code migration from `ml4t-backtest`
8+
9+
## Core Surface
10+
11+
- `engine.py` - live engine orchestration
12+
- `wrappers.py` - sync to async strategy bridge
13+
- `safety.py` - risk controls, shadow mode, VirtualPortfolio
14+
- `brokers/` - Interactive Brokers and Alpaca adapters
15+
- `feeds/` - Alpaca, IB, Databento, CCXT, OKX, and aggregation
16+
17+
## Workflow
18+
19+
```bash
20+
uv sync
21+
uv run ruff check src/
22+
uv run ruff format src/
23+
uv run ty check
24+
uv run pytest tests/ -q
25+
```
26+
27+
## Safety
28+
29+
- Start with `shadow_mode=True`
30+
- Keep public symbols stable for book and notebook consumers
31+
- Treat docs, examples, and tests as part of the shipped library surface

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [main]
88

99
env:
10-
PYTHON_VERSION: "3.11"
10+
PYTHON_VERSION: "3.12"
1111
UV_NO_SOURCES: "1"
1212

1313
jobs:
@@ -60,7 +60,7 @@ jobs:
6060
strategy:
6161
fail-fast: false
6262
matrix:
63-
python-version: ["3.11", "3.12", "3.13"]
63+
python-version: ["3.12", "3.13"]
6464

6565
steps:
6666
- uses: actions/checkout@v4

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
tags: ["v*"]
66

77
env:
8-
PYTHON_VERSION: "3.11"
8+
PYTHON_VERSION: "3.12"
99
UV_NO_SOURCES: "1"
1010

1111
jobs:

AGENT.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

AGENTS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ml4t-live
2+
3+
Codex uses `AGENTS.md` as the repo entry point.
4+
5+
@.agents/shared-context.md
6+
7+
## Navigation
8+
9+
- `src/ml4t/live/AGENTS.md` provides the package-level module index
10+
- Public entry point: `from ml4t.live import LiveEngine`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ml4t-live
22

3-
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
3+
[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
44
[![PyPI](https://img.shields.io/pypi/v/ml4t-live)](https://pypi.org/project/ml4t-live/)
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66

docs/getting-started/installation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
## Requirements
44

5-
- Python 3.11+
5+
- Python 3.12+
66
- A supported broker or data source for live use
77
- `ml4t-backtest` is installed automatically as a package dependency
88

99
## Install From PyPI
1010

1111
```bash
12-
pip install ml4t-live
12+
uv add ml4t-live
1313
```
1414

1515
## Optional Add-Ons
@@ -18,7 +18,7 @@ pip install ml4t-live
1818
be installed separately if you want `DataBentoFeed`:
1919

2020
```bash
21-
pip install databento
21+
uv add databento
2222
```
2323

2424
## Install From Source

docs/getting-started/quickstart.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ feed = BarAggregator(raw_feed, bar_size_minutes=1, flush_timeout_seconds=2.0)
8989
## Next Steps
9090

9191
- [Installation](installation.md)
92+
- [Risk Controls](../user-guide/risk.md)
93+
- [CLI](../user-guide/cli.md)
94+
- [Examples](../user-guide/examples.md)
95+
- [Operator Guide](../user-guide/operator-guide.md)
9296
- [Brokers](../user-guide/brokers.md)
9397
- [Data Feeds](../user-guide/feeds.md)
94-
- [Risk Controls](../user-guide/risk.md)

docs/index.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ With `ml4t-live`, you can:
5252
- connect that strategy to Alpaca or Interactive Brokers
5353
- replay or stream data through a live-style feed interface
5454
- start in `shadow_mode=True` so orders are tracked but not routed
55-
- add hard limits for order size, exposure, order rate, and drawdown before going live
55+
- add hard limits for order size, exposure, stale data, daily loss, and drawdown before going live
56+
- inspect persisted state and broker reachability with `ml4t-live status`
57+
- run bounded shadow sessions from the CLI before promoting to paper or live
5658

5759
If you do not yet have a validated strategy, start in `ml4t-backtest`. If you do have one, this is the
5860
next layer.
@@ -249,6 +251,11 @@ See [Brokers](user-guide/brokers.md) for connection details and usage patterns.
249251

250252
Use [Data Feeds](user-guide/feeds.md) for examples and feed-specific setup.
251253

254+
## Operator Surfaces
255+
256+
The library now includes a small CLI and a set of bounded operator-focused examples.
257+
Use [CLI](user-guide/cli.md) for `status` and `shadow`, [Examples](user-guide/examples.md) for runnable scripts, and [Operator Guide](user-guide/operator-guide.md) for the recommended promotion workflow.
258+
252259
## Installation
253260

254261
```bash

docs/user-guide/brokers.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77

88
## Broker Model
99

10-
The raw broker implementations are asynchronous. They implement `AsyncBrokerProtocol` and are meant
11-
to be used by `LiveEngine` and `SafeBroker`.
10+
The raw broker implementations are asynchronous and satisfy `AsyncBrokerProtocol`. In normal usage they sit behind `SafeBroker`, and strategies interact with a synchronous broker wrapper created by `LiveEngine`.
1211

13-
- Strategy code uses synchronous broker calls such as `broker.get_position(...)`
14-
- Raw broker instances use async methods such as `await broker.get_cash_async()`
12+
- Strategy code uses synchronous calls such as `broker.get_position(...)` and `broker.submit_order(...)`
13+
- Infrastructure code uses async methods such as `await broker.get_cash_async()`
1514

1615
## Interactive Brokers
1716

@@ -20,8 +19,9 @@ from ml4t.live import IBBroker
2019

2120
broker = IBBroker(
2221
host="127.0.0.1",
23-
port=7497, # paper
22+
port=7497, # paper TWS
2423
client_id=1,
24+
account=None,
2525
)
2626

2727
await broker.connect()
@@ -31,7 +31,8 @@ await broker.connect()
3131

3232
- `7497` is the usual TWS paper port
3333
- `7496` is the usual TWS live port
34-
- You must have TWS or IB Gateway running with API access enabled
34+
- `4002` and `4001` are the usual paper/live IB Gateway ports
35+
- TWS or IB Gateway must be running with API access enabled before you connect
3536

3637
## Alpaca
3738

@@ -49,9 +50,8 @@ await broker.connect()
4950

5051
### Notes
5152

52-
- `paper=True` is the safe default
53-
- The broker maintains positions and pending orders internally from Alpaca account state and trade
54-
updates
53+
- `paper=True` is the safe default and should stay on until you are ready for live deployment
54+
- The broker tracks positions and pending orders from Alpaca account state plus trade-update callbacks
5555

5656
## Recommended Wrapper
5757

@@ -98,8 +98,7 @@ await broker.disconnect()
9898

9999
## Error Handling
100100

101-
Broker connection and order failures surface as standard Python exceptions, typically
102-
`RuntimeError`, broker SDK exceptions, or `RiskLimitError` when wrapped by `SafeBroker`.
101+
Broker connection and order failures surface as standard Python exceptions, broker-SDK exceptions, or `RiskLimitError` when wrapped by `SafeBroker`.
103102

104103
```python
105104
from ml4t.live import RiskLimitError

0 commit comments

Comments
 (0)