filtrix-cli 0.2.0__tar.gz → 0.4.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.
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/PKG-INFO +13 -2
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/README.md +12 -1
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/pyproject.toml +1 -1
- filtrix_cli-0.4.0/src/filtrix_cli/AGENTS.md +102 -0
- filtrix_cli-0.4.0/src/filtrix_cli/__init__.py +1 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/__main__.py +7 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/client.py +43 -2
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/_helpers.py +55 -44
- filtrix_cli-0.4.0/src/filtrix_cli/commands/live.py +370 -0
- filtrix_cli-0.4.0/src/filtrix_cli/commands/research.py +240 -0
- filtrix_cli-0.4.0/tests/test_cmd_live.py +185 -0
- filtrix_cli-0.4.0/tests/test_cmd_research.py +195 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_smoke.py +1 -1
- filtrix_cli-0.2.0/src/filtrix_cli/AGENTS.md +0 -59
- filtrix_cli-0.2.0/src/filtrix_cli/__init__.py +0 -1
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/.gitignore +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/LICENSE +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/auth.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/__init__.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/account.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/authcmd.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/backtest.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/configcmd.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/filters.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/keys.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/llms.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/market.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/screen.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/commands/ticker.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/config.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/filters.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/output.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/render.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/src/filtrix_cli/state.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/__init__.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_auth.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_client.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_client_register.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_cmd_auth.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_cmd_backtest_screen.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_cmd_config.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_cmd_keys.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_cmd_llms.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_cmd_market.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_cmd_profile.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_cmd_read.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_cmd_register.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_config.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_filters.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_helpers.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_output.py +0 -0
- {filtrix_cli-0.2.0 → filtrix_cli-0.4.0}/tests/test_render.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: filtrix-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Agent-first command-line interface for the FILTRIX backtest engine.
|
|
5
5
|
Project-URL: Homepage, https://filtrix.net
|
|
6
6
|
Project-URL: Documentation, https://pypi.org/project/filtrix-cli/
|
|
@@ -70,6 +70,13 @@ filtrix daily AAPL --limit 60 # daily OHLCV bars
|
|
|
70
70
|
filtrix coverage TSLA # how much history
|
|
71
71
|
filtrix premarket # today's premarket gappers (free)
|
|
72
72
|
filtrix account
|
|
73
|
+
filtrix runs save -f "gap_gup>=20" -f "price_price<10" --name "Small gappers" --wait
|
|
74
|
+
filtrix runs list
|
|
75
|
+
filtrix simulate --run-id 42 --entry open_at_0930 --exit stop_loss_take_profit --sl 0.03 --tp 0.06 --wait
|
|
76
|
+
filtrix runs context 42 ABCD 2025-03-14 # daily + minute bars of one event
|
|
77
|
+
filtrix jobs get JOB_ID
|
|
78
|
+
filtrix scanner query -f "gap_gup>=10" --order-by gap_gup --desc # live market now (Pro, once enabled)
|
|
79
|
+
filtrix paper account # paper trading account (Pro, once enabled)
|
|
73
80
|
filtrix keys create --name laptop
|
|
74
81
|
filtrix llms # machine-readable usage guide for AI agents
|
|
75
82
|
```
|
|
@@ -78,7 +85,11 @@ filtrix llms # machine-readable usage guide for AI agents
|
|
|
78
85
|
|
|
79
86
|
Output is human-readable in a terminal and JSON when piped or with the global `--json` flag.
|
|
80
87
|
Global flags (`--json`, `--quiet`, `--profile`, `--api-key`, `--base-url`) go BEFORE the subcommand.
|
|
81
|
-
Exit codes: 0 ok, 2 usage, 3 not-found, 4 auth, 5 rate-limited, 6 network, 1 server
|
|
88
|
+
Exit codes: 0 ok, 2 usage, 3 not-found, 4 auth, 5 rate-limited, 6 network or `--wait` timeout, 1 server
|
|
89
|
+
or failed job.
|
|
90
|
+
|
|
91
|
+
`runs save` and `simulate` start background jobs; `--wait` polls until they finish. `runs delete` needs
|
|
92
|
+
`--yes` when not interactive.
|
|
82
93
|
|
|
83
94
|
## Configuration
|
|
84
95
|
|
|
@@ -38,6 +38,13 @@ filtrix daily AAPL --limit 60 # daily OHLCV bars
|
|
|
38
38
|
filtrix coverage TSLA # how much history
|
|
39
39
|
filtrix premarket # today's premarket gappers (free)
|
|
40
40
|
filtrix account
|
|
41
|
+
filtrix runs save -f "gap_gup>=20" -f "price_price<10" --name "Small gappers" --wait
|
|
42
|
+
filtrix runs list
|
|
43
|
+
filtrix simulate --run-id 42 --entry open_at_0930 --exit stop_loss_take_profit --sl 0.03 --tp 0.06 --wait
|
|
44
|
+
filtrix runs context 42 ABCD 2025-03-14 # daily + minute bars of one event
|
|
45
|
+
filtrix jobs get JOB_ID
|
|
46
|
+
filtrix scanner query -f "gap_gup>=10" --order-by gap_gup --desc # live market now (Pro, once enabled)
|
|
47
|
+
filtrix paper account # paper trading account (Pro, once enabled)
|
|
41
48
|
filtrix keys create --name laptop
|
|
42
49
|
filtrix llms # machine-readable usage guide for AI agents
|
|
43
50
|
```
|
|
@@ -46,7 +53,11 @@ filtrix llms # machine-readable usage guide for AI agents
|
|
|
46
53
|
|
|
47
54
|
Output is human-readable in a terminal and JSON when piped or with the global `--json` flag.
|
|
48
55
|
Global flags (`--json`, `--quiet`, `--profile`, `--api-key`, `--base-url`) go BEFORE the subcommand.
|
|
49
|
-
Exit codes: 0 ok, 2 usage, 3 not-found, 4 auth, 5 rate-limited, 6 network, 1 server
|
|
56
|
+
Exit codes: 0 ok, 2 usage, 3 not-found, 4 auth, 5 rate-limited, 6 network or `--wait` timeout, 1 server
|
|
57
|
+
or failed job.
|
|
58
|
+
|
|
59
|
+
`runs save` and `simulate` start background jobs; `--wait` polls until they finish. `runs delete` needs
|
|
60
|
+
`--yes` when not interactive.
|
|
50
61
|
|
|
51
62
|
## Configuration
|
|
52
63
|
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# filtrix-cli — agent guide
|
|
2
|
+
|
|
3
|
+
Structured command-line access to the FILTRIX historical backtest engine.
|
|
4
|
+
|
|
5
|
+
## Output contract
|
|
6
|
+
- Add `--json` (or pipe stdout) to get JSON on stdout. Human tables otherwise.
|
|
7
|
+
- Data goes to stdout; errors/progress go to stderr.
|
|
8
|
+
- Errors (stderr, JSON): {"error":{"type","message","status","retryable","suggestion","input"}}.
|
|
9
|
+
|
|
10
|
+
## Exit codes
|
|
11
|
+
- 0 success
|
|
12
|
+
- 1 server/unexpected error (retryable)
|
|
13
|
+
- 2 usage / invalid filter
|
|
14
|
+
- 3 not found
|
|
15
|
+
- 4 authentication required/failed
|
|
16
|
+
- 5 rate limited (retryable)
|
|
17
|
+
- 6 network/timeout, incl. `--wait` giving up on a job that is still running (retryable)
|
|
18
|
+
|
|
19
|
+
## Auth
|
|
20
|
+
- Reads/backtests: set env FILTRIX_API_KEY=flt_... (or `filtrix config set api_key ...`).
|
|
21
|
+
- Quota: 50 requests/day free, 1000 Pro; meta, filters, account, premarket, jobs get are free. Resets at midnight America/New_York.
|
|
22
|
+
- Saved runs and simulations also have plan limits (`filtrix account`). `runs save`, `simulate`, `runs share|unshare|delete`
|
|
23
|
+
and `jobs cancel` change your account; an OAuth token granted read-only cannot run them.
|
|
24
|
+
- Key management: `filtrix auth login` first (stores a JWT).
|
|
25
|
+
|
|
26
|
+
## Commands
|
|
27
|
+
- filtrix meta (free) outcome definitions + units, limits, quotas, data coverage
|
|
28
|
+
- filtrix filters [--search TEXT] [--type number|date|string|time|enum] [--limit N] (no auth; ranked search)
|
|
29
|
+
- filtrix backtest --filter "COL OP VAL" [--filter ...] [--outcome ...] [--threshold X] [--pos-min A --pos-max B]
|
|
30
|
+
[--sample N] [--start YYYY-MM-DD] [--end YYYY-MM-DD] [--flat-threshold F]
|
|
31
|
+
- filtrix screen --filter ... [--limit N] [--offset N] [--field COL ...]
|
|
32
|
+
- filtrix ticker SYMBOL metadata (name, sector, market cap)
|
|
33
|
+
- filtrix overview SYMBOL last close, 1d/5d/20d moves, 52-week range, TTM fundamentals (verified email)
|
|
34
|
+
- filtrix gaps SYMBOL [--threshold 10] [--direction up|down] [--stat avg|median] this ticker's own gap history
|
|
35
|
+
- filtrix daily SYMBOL [--limit 250] daily OHLCV bars, oldest first (max 500)
|
|
36
|
+
- filtrix coverage [SYMBOL] first/last event date and counts
|
|
37
|
+
- filtrix premarket (free) today's premarket gappers with historical stats
|
|
38
|
+
- filtrix account (free) tier, quota used/remaining, reset time, capabilities
|
|
39
|
+
- filtrix runs list [--limit 20] [--offset 0] your saved runs with summaries
|
|
40
|
+
- filtrix runs get RUN_ID filters, outcome, summary, share link
|
|
41
|
+
- filtrix runs rows RUN_ID [--limit 100] [--offset 0] the run's events with outcome values (max 500)
|
|
42
|
+
- filtrix runs save --filter ... [--name N] [--outcome ...] [--row-filter all|positive|negative|neutral|nonzero]
|
|
43
|
+
[backtest options] [--wait] [--timeout 600] saves a run (background job)
|
|
44
|
+
- filtrix runs share|unshare RUN_ID public read-only link on/off
|
|
45
|
+
- filtrix runs delete RUN_ID --yes permanent; --yes is required when not interactive
|
|
46
|
+
- filtrix runs context RUN_ID SYMBOL DATE [--lookback 120] daily + that day's minute bars for one event
|
|
47
|
+
- filtrix simulate (--run-id N | --filter ...) --entry open_at_0930|green_to_red|red_to_green|bar_break
|
|
48
|
+
[--within-minutes M] --exit close_1600|hold_minutes|stop_loss_take_profit
|
|
49
|
+
[--hold-minutes M] [--sl 0.02] [--tp 0.05] [--side long|short] [--bar-minutes 1..30]
|
|
50
|
+
[--limit-pairs 200] [--wait] [--timeout 600]
|
|
51
|
+
- filtrix jobs get JOB_ID (free) status, progress, result
|
|
52
|
+
- filtrix jobs cancel JOB_ID
|
|
53
|
+
- filtrix keys list|create|revoke
|
|
54
|
+
- filtrix auth login|logout|status
|
|
55
|
+
- filtrix auth register --email E --password P --accept-tos (emails a 6-digit code, then prompts for it, then auto-logs-in)
|
|
56
|
+
- filtrix auth verify-code CODE --email E --password P (resume a pending signup)
|
|
57
|
+
- filtrix auth resend-code --email E
|
|
58
|
+
- filtrix config get|set|list|path
|
|
59
|
+
|
|
60
|
+
Note: global flags like `--json` go BEFORE the subcommand (e.g. `filtrix --json backtest ...`).
|
|
61
|
+
|
|
62
|
+
## Live Scanner and Paper Trading (Pro)
|
|
63
|
+
Available once FILTRIX enables the live API (until then: exit 3, "not available through the API yet").
|
|
64
|
+
- filtrix scanner status (free) session, freshness, allowed + reason
|
|
65
|
+
- filtrix scanner columns [--search Q] live columns (not the historical `filtrix filters`)
|
|
66
|
+
- filtrix scanner query --filter ... [--field COL ...] [--order-by COL --desc] [--limit 25 (max 100)] [--monitor-id N]
|
|
67
|
+
- filtrix scanner matches [--field COL ...] [--rows 25] what your running windows match now
|
|
68
|
+
- filtrix scanner chart SYMBOL
|
|
69
|
+
- filtrix scanner monitors list | save [--id N] [--name X] [--filter ...] [--telegram/--no-telegram] [--run/--stop]
|
|
70
|
+
| delete ID --yes
|
|
71
|
+
- filtrix paper status (free) | catalog | validate --spec-json JSON|- | account | list KIND [--after C] [--limit N]
|
|
72
|
+
(KIND: strategies, orders, positions, trades, events, epochs)
|
|
73
|
+
- filtrix paper create-account --limits-json JSON [--capital 100000] | limits --limits-json JSON
|
|
74
|
+
| reset --capital X --limits-json JSON --yes | close-all --yes
|
|
75
|
+
- filtrix paper strategy save --spec-json JSON [--id N] [--monitor-id N] | strategy archive ID --yes
|
|
76
|
+
- filtrix paper start STRATEGY_ID | pause RUN_ID | resume RUN_ID | close RUN_ID --yes
|
|
77
|
+
Paper money is simulated. Every paper write sends an Idempotency-Key (--idempotency-key, else a new one);
|
|
78
|
+
versions (--version, --account-version, --draft-version) are fetched from `filtrix paper account` when omitted.
|
|
79
|
+
A 409 version_conflict carries current_version. Run ids are UUIDs.
|
|
80
|
+
|
|
81
|
+
## Background jobs
|
|
82
|
+
`runs save` and `simulate` print {"job_id","status":"queued","poll"}. Add `--wait` to poll until the job ends
|
|
83
|
+
(prints the finished job; a failed job exits 1, `--timeout` seconds without an end exits 6), or poll with
|
|
84
|
+
`filtrix jobs get JOB_ID`. At most 2 jobs run at a time per account (429 otherwise).
|
|
85
|
+
A simulation's result: summary (n_trades, win_rate 0..1, profit_factor, avg_pnl / total_pnl in USD per share,
|
|
86
|
+
avg_holding_min), up to 200 trades with pnl_pct, run_id. Definitions: `filtrix meta --json` -> "simulation".
|
|
87
|
+
--sl / --tp are fractions (0.02 = 2%).
|
|
88
|
+
|
|
89
|
+
## Filter DSL
|
|
90
|
+
"COL OP VAL", operators: >= <= != = > < like in. Repeat --filter for AND.
|
|
91
|
+
Examples: "gap_gup>=10", "price_price<5", "earnings_date_days_earningd=0.25", "sic_code in 7372,7389".
|
|
92
|
+
Use the RAW schema column names from `filtrix filters` (e.g. price_price, float_shares_float) — these
|
|
93
|
+
can differ from screen's friendlier output field names (price, float_shares). Unknown columns return exit 2.
|
|
94
|
+
For exact control, pass `--filters-json '[{"column":...,"operator":...,"value":...,"value_type":...}]'`
|
|
95
|
+
or `--filters-json -` to read the JSON array from stdin.
|
|
96
|
+
|
|
97
|
+
## Discover filters
|
|
98
|
+
Run `filtrix filters --search "<words>" --json` to find columns (raw name, Trade-Ideas code, description,
|
|
99
|
+
operators, value type). `filtrix meta --json` defines every backtest outcome and its unit:
|
|
100
|
+
day_close_position (0 = closed at the low, 1 = at the high; default), day_return (fraction),
|
|
101
|
+
reg_pct / hi_to_cl_pct / lo_to_cl_pct (percent). Each backtest response also carries
|
|
102
|
+
outcome_definition, direction_rule (what long/short/flat_pct mean) and bucket_prob_definition.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.0"
|
|
@@ -12,6 +12,8 @@ from filtrix_cli.commands import authcmd
|
|
|
12
12
|
from filtrix_cli.commands import configcmd
|
|
13
13
|
from filtrix_cli.commands import llms as llms_cmd
|
|
14
14
|
from filtrix_cli.commands import market as market_cmd
|
|
15
|
+
from filtrix_cli.commands import research as research_cmd
|
|
16
|
+
from filtrix_cli.commands import live as live_cmd
|
|
15
17
|
|
|
16
18
|
app = typer.Typer(
|
|
17
19
|
add_completion=False,
|
|
@@ -57,6 +59,11 @@ app.command("overview")(market_cmd.overview)
|
|
|
57
59
|
app.command("gaps")(market_cmd.gaps)
|
|
58
60
|
app.command("daily")(market_cmd.daily)
|
|
59
61
|
app.command("premarket")(market_cmd.premarket)
|
|
62
|
+
app.add_typer(research_cmd.runs_app, name="runs")
|
|
63
|
+
app.command("simulate")(research_cmd.simulate)
|
|
64
|
+
app.add_typer(research_cmd.jobs_app, name="jobs")
|
|
65
|
+
app.add_typer(live_cmd.scanner_app, name="scanner")
|
|
66
|
+
app.add_typer(live_cmd.paper_app, name="paper")
|
|
60
67
|
|
|
61
68
|
|
|
62
69
|
def main() -> None:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Synchronous httpx client for the FILTRIX API, with error -> CLIError mapping."""
|
|
2
2
|
import json
|
|
3
3
|
from typing import Any, List, Optional
|
|
4
|
+
from urllib.parse import quote
|
|
4
5
|
|
|
5
6
|
import httpx
|
|
6
7
|
|
|
@@ -53,9 +54,9 @@ class FiltrixClient:
|
|
|
53
54
|
return headers
|
|
54
55
|
|
|
55
56
|
def _request(self, method: str, path: str, *, json_body: Any = None, auth: str = "any",
|
|
56
|
-
params: Optional[dict] = None) -> Any:
|
|
57
|
+
params: Optional[dict] = None, headers: Optional[dict] = None) -> Any:
|
|
57
58
|
url = f"{self.base_url}{path}"
|
|
58
|
-
headers = self._headers(auth)
|
|
59
|
+
headers = {**self._headers(auth), **(headers or {})}
|
|
59
60
|
clean_params = {k: v for k, v in (params or {}).items() if v is not None} or None
|
|
60
61
|
try:
|
|
61
62
|
with httpx.Client(timeout=self.timeout) as client:
|
|
@@ -136,6 +137,46 @@ class FiltrixClient:
|
|
|
136
137
|
def premarket_gappers(self) -> Any:
|
|
137
138
|
return self._request("GET", "/api/v1/premarket/gappers")
|
|
138
139
|
|
|
140
|
+
def call(self, method: str, path: str, *, json_body: Any = None, params: Optional[dict] = None,
|
|
141
|
+
headers: Optional[dict] = None) -> Any:
|
|
142
|
+
"""Any Public API v1 call with the configured credential (live scanner / paper commands)."""
|
|
143
|
+
return self._request(method, path, json_body=json_body, params=params, headers=headers)
|
|
144
|
+
|
|
145
|
+
# ---- Saved runs, simulations, jobs (v1) ----
|
|
146
|
+
def runs_list(self, limit: int = 20, offset: int = 0) -> Any:
|
|
147
|
+
return self._request("GET", "/api/v1/runs", params={"limit": limit, "offset": offset})
|
|
148
|
+
|
|
149
|
+
def run_get(self, run_id: int) -> Any:
|
|
150
|
+
return self._request("GET", f"/api/v1/runs/{int(run_id)}")
|
|
151
|
+
|
|
152
|
+
def run_rows(self, run_id: int, limit: int = 100, offset: int = 0) -> Any:
|
|
153
|
+
return self._request("GET", f"/api/v1/runs/{int(run_id)}/rows", params={"limit": limit, "offset": offset})
|
|
154
|
+
|
|
155
|
+
def run_save(self, body: dict) -> Any:
|
|
156
|
+
return self._request("POST", "/api/v1/runs", json_body=body)
|
|
157
|
+
|
|
158
|
+
def run_share(self, run_id: int) -> Any:
|
|
159
|
+
return self._request("POST", f"/api/v1/runs/{int(run_id)}/share")
|
|
160
|
+
|
|
161
|
+
def run_unshare(self, run_id: int) -> Any:
|
|
162
|
+
return self._request("DELETE", f"/api/v1/runs/{int(run_id)}/share")
|
|
163
|
+
|
|
164
|
+
def run_delete(self, run_id: int) -> Any:
|
|
165
|
+
return self._request("DELETE", f"/api/v1/runs/{int(run_id)}")
|
|
166
|
+
|
|
167
|
+
def trade_context(self, run_id: int, symbol: str, date: str, daily_lookback: int = 120) -> Any:
|
|
168
|
+
return self._request("GET", f"/api/v1/runs/{int(run_id)}/trade-context",
|
|
169
|
+
params={"symbol": symbol.upper(), "date": date, "daily_lookback": daily_lookback})
|
|
170
|
+
|
|
171
|
+
def simulate(self, body: dict) -> Any:
|
|
172
|
+
return self._request("POST", "/api/v1/simulations", json_body=body)
|
|
173
|
+
|
|
174
|
+
def job_get(self, job_id: str) -> Any:
|
|
175
|
+
return self._request("GET", f"/api/v1/jobs/{quote(job_id, safe='')}")
|
|
176
|
+
|
|
177
|
+
def job_cancel(self, job_id: str) -> Any:
|
|
178
|
+
return self._request("POST", f"/api/v1/jobs/{quote(job_id, safe='')}/cancel")
|
|
179
|
+
|
|
139
180
|
# ---- Key management (JWT) ----
|
|
140
181
|
def keys_list(self) -> Any:
|
|
141
182
|
return self._request("GET", "/api/keys", auth="jwt")
|
|
@@ -1,44 +1,55 @@
|
|
|
1
|
-
"""Shared plumbing for Typer commands: error handling, client construction, output."""
|
|
2
|
-
import functools
|
|
3
|
-
from typing import Any, Callable, Tuple
|
|
4
|
-
|
|
5
|
-
import typer
|
|
6
|
-
|
|
7
|
-
from filtrix_cli import config as config_mod
|
|
8
|
-
from filtrix_cli.client import FiltrixClient
|
|
9
|
-
from filtrix_cli.output import CLIError, emit_error, emit_json, is_json_mode
|
|
10
|
-
from filtrix_cli.render import render_human
|
|
11
|
-
from filtrix_cli.state import get_state
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def command(func: Callable) -> Callable:
|
|
15
|
-
"""Wrap a Typer command: catch CLIError, emit it, exit with its code.
|
|
16
|
-
functools.wraps keeps the original signature so Typer still sees the params."""
|
|
17
|
-
@functools.wraps(func)
|
|
18
|
-
def wrapper(*args, **kwargs):
|
|
19
|
-
json_mode = is_json_mode(get_state().json)
|
|
20
|
-
try:
|
|
21
|
-
return func(*args, **kwargs)
|
|
22
|
-
except CLIError as err:
|
|
23
|
-
emit_error(err, json_mode)
|
|
24
|
-
raise typer.Exit(err.exit_code)
|
|
25
|
-
return wrapper
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def
|
|
40
|
-
state = get_state()
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
"""Shared plumbing for Typer commands: error handling, client construction, output."""
|
|
2
|
+
import functools
|
|
3
|
+
from typing import Any, Callable, Tuple
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from filtrix_cli import config as config_mod
|
|
8
|
+
from filtrix_cli.client import FiltrixClient
|
|
9
|
+
from filtrix_cli.output import CLIError, emit_error, emit_json, is_json_mode
|
|
10
|
+
from filtrix_cli.render import render_human
|
|
11
|
+
from filtrix_cli.state import get_state
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def command(func: Callable) -> Callable:
|
|
15
|
+
"""Wrap a Typer command: catch CLIError, emit it, exit with its code.
|
|
16
|
+
functools.wraps keeps the original signature so Typer still sees the params."""
|
|
17
|
+
@functools.wraps(func)
|
|
18
|
+
def wrapper(*args, **kwargs):
|
|
19
|
+
json_mode = is_json_mode(get_state().json)
|
|
20
|
+
try:
|
|
21
|
+
return func(*args, **kwargs)
|
|
22
|
+
except CLIError as err:
|
|
23
|
+
emit_error(err, json_mode)
|
|
24
|
+
raise typer.Exit(err.exit_code)
|
|
25
|
+
return wrapper
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def require_yes(yes: bool, message: str, suggestion: str) -> None:
|
|
29
|
+
"""Destructive commands: --yes, or an interactive confirmation. Never silently in scripts."""
|
|
30
|
+
import sys
|
|
31
|
+
|
|
32
|
+
if yes:
|
|
33
|
+
return
|
|
34
|
+
if is_json_mode(get_state().json) or not sys.stdin.isatty():
|
|
35
|
+
raise CLIError("invalid_request", f"{message}; pass --yes to confirm.", suggestion=suggestion, exit_code=2)
|
|
36
|
+
typer.confirm(f"{message}. Continue?", abort=True)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def build_client() -> Tuple[FiltrixClient, dict]:
|
|
40
|
+
state = get_state()
|
|
41
|
+
settings = config_mod.resolve_settings(
|
|
42
|
+
profile=state.profile, api_key=state.api_key, base_url=state.base_url
|
|
43
|
+
)
|
|
44
|
+
client = FiltrixClient(
|
|
45
|
+
base_url=settings["base_url"], api_key=settings["api_key"], jwt=settings["jwt"]
|
|
46
|
+
)
|
|
47
|
+
return client, settings
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def output_result(result: Any, *, kind: str) -> None:
|
|
51
|
+
state = get_state()
|
|
52
|
+
if is_json_mode(state.json):
|
|
53
|
+
emit_json(result)
|
|
54
|
+
else:
|
|
55
|
+
render_human(result, kind=kind, quiet=state.quiet, no_color=state.no_color)
|