quantpipe 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quantpipe-0.1.0/PKG-INFO +311 -0
- quantpipe-0.1.0/README.md +281 -0
- quantpipe-0.1.0/setup.cfg +4 -0
- quantpipe-0.1.0/setup.py +38 -0
- quantpipe-0.1.0/src/quantpipe/__init__.py +3 -0
- quantpipe-0.1.0/src/quantpipe/__main__.py +7 -0
- quantpipe-0.1.0/src/quantpipe/cli.py +49 -0
- quantpipe-0.1.0/src/quantpipe/cli_exit.py +15 -0
- quantpipe-0.1.0/src/quantpipe/commands/__init__.py +1 -0
- quantpipe-0.1.0/src/quantpipe/commands/backtest.py +285 -0
- quantpipe-0.1.0/src/quantpipe/commands/io_util.py +60 -0
- quantpipe-0.1.0/src/quantpipe/commands/paper.py +371 -0
- quantpipe-0.1.0/src/quantpipe/commands/scan.py +345 -0
- quantpipe-0.1.0/src/quantpipe/commands/signal.py +200 -0
- quantpipe-0.1.0/src/quantpipe/core/__init__.py +26 -0
- quantpipe-0.1.0/src/quantpipe/core/adapter.py +689 -0
- quantpipe-0.1.0/src/quantpipe/core/backtest.py +229 -0
- quantpipe-0.1.0/src/quantpipe/core/data.py +132 -0
- quantpipe-0.1.0/src/quantpipe/core/indicators.py +89 -0
- quantpipe-0.1.0/src/quantpipe/core/pipeline_json.py +83 -0
- quantpipe-0.1.0/src/quantpipe/core/strategy.py +100 -0
- quantpipe-0.1.0/src/quantpipe/strategies/__init__.py +13 -0
- quantpipe-0.1.0/src/quantpipe/strategies/ma_cross.py +97 -0
- quantpipe-0.1.0/src/quantpipe/strategies/macd.py +96 -0
- quantpipe-0.1.0/src/quantpipe/strategies/rsi.py +82 -0
- quantpipe-0.1.0/src/quantpipe/types.py +104 -0
- quantpipe-0.1.0/src/quantpipe.egg-info/PKG-INFO +311 -0
- quantpipe-0.1.0/src/quantpipe.egg-info/SOURCES.txt +34 -0
- quantpipe-0.1.0/src/quantpipe.egg-info/dependency_links.txt +1 -0
- quantpipe-0.1.0/src/quantpipe.egg-info/entry_points.txt +2 -0
- quantpipe-0.1.0/src/quantpipe.egg-info/requires.txt +3 -0
- quantpipe-0.1.0/src/quantpipe.egg-info/top_level.txt +1 -0
- quantpipe-0.1.0/tests/test_adapter.py +62 -0
- quantpipe-0.1.0/tests/test_backtest_engine.py +28 -0
- quantpipe-0.1.0/tests/test_data_load_data.py +21 -0
- quantpipe-0.1.0/tests/test_pipeline_json.py +88 -0
quantpipe-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: quantpipe
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Quantitative trading toolkit for LLM AI
|
|
5
|
+
Home-page: https://github.com/yourusername/quantpipe
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: your.email@example.com
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: pandas>=2.0.0
|
|
19
|
+
Requires-Dist: numpy>=1.24.0
|
|
20
|
+
Requires-Dist: click>=8.0.0
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: author-email
|
|
23
|
+
Dynamic: classifier
|
|
24
|
+
Dynamic: description
|
|
25
|
+
Dynamic: description-content-type
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: requires-dist
|
|
28
|
+
Dynamic: requires-python
|
|
29
|
+
Dynamic: summary
|
|
30
|
+
|
|
31
|
+
# QuantPipe
|
|
32
|
+
|
|
33
|
+
Quantitative trading toolkit for LLM AI, designed to work seamlessly with [SeamFlux CLI](https://github.com/seamflux/seamflux-cli) via Unix pipes.
|
|
34
|
+
|
|
35
|
+
**Contract & layout:** See the repo root [`rule.md`](../rule.md) for shared conventions with chartpipe/seamflux (stdout JSON, exit codes, `runs/<runId>/`, etc.).
|
|
36
|
+
|
|
37
|
+
**Supported pipeline JSON:** `schemaVersion` **1** (see [Pipeline JSON](#pipeline-json-machine-readable) below).
|
|
38
|
+
|
|
39
|
+
**SeamFlux CLI (current syntax):** invoke services with `seamflux invoke <service> <method> [-p key=value ...]`. For piping into QuantPipe, prefer **`seamflux invoke ... --pipe`** so stdout is the raw payload JSON (no wrapper/no extra logs). QuantPipe also accepts a one-level wrapper `{"result": { ... }}` (no `jq` required).
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **Signal Generation**: Generate trading signals from market data
|
|
44
|
+
- **Backtesting**: Test strategies on historical data (supports Binance, Polymarket, and more)
|
|
45
|
+
- **Multi-symbol Scanning**: Scan multiple symbols for trading opportunities (default cap + optional `scan.json` output)
|
|
46
|
+
- **Paper Trading**: Simulate trading with real-time signals (supports Binance, Polymarket prediction markets)
|
|
47
|
+
- **Seamless Integration**: Works with seamflux CLI for market data via pipes
|
|
48
|
+
- **Multi-Market Support**: Native support for crypto exchanges (Binance) and prediction markets (Polymarket)
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install -r requirements.txt
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Or install in development mode:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install -e .
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Exit codes
|
|
63
|
+
|
|
64
|
+
| Code | Meaning |
|
|
65
|
+
|------|---------|
|
|
66
|
+
| 0 | Success |
|
|
67
|
+
| 1 | General failure (invalid arguments, I/O error) |
|
|
68
|
+
| 2 | Input format / JSON schema mismatch |
|
|
69
|
+
| 3 | Upstream dependency failed (e.g. `--exec` subprocess non-zero, timeout, missing executable) |
|
|
70
|
+
|
|
71
|
+
Also shown at the bottom of `quantpipe --help`.
|
|
72
|
+
|
|
73
|
+
## Pipeline JSON (machine-readable)
|
|
74
|
+
|
|
75
|
+
With `--json`, commands print a **single-line** JSON object (use `--pretty` only for debugging; not for pipes).
|
|
76
|
+
|
|
77
|
+
**Success (shape):**
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"schemaVersion": 1,
|
|
82
|
+
"tool": "quantpipe",
|
|
83
|
+
"command": "backtest",
|
|
84
|
+
"ok": true,
|
|
85
|
+
"data": { },
|
|
86
|
+
"runId": "optional",
|
|
87
|
+
"artifacts": { "summary": "runs/abc/summary.json", "trades": "runs/abc/trades.csv", "equity": "runs/abc/equity.csv" },
|
|
88
|
+
"meta": { "startedAt": "ISO-8601", "finishedAt": "ISO-8601" }
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Failure:**
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"schemaVersion": 1,
|
|
97
|
+
"tool": "quantpipe",
|
|
98
|
+
"command": "signal",
|
|
99
|
+
"ok": false,
|
|
100
|
+
"error": { "code": "INVALID_INPUT", "message": "human readable" }
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The previous ad-hoc fields now live under **`data`** (e.g. `data.signal`, `data.performance`, `data.scan`).
|
|
105
|
+
|
|
106
|
+
## Runs directory (backtest)
|
|
107
|
+
|
|
108
|
+
Write CSV/JSON artifacts for orchestration/chartpipe:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
quantpipe backtest --input btc_history.json --strategy ma_cross --json --run-id "$(uuidgen)"
|
|
112
|
+
# or
|
|
113
|
+
quantpipe backtest --input btc_history.json --strategy ma_cross --json --run-dir runs/my-run
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Creates (when `--run-dir` or `--run-id` is set):
|
|
117
|
+
|
|
118
|
+
- `summary.json` — metrics + strategy + source (same as `data` in stdout envelope)
|
|
119
|
+
- `trades.csv` — closed trades (`timestamp`, `side`, `price`, `size`, …)
|
|
120
|
+
- `equity.csv` — `timestamp`, `equity`
|
|
121
|
+
- `manifest.json` — inputs, strategy, package version
|
|
122
|
+
|
|
123
|
+
Paths in stdout `artifacts` are relative to the current working directory when possible.
|
|
124
|
+
|
|
125
|
+
## Usage
|
|
126
|
+
|
|
127
|
+
### Common flags
|
|
128
|
+
|
|
129
|
+
- **`--data` / `-d` / `--input` / `-i`** — JSON input file (mutually redundant aliases)
|
|
130
|
+
- **`--stdin`** — read JSON from stdin
|
|
131
|
+
- **`--json`** — pipeline envelope on stdout
|
|
132
|
+
- **`--verbose` / `-v`** — debug logs on **stderr** only
|
|
133
|
+
- **`--dry-run`** — validate input/strategy (and `paper` `--exec` argv parsing); no heavy work / no artifact writes
|
|
134
|
+
|
|
135
|
+
### 1. Signal Generation
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
seamflux invoke binance fetchOhlcv --pipe \
|
|
139
|
+
-p symbol=BTC/USDT \
|
|
140
|
+
-p interval=1h \
|
|
141
|
+
-p limit=100 | \
|
|
142
|
+
quantpipe signal --stdin --strategy ma_cross --json
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Optional: `--output-dir DIR` writes full payload to `DIR/signal.json`; stdout still carries the envelope with `artifacts.signal`.
|
|
146
|
+
|
|
147
|
+
### 2. Backtesting
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
seamflux invoke binance fetchOhlcv --pipe \
|
|
151
|
+
-p symbol=BTC/USDT \
|
|
152
|
+
-p interval=1d \
|
|
153
|
+
-p limit=365 > btc_history.json
|
|
154
|
+
|
|
155
|
+
quantpipe backtest --input btc_history.json --strategy ma_cross --json
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 3. Multi-symbol Scan
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
seamflux invoke binance fetchTickers --pipe \
|
|
162
|
+
-p marketType=spot \
|
|
163
|
+
-p symbols=BTCUSDT,ETHUSDT,SOLUSDT | \
|
|
164
|
+
quantpipe scan --stdin --strategy rsi --filter-signal BUY --json
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
- **Default `--limit` is 500** after sorting. Use **`--limit 0`** for no cap.
|
|
168
|
+
- **`--output-dir DIR`** writes the full result to **`DIR/scan.json`**; stdout envelope lists `artifacts.scan` and may omit the full `signals` list when the file is written.
|
|
169
|
+
|
|
170
|
+
Single-ticker responses and Polymarket **market snapshots** are supported. See `examples/binance_single_ticker.json` and `examples/polymarket_market_snapshot.json`.
|
|
171
|
+
|
|
172
|
+
### 4. Paper Trading
|
|
173
|
+
|
|
174
|
+
`--exec` is parsed with **`shlex.split` (no shell)**. Pass a single string of arguments as you would on the command line (quoted where needed). Use **`--exec-timeout`** (seconds, default 120) for subprocess timeouts.
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
quantpipe paper \
|
|
178
|
+
--exec "seamflux invoke binance fetchOhlcv --pipe -p symbol=BTC/USDT -p interval=5m -p limit=50" \
|
|
179
|
+
--interval 300 \
|
|
180
|
+
--strategy ma_cross \
|
|
181
|
+
--json
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Streaming modes (`--exec` loop or `--stdin`) emit **one JSON envelope per iteration** (NDJSON) when `--json` is set.
|
|
185
|
+
|
|
186
|
+
Shell loop alternative:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
while true; do
|
|
190
|
+
seamflux invoke binance fetchOhlcv --pipe -p symbol=BTC/USDT -p interval=5m -p limit=50
|
|
191
|
+
sleep 300
|
|
192
|
+
done | quantpipe paper --stdin --strategy ma_cross --json
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Polymarket Support
|
|
196
|
+
|
|
197
|
+
QuantPipe natively supports Polymarket prediction market data, enabling backtesting and paper trading on prediction markets.
|
|
198
|
+
|
|
199
|
+
### Data Format
|
|
200
|
+
|
|
201
|
+
- **Price History**: `history: [{t: timestamp, p: price}, ...]` → OHLCV candles
|
|
202
|
+
- **Market Snapshot**: `outcomePrices`, `question` → real-time market state
|
|
203
|
+
|
|
204
|
+
### Backtesting on Polymarket
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
seamflux invoke polymarket getPriceHistory --pipe \
|
|
208
|
+
-p market=<TOKEN_ID> \
|
|
209
|
+
-p interval=1d \
|
|
210
|
+
-p startDate=2025-01-01 \
|
|
211
|
+
-p endDate=2025-03-01 | \
|
|
212
|
+
quantpipe backtest --stdin --strategy ma_cross --param fast=10 --param slow=30 --pretty
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Paper Trading on Polymarket
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
quantpipe paper \
|
|
219
|
+
--exec "seamflux invoke polymarket getPriceHistory --pipe -p market=<TOKEN_ID> -p interval=1h" \
|
|
220
|
+
--interval 3600 \
|
|
221
|
+
--strategy rsi \
|
|
222
|
+
--param period=14 \
|
|
223
|
+
--json
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Available Polymarket Methods
|
|
227
|
+
|
|
228
|
+
Use with `seamflux invoke polymarket <method>`:
|
|
229
|
+
|
|
230
|
+
- `getPriceHistory` - Fetch historical prices (for backtesting & signals)
|
|
231
|
+
- `getPrice` / `getPrices` - Current market prices
|
|
232
|
+
- `getMidpoint` / `getMidpoints` - Current mid-market prices
|
|
233
|
+
- `getOrderBook` - Order book depth
|
|
234
|
+
- `getMarket` / `getMarkets` - Market information
|
|
235
|
+
- `getEvents` - Event listings
|
|
236
|
+
|
|
237
|
+
## Strategies
|
|
238
|
+
|
|
239
|
+
### MA Cross (Moving Average Crossover)
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
quantpipe signal --stdin --strategy ma_cross --param fast=10 --param slow=30
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Parameters: `fast`, `slow`, `ma_type` (`sma` / `ema`).
|
|
246
|
+
|
|
247
|
+
### RSI
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
quantpipe signal --stdin --strategy rsi --param period=14 --param oversold=30 --param overbought=70
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### MACD
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
quantpipe signal --stdin --strategy macd --param fast=12 --param slow=26 --param signal=9
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Output format (`data` field examples)
|
|
260
|
+
|
|
261
|
+
### Signal (`data`)
|
|
262
|
+
|
|
263
|
+
```json
|
|
264
|
+
{
|
|
265
|
+
"timestamp": "2024-01-01T12:00:00Z",
|
|
266
|
+
"validUntil": "2024-01-01T13:00:00Z",
|
|
267
|
+
"source": { "format": "binance_ohlcv", "market_type": "exchange", "type": "ohlcv", "symbol": "BTCUSDT", "bars": 100 },
|
|
268
|
+
"strategy": { "name": "ma_cross", "params": {"fast": 10, "slow": 30} },
|
|
269
|
+
"signal": { "action": "BUY", "confidence": 0.85, "price": 65000, "reason": "..." },
|
|
270
|
+
"indicators": { "fastMa": 65100, "slowMa": 64900 },
|
|
271
|
+
"metadata": { "synthesized": false, "interval": null }
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Backtest (`data`)
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
{
|
|
279
|
+
"source": { "symbol": "BTCUSDT", "market_type": "exchange", "type": "ohlcv", "bars": 500, "period": {"start": "...", "end": "..."} },
|
|
280
|
+
"strategy": { "name": "ma_cross", "params": {"fast": 10, "slow": 30} },
|
|
281
|
+
"performance": {
|
|
282
|
+
"total_trades": 24,
|
|
283
|
+
"win_rate": 0.625,
|
|
284
|
+
"total_return": 0.255,
|
|
285
|
+
"max_drawdown": -0.085,
|
|
286
|
+
"sharpe_ratio": 1.85,
|
|
287
|
+
"profit_factor": 1.2
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## CLI reference (summary)
|
|
293
|
+
|
|
294
|
+
| Command | Notable options |
|
|
295
|
+
|-----------|-----------------|
|
|
296
|
+
| `signal` | `--input`/`--data`, `--output-dir`, `--dry-run`, `--json` |
|
|
297
|
+
| `backtest`| `--run-dir`, `--run-id`, `--dry-run`, `--json` |
|
|
298
|
+
| `scan` | `--limit` (default 500, `0` = unlimited), `--output-dir`, `--json` |
|
|
299
|
+
| `paper` | `--exec`, `--exec-timeout`, `--once`, `--stdin`, `--json` |
|
|
300
|
+
|
|
301
|
+
## Orchestration example (rule.md §9)
|
|
302
|
+
|
|
303
|
+
```text
|
|
304
|
+
seamflux invoke ... > runs/id/input.json
|
|
305
|
+
quantpipe backtest --input runs/id/input.json --json --run-dir runs/id
|
|
306
|
+
chartpipe backtest --run-dir runs/id --json
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## License
|
|
310
|
+
|
|
311
|
+
MIT
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# QuantPipe
|
|
2
|
+
|
|
3
|
+
Quantitative trading toolkit for LLM AI, designed to work seamlessly with [SeamFlux CLI](https://github.com/seamflux/seamflux-cli) via Unix pipes.
|
|
4
|
+
|
|
5
|
+
**Contract & layout:** See the repo root [`rule.md`](../rule.md) for shared conventions with chartpipe/seamflux (stdout JSON, exit codes, `runs/<runId>/`, etc.).
|
|
6
|
+
|
|
7
|
+
**Supported pipeline JSON:** `schemaVersion` **1** (see [Pipeline JSON](#pipeline-json-machine-readable) below).
|
|
8
|
+
|
|
9
|
+
**SeamFlux CLI (current syntax):** invoke services with `seamflux invoke <service> <method> [-p key=value ...]`. For piping into QuantPipe, prefer **`seamflux invoke ... --pipe`** so stdout is the raw payload JSON (no wrapper/no extra logs). QuantPipe also accepts a one-level wrapper `{"result": { ... }}` (no `jq` required).
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Signal Generation**: Generate trading signals from market data
|
|
14
|
+
- **Backtesting**: Test strategies on historical data (supports Binance, Polymarket, and more)
|
|
15
|
+
- **Multi-symbol Scanning**: Scan multiple symbols for trading opportunities (default cap + optional `scan.json` output)
|
|
16
|
+
- **Paper Trading**: Simulate trading with real-time signals (supports Binance, Polymarket prediction markets)
|
|
17
|
+
- **Seamless Integration**: Works with seamflux CLI for market data via pipes
|
|
18
|
+
- **Multi-Market Support**: Native support for crypto exchanges (Binance) and prediction markets (Polymarket)
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install -r requirements.txt
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or install in development mode:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install -e .
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Exit codes
|
|
33
|
+
|
|
34
|
+
| Code | Meaning |
|
|
35
|
+
|------|---------|
|
|
36
|
+
| 0 | Success |
|
|
37
|
+
| 1 | General failure (invalid arguments, I/O error) |
|
|
38
|
+
| 2 | Input format / JSON schema mismatch |
|
|
39
|
+
| 3 | Upstream dependency failed (e.g. `--exec` subprocess non-zero, timeout, missing executable) |
|
|
40
|
+
|
|
41
|
+
Also shown at the bottom of `quantpipe --help`.
|
|
42
|
+
|
|
43
|
+
## Pipeline JSON (machine-readable)
|
|
44
|
+
|
|
45
|
+
With `--json`, commands print a **single-line** JSON object (use `--pretty` only for debugging; not for pipes).
|
|
46
|
+
|
|
47
|
+
**Success (shape):**
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"schemaVersion": 1,
|
|
52
|
+
"tool": "quantpipe",
|
|
53
|
+
"command": "backtest",
|
|
54
|
+
"ok": true,
|
|
55
|
+
"data": { },
|
|
56
|
+
"runId": "optional",
|
|
57
|
+
"artifacts": { "summary": "runs/abc/summary.json", "trades": "runs/abc/trades.csv", "equity": "runs/abc/equity.csv" },
|
|
58
|
+
"meta": { "startedAt": "ISO-8601", "finishedAt": "ISO-8601" }
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Failure:**
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"schemaVersion": 1,
|
|
67
|
+
"tool": "quantpipe",
|
|
68
|
+
"command": "signal",
|
|
69
|
+
"ok": false,
|
|
70
|
+
"error": { "code": "INVALID_INPUT", "message": "human readable" }
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The previous ad-hoc fields now live under **`data`** (e.g. `data.signal`, `data.performance`, `data.scan`).
|
|
75
|
+
|
|
76
|
+
## Runs directory (backtest)
|
|
77
|
+
|
|
78
|
+
Write CSV/JSON artifacts for orchestration/chartpipe:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
quantpipe backtest --input btc_history.json --strategy ma_cross --json --run-id "$(uuidgen)"
|
|
82
|
+
# or
|
|
83
|
+
quantpipe backtest --input btc_history.json --strategy ma_cross --json --run-dir runs/my-run
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Creates (when `--run-dir` or `--run-id` is set):
|
|
87
|
+
|
|
88
|
+
- `summary.json` — metrics + strategy + source (same as `data` in stdout envelope)
|
|
89
|
+
- `trades.csv` — closed trades (`timestamp`, `side`, `price`, `size`, …)
|
|
90
|
+
- `equity.csv` — `timestamp`, `equity`
|
|
91
|
+
- `manifest.json` — inputs, strategy, package version
|
|
92
|
+
|
|
93
|
+
Paths in stdout `artifacts` are relative to the current working directory when possible.
|
|
94
|
+
|
|
95
|
+
## Usage
|
|
96
|
+
|
|
97
|
+
### Common flags
|
|
98
|
+
|
|
99
|
+
- **`--data` / `-d` / `--input` / `-i`** — JSON input file (mutually redundant aliases)
|
|
100
|
+
- **`--stdin`** — read JSON from stdin
|
|
101
|
+
- **`--json`** — pipeline envelope on stdout
|
|
102
|
+
- **`--verbose` / `-v`** — debug logs on **stderr** only
|
|
103
|
+
- **`--dry-run`** — validate input/strategy (and `paper` `--exec` argv parsing); no heavy work / no artifact writes
|
|
104
|
+
|
|
105
|
+
### 1. Signal Generation
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
seamflux invoke binance fetchOhlcv --pipe \
|
|
109
|
+
-p symbol=BTC/USDT \
|
|
110
|
+
-p interval=1h \
|
|
111
|
+
-p limit=100 | \
|
|
112
|
+
quantpipe signal --stdin --strategy ma_cross --json
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Optional: `--output-dir DIR` writes full payload to `DIR/signal.json`; stdout still carries the envelope with `artifacts.signal`.
|
|
116
|
+
|
|
117
|
+
### 2. Backtesting
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
seamflux invoke binance fetchOhlcv --pipe \
|
|
121
|
+
-p symbol=BTC/USDT \
|
|
122
|
+
-p interval=1d \
|
|
123
|
+
-p limit=365 > btc_history.json
|
|
124
|
+
|
|
125
|
+
quantpipe backtest --input btc_history.json --strategy ma_cross --json
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 3. Multi-symbol Scan
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
seamflux invoke binance fetchTickers --pipe \
|
|
132
|
+
-p marketType=spot \
|
|
133
|
+
-p symbols=BTCUSDT,ETHUSDT,SOLUSDT | \
|
|
134
|
+
quantpipe scan --stdin --strategy rsi --filter-signal BUY --json
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
- **Default `--limit` is 500** after sorting. Use **`--limit 0`** for no cap.
|
|
138
|
+
- **`--output-dir DIR`** writes the full result to **`DIR/scan.json`**; stdout envelope lists `artifacts.scan` and may omit the full `signals` list when the file is written.
|
|
139
|
+
|
|
140
|
+
Single-ticker responses and Polymarket **market snapshots** are supported. See `examples/binance_single_ticker.json` and `examples/polymarket_market_snapshot.json`.
|
|
141
|
+
|
|
142
|
+
### 4. Paper Trading
|
|
143
|
+
|
|
144
|
+
`--exec` is parsed with **`shlex.split` (no shell)**. Pass a single string of arguments as you would on the command line (quoted where needed). Use **`--exec-timeout`** (seconds, default 120) for subprocess timeouts.
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
quantpipe paper \
|
|
148
|
+
--exec "seamflux invoke binance fetchOhlcv --pipe -p symbol=BTC/USDT -p interval=5m -p limit=50" \
|
|
149
|
+
--interval 300 \
|
|
150
|
+
--strategy ma_cross \
|
|
151
|
+
--json
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Streaming modes (`--exec` loop or `--stdin`) emit **one JSON envelope per iteration** (NDJSON) when `--json` is set.
|
|
155
|
+
|
|
156
|
+
Shell loop alternative:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
while true; do
|
|
160
|
+
seamflux invoke binance fetchOhlcv --pipe -p symbol=BTC/USDT -p interval=5m -p limit=50
|
|
161
|
+
sleep 300
|
|
162
|
+
done | quantpipe paper --stdin --strategy ma_cross --json
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Polymarket Support
|
|
166
|
+
|
|
167
|
+
QuantPipe natively supports Polymarket prediction market data, enabling backtesting and paper trading on prediction markets.
|
|
168
|
+
|
|
169
|
+
### Data Format
|
|
170
|
+
|
|
171
|
+
- **Price History**: `history: [{t: timestamp, p: price}, ...]` → OHLCV candles
|
|
172
|
+
- **Market Snapshot**: `outcomePrices`, `question` → real-time market state
|
|
173
|
+
|
|
174
|
+
### Backtesting on Polymarket
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
seamflux invoke polymarket getPriceHistory --pipe \
|
|
178
|
+
-p market=<TOKEN_ID> \
|
|
179
|
+
-p interval=1d \
|
|
180
|
+
-p startDate=2025-01-01 \
|
|
181
|
+
-p endDate=2025-03-01 | \
|
|
182
|
+
quantpipe backtest --stdin --strategy ma_cross --param fast=10 --param slow=30 --pretty
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Paper Trading on Polymarket
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
quantpipe paper \
|
|
189
|
+
--exec "seamflux invoke polymarket getPriceHistory --pipe -p market=<TOKEN_ID> -p interval=1h" \
|
|
190
|
+
--interval 3600 \
|
|
191
|
+
--strategy rsi \
|
|
192
|
+
--param period=14 \
|
|
193
|
+
--json
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Available Polymarket Methods
|
|
197
|
+
|
|
198
|
+
Use with `seamflux invoke polymarket <method>`:
|
|
199
|
+
|
|
200
|
+
- `getPriceHistory` - Fetch historical prices (for backtesting & signals)
|
|
201
|
+
- `getPrice` / `getPrices` - Current market prices
|
|
202
|
+
- `getMidpoint` / `getMidpoints` - Current mid-market prices
|
|
203
|
+
- `getOrderBook` - Order book depth
|
|
204
|
+
- `getMarket` / `getMarkets` - Market information
|
|
205
|
+
- `getEvents` - Event listings
|
|
206
|
+
|
|
207
|
+
## Strategies
|
|
208
|
+
|
|
209
|
+
### MA Cross (Moving Average Crossover)
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
quantpipe signal --stdin --strategy ma_cross --param fast=10 --param slow=30
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Parameters: `fast`, `slow`, `ma_type` (`sma` / `ema`).
|
|
216
|
+
|
|
217
|
+
### RSI
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
quantpipe signal --stdin --strategy rsi --param period=14 --param oversold=30 --param overbought=70
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### MACD
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
quantpipe signal --stdin --strategy macd --param fast=12 --param slow=26 --param signal=9
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Output format (`data` field examples)
|
|
230
|
+
|
|
231
|
+
### Signal (`data`)
|
|
232
|
+
|
|
233
|
+
```json
|
|
234
|
+
{
|
|
235
|
+
"timestamp": "2024-01-01T12:00:00Z",
|
|
236
|
+
"validUntil": "2024-01-01T13:00:00Z",
|
|
237
|
+
"source": { "format": "binance_ohlcv", "market_type": "exchange", "type": "ohlcv", "symbol": "BTCUSDT", "bars": 100 },
|
|
238
|
+
"strategy": { "name": "ma_cross", "params": {"fast": 10, "slow": 30} },
|
|
239
|
+
"signal": { "action": "BUY", "confidence": 0.85, "price": 65000, "reason": "..." },
|
|
240
|
+
"indicators": { "fastMa": 65100, "slowMa": 64900 },
|
|
241
|
+
"metadata": { "synthesized": false, "interval": null }
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Backtest (`data`)
|
|
246
|
+
|
|
247
|
+
```json
|
|
248
|
+
{
|
|
249
|
+
"source": { "symbol": "BTCUSDT", "market_type": "exchange", "type": "ohlcv", "bars": 500, "period": {"start": "...", "end": "..."} },
|
|
250
|
+
"strategy": { "name": "ma_cross", "params": {"fast": 10, "slow": 30} },
|
|
251
|
+
"performance": {
|
|
252
|
+
"total_trades": 24,
|
|
253
|
+
"win_rate": 0.625,
|
|
254
|
+
"total_return": 0.255,
|
|
255
|
+
"max_drawdown": -0.085,
|
|
256
|
+
"sharpe_ratio": 1.85,
|
|
257
|
+
"profit_factor": 1.2
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## CLI reference (summary)
|
|
263
|
+
|
|
264
|
+
| Command | Notable options |
|
|
265
|
+
|-----------|-----------------|
|
|
266
|
+
| `signal` | `--input`/`--data`, `--output-dir`, `--dry-run`, `--json` |
|
|
267
|
+
| `backtest`| `--run-dir`, `--run-id`, `--dry-run`, `--json` |
|
|
268
|
+
| `scan` | `--limit` (default 500, `0` = unlimited), `--output-dir`, `--json` |
|
|
269
|
+
| `paper` | `--exec`, `--exec-timeout`, `--once`, `--stdin`, `--json` |
|
|
270
|
+
|
|
271
|
+
## Orchestration example (rule.md §9)
|
|
272
|
+
|
|
273
|
+
```text
|
|
274
|
+
seamflux invoke ... > runs/id/input.json
|
|
275
|
+
quantpipe backtest --input runs/id/input.json --json --run-dir runs/id
|
|
276
|
+
chartpipe backtest --run-dir runs/id --json
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## License
|
|
280
|
+
|
|
281
|
+
MIT
|
quantpipe-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
|
4
|
+
long_description = fh.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name='quantpipe',
|
|
8
|
+
version='0.1.0',
|
|
9
|
+
author='Your Name',
|
|
10
|
+
author_email='your.email@example.com',
|
|
11
|
+
description='Quantitative trading toolkit for LLM AI',
|
|
12
|
+
long_description=long_description,
|
|
13
|
+
long_description_content_type="text/markdown",
|
|
14
|
+
url='https://github.com/yourusername/quantpipe',
|
|
15
|
+
package_dir={'': 'src'},
|
|
16
|
+
packages=find_packages(where='src'),
|
|
17
|
+
install_requires=[
|
|
18
|
+
'pandas>=2.0.0',
|
|
19
|
+
'numpy>=1.24.0',
|
|
20
|
+
'click>=8.0.0',
|
|
21
|
+
],
|
|
22
|
+
entry_points={
|
|
23
|
+
'console_scripts': [
|
|
24
|
+
'quantpipe=quantpipe.cli:cli',
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
python_requires='>=3.9',
|
|
28
|
+
classifiers=[
|
|
29
|
+
"Development Status :: 3 - Alpha",
|
|
30
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
31
|
+
"License :: OSI Approved :: MIT License",
|
|
32
|
+
"Programming Language :: Python :: 3",
|
|
33
|
+
"Programming Language :: Python :: 3.9",
|
|
34
|
+
"Programming Language :: Python :: 3.10",
|
|
35
|
+
"Programming Language :: Python :: 3.11",
|
|
36
|
+
"Programming Language :: Python :: 3.12",
|
|
37
|
+
],
|
|
38
|
+
)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""CLI entry point for QuantPipe."""
|
|
3
|
+
|
|
4
|
+
import click
|
|
5
|
+
|
|
6
|
+
from .cli_exit import EXIT_CODE_HELP
|
|
7
|
+
from .commands.backtest import backtest_command
|
|
8
|
+
from .commands.signal import signal_command
|
|
9
|
+
from .commands.scan import scan_command
|
|
10
|
+
from .commands.paper import paper_command
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@click.group(epilog=EXIT_CODE_HELP)
|
|
14
|
+
@click.version_option(version='0.1.0', prog_name='quantpipe')
|
|
15
|
+
def cli():
|
|
16
|
+
"""QuantPipe - Quantitative trading toolkit for LLM AI.
|
|
17
|
+
|
|
18
|
+
Designed to work seamlessly with seamflux CLI for market data via Unix pipes.
|
|
19
|
+
|
|
20
|
+
Auto-detects data formats: Binance, Polymarket, Uniswap, generic OHLCV.
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
# Generate signal from Binance
|
|
24
|
+
seamflux invoke binance fetchOhlcv -p symbol=BTC/USDT -p timeframe=1h | quantpipe signal --strategy ma_cross --stdin
|
|
25
|
+
|
|
26
|
+
# Generate signal from Polymarket
|
|
27
|
+
seamflux invoke polymarket getPriceHistory -p market=<token_id> -p interval=1h | quantpipe signal --strategy rsi --stdin
|
|
28
|
+
|
|
29
|
+
# Run backtest
|
|
30
|
+
quantpipe backtest --data btc_history.json --strategy rsi --json
|
|
31
|
+
|
|
32
|
+
# Scan multiple symbols
|
|
33
|
+
seamflux invoke binance fetchTickers | quantpipe scan --strategy ma_cross --filter-signal BUY
|
|
34
|
+
|
|
35
|
+
# Paper trading with Polymarket
|
|
36
|
+
quantpipe paper --exec "seamflux invoke polymarket getMarket -p slug=<market_slug>" --strategy ma_cross
|
|
37
|
+
"""
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# Register commands
|
|
42
|
+
cli.add_command(backtest_command)
|
|
43
|
+
cli.add_command(signal_command)
|
|
44
|
+
cli.add_command(scan_command)
|
|
45
|
+
cli.add_command(paper_command)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == '__main__':
|
|
49
|
+
cli()
|