filtrix-cli 0.6.0__tar.gz → 0.7.1__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.
Files changed (56) hide show
  1. filtrix_cli-0.7.1/CHANGELOG.md +49 -0
  2. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/PKG-INFO +1 -1
  3. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/pyproject.toml +1 -1
  4. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/AGENTS.md +30 -1
  5. filtrix_cli-0.7.1/src/filtrix_cli/__init__.py +1 -0
  6. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/__main__.py +76 -74
  7. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/client.py +71 -6
  8. filtrix_cli-0.7.1/src/filtrix_cli/commands/scanner_backtest.py +321 -0
  9. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/output.py +8 -0
  10. filtrix_cli-0.7.1/src/filtrix_cli/render.py +239 -0
  11. filtrix_cli-0.7.1/tests/test_cmd_scanner_backtest.py +346 -0
  12. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_smoke.py +1 -1
  13. filtrix_cli-0.6.0/CHANGELOG.md +0 -25
  14. filtrix_cli-0.6.0/src/filtrix_cli/__init__.py +0 -1
  15. filtrix_cli-0.6.0/src/filtrix_cli/render.py +0 -120
  16. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/.gitignore +0 -0
  17. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/LICENSE +0 -0
  18. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/README.md +0 -0
  19. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/auth.py +0 -0
  20. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/__init__.py +0 -0
  21. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/_helpers.py +0 -0
  22. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/account.py +0 -0
  23. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/authcmd.py +0 -0
  24. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/backtest.py +0 -0
  25. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/configcmd.py +0 -0
  26. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/filters.py +0 -0
  27. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/keys.py +0 -0
  28. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/live.py +0 -0
  29. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/llms.py +0 -0
  30. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/market.py +0 -0
  31. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/research.py +0 -0
  32. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/screen.py +0 -0
  33. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/ticker.py +0 -0
  34. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/config.py +0 -0
  35. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/filters.py +0 -0
  36. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/src/filtrix_cli/state.py +0 -0
  37. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/__init__.py +0 -0
  38. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_auth.py +0 -0
  39. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_client.py +0 -0
  40. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_client_register.py +0 -0
  41. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_auth.py +0 -0
  42. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_backtest_screen.py +0 -0
  43. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_config.py +0 -0
  44. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_keys.py +0 -0
  45. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_live.py +0 -0
  46. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_llms.py +0 -0
  47. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_market.py +0 -0
  48. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_profile.py +0 -0
  49. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_read.py +0 -0
  50. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_register.py +0 -0
  51. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_cmd_research.py +0 -0
  52. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_config.py +0 -0
  53. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_filters.py +0 -0
  54. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_helpers.py +0 -0
  55. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_output.py +0 -0
  56. {filtrix_cli-0.6.0 → filtrix_cli-0.7.1}/tests/test_render.py +0 -0
@@ -0,0 +1,49 @@
1
+ # Changelog
2
+
3
+ ## 0.7.1 (2026-12-04)
4
+
5
+ Follows the Scanner Backtest API changes of 0cc0473f (all additive):
6
+
7
+ - `start --rerun --wait` exits 1 (`rerun_failed`) when the rerun failed or was cancelled: the run stays done
8
+ with its earlier result (`last_rerun`). The human output of a run shows its last failed rerun.
9
+ - A queued simulation shows its place in line (`queue position N`).
10
+
11
+ ## 0.7.0 (2026-12-03)
12
+
13
+ - New `filtrix scanner-backtest` commands on the Scanner Backtest API (`/api/v1/scanner-backtest`). They answer
14
+ `not_enabled` until FILTRIX opens that API for the account.
15
+ - `start` (a window with `--monitor`, or `--filter`; `--years` or `--from/--to`; `--session`; `--rerun`),
16
+ `get`, `list`, `events` (`--all` reads pages of 1000), `cancel` and `limits`.
17
+ - `catalog`, `simulate JOB_ID --rules ...` (inline JSON, a file or `-`), `simulation`, `simulations`,
18
+ `trades` and `cancel-simulation`.
19
+ - `paper-spec` gives a simulation's rules as a spec for `filtrix paper strategy save`.
20
+ - `--wait` polls at the server's `poll.after_seconds`. A failed run prints its body and exits 1 with its
21
+ code and reasons.
22
+ - An API error that names its code (`{"error": code, ...}`) shows it with its extra fields
23
+ (`next_start_at`, `resets_at`, `active_id`, `retry_after`, the reasons per column...). The JSON error also has
24
+ `code` and `details`, and the suggestion fits the code.
25
+ - Agent guide: a Scanner Backtest section.
26
+
27
+ ## 0.6.0 (2026-11-30)
28
+
29
+ - `filtrix gaps`: the statistics come from FILTRIX's own 1-minute bars since Nov 2016 for tickers in that
30
+ universe (`meta.source` `"filtrix_minute_bars"`), Trade-Ideas alert days otherwise. New `--events` also
31
+ lists every counted gap day (long output).
32
+ - `filtrix runs save --row-filter` help: it picks which rows are stored with the run; the run's statistics
33
+ always use all rows.
34
+ - Agent guide: events without minute bars are not simulated; `missing_minute_data` counts them.
35
+
36
+ ## 0.5.0 (2026-11-11)
37
+
38
+ - A paper write the account worker has not answered within the server's 10 s wait comes back
39
+ `{"status": "pending", "event_id"}`. The CLI now reads its outcome for about 12 s more, with the same
40
+ Idempotency-Key, and prints the result.
41
+ - Still no answer: it prints `{"status": "pending", "event_id", "idempotency_key"}` and exits 6. The command
42
+ may still apply. Read it later with the new `filtrix paper command EVENT_ID`, and resend only with the same
43
+ `--idempotency-key`.
44
+ - A command refused while pending (for example 409 `version_conflict`) exits as a direct refusal would.
45
+ - A 500 `internal_error` on a paper write is retried once with the same key and body.
46
+
47
+ ## 0.4.0 (2026-11-08)
48
+
49
+ - `filtrix scanner` and `filtrix paper` commands (Pro), available once FILTRIX enables the live API.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: filtrix-cli
3
- Version: 0.6.0
3
+ Version: 0.7.1
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/
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "filtrix-cli"
7
- version = "0.6.0"
7
+ version = "0.7.1"
8
8
  description = "Agent-first command-line interface for the FILTRIX backtest engine."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -5,7 +5,9 @@ Structured command-line access to the FILTRIX historical backtest engine.
5
5
  ## Output contract
6
6
  - Add `--json` (or pipe stdout) to get JSON on stdout. Human tables otherwise.
7
7
  - Data goes to stdout; errors/progress go to stderr.
8
- - Errors (stderr, JSON): {"error":{"type","message","status","retryable","suggestion","input"}}.
8
+ - Errors (stderr, JSON): {"error":{"type","message","status","retryable","suggestion","input"}}. An API error
9
+ that names its code (Scanner Backtest) also has "code" and "details" (e.g. next_start_at, resets_at, active_id,
10
+ retry_after, reasons).
9
11
 
10
12
  ## Exit codes
11
13
  - 0 success
@@ -85,6 +87,33 @@ answer: stdout {"status":"pending","event_id","idempotency_key"}, exit 6; it may
85
87
  a direct one would (e.g. 409 version_conflict, exit 2). A 500 internal_error is
86
88
  retried once with the same key and body.
87
89
 
90
+ ## Scanner Backtest
91
+ Replays one of your scanner windows (or Live Scanner filters) over FILTRIX's minute-bar history (up to 10 years,
92
+ premarket included), then simulates trades on its events. Available once FILTRIX opens this API for your account
93
+ (until then: exit 3, code not_enabled).
94
+ - filtrix scanner-backtest limits (free) plan, max_months, today's months and simulations quota, can_start_now /
95
+ next_start_at, retention, pace (seconds per computed month)
96
+ - filtrix scanner-backtest start (--monitor N | --filter ...) [--years 2 | --from D --to D]
97
+ [--session premarket|rth|postmarket ...] [--rerun] [--wait] [--timeout 900]
98
+ - filtrix scanner-backtest get JOB_ID [--wait] (free) status, progress; when done summary + caveats
99
+ - filtrix scanner-backtest list | events JOB_ID [--limit 100 (max 1000)] [--cursor C] [--all [--max-pages 20]]
100
+ | cancel JOB_ID
101
+ - filtrix scanner-backtest catalog rules/account schema and defaults (start from defaults.rules)
102
+ - filtrix scanner-backtest simulate JOB_ID --rules JSON|FILE|- [--account JSON|FILE|-] [--rerun] [--wait]
103
+ - filtrix scanner-backtest simulation SIM_ID [--wait] (free) | simulations [--job JOB_ID]
104
+ | trades SIM_ID [--limit/--cursor/--all] | cancel-simulation SIM_ID
105
+ - filtrix scanner-backtest paper-spec SIM_ID the rules as a spec for `filtrix paper strategy save` (saves nothing)
106
+ Quota (shared with the web page): months computed a day and 60 simulations a day; the same request joins the
107
+ existing run without charging (created: false). One queued or running backtest and one simulation at a time
108
+ (active_limit, with active_id). No start on a trading day from 09:30 ET until 5 minutes after the close
109
+ (closed_hours, exit 2, details.next_start_at). 20:30-21:45 ET a run waits for the nightly update and resumes by
110
+ itself (deferred_until). A first 10-year run of new filters takes about 9-10 minutes: start without --wait and
111
+ poll `get JOB_ID` (free), or --wait with --timeout. A failed run prints its body and exits 1 (code e.g.
112
+ unsupported_columns with reasons per column). Each events/trades page is one request: page one after another,
113
+ --all reads 1000 a page; events_gone (410) means run it again with --rerun (months come from the cache).
114
+ A backtest's outcomes are raw % moves from the next bar's open, no slippage or fees; a simulation applies slippage
115
+ and fees with full fills at the bar open (caveats.not_modelled lists what is not modelled).
116
+
88
117
  ## Background jobs
89
118
  `runs save` and `simulate` print {"job_id","status":"queued","poll"}. Add `--wait` to poll until the job ends
90
119
  (prints the finished job; a failed job exits 1, `--timeout` seconds without an end exits 6), or poll with
@@ -0,0 +1 @@
1
+ __version__ = "0.7.1"
@@ -1,74 +1,76 @@
1
- import typer
2
-
3
- from filtrix_cli import __version__
4
- from filtrix_cli.state import set_state
5
- from filtrix_cli.commands import backtest as backtest_cmd
6
- from filtrix_cli.commands import screen as screen_cmd
7
- from filtrix_cli.commands import ticker as ticker_cmd
8
- from filtrix_cli.commands import filters as filters_cmd
9
- from filtrix_cli.commands import account as account_cmd
10
- from filtrix_cli.commands import keys as keys_cmd
11
- from filtrix_cli.commands import authcmd
12
- from filtrix_cli.commands import configcmd
13
- from filtrix_cli.commands import llms as llms_cmd
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
17
-
18
- app = typer.Typer(
19
- add_completion=False,
20
- help="FILTRIX CLI — terminal access to the FILTRIX backtest engine.",
21
- )
22
-
23
-
24
- @app.callback(invoke_without_command=True)
25
- def _root(
26
- ctx: typer.Context,
27
- json: bool = typer.Option(False, "--json", help="Force JSON output to stdout."),
28
- quiet: bool = typer.Option(False, "--quiet", "-q", help="Bare values only."),
29
- no_color: bool = typer.Option(False, "--no-color", help="Disable colored output."),
30
- profile: str = typer.Option(None, "--profile", help="Config profile to use."),
31
- api_key: str = typer.Option(None, "--api-key", help="Override API key for this run."),
32
- base_url: str = typer.Option(None, "--base-url", help="Override API base URL for this run."),
33
- ) -> None:
34
- """FILTRIX CLI — terminal access to the FILTRIX backtest engine."""
35
- set_state(json=json, quiet=quiet, no_color=no_color,
36
- profile=profile, api_key=api_key, base_url=base_url)
37
- if ctx.invoked_subcommand is None:
38
- typer.echo(ctx.get_help())
39
-
40
-
41
- @app.command()
42
- def version() -> None:
43
- """Print the CLI version."""
44
- typer.echo(f"filtrix-cli {__version__}")
45
-
46
-
47
- app.command("backtest")(backtest_cmd.backtest)
48
- app.command("screen")(screen_cmd.screen)
49
- app.command("ticker")(ticker_cmd.ticker)
50
- app.command("filters")(filters_cmd.filters)
51
- app.command("account")(account_cmd.account)
52
- app.add_typer(keys_cmd.app, name="keys")
53
- app.add_typer(authcmd.app, name="auth")
54
- app.add_typer(configcmd.app, name="config")
55
- app.command("llms")(llms_cmd.llms)
56
- app.command("meta")(market_cmd.meta)
57
- app.command("coverage")(market_cmd.coverage)
58
- app.command("overview")(market_cmd.overview)
59
- app.command("gaps")(market_cmd.gaps)
60
- app.command("daily")(market_cmd.daily)
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")
67
-
68
-
69
- def main() -> None:
70
- app()
71
-
72
-
73
- if __name__ == "__main__":
74
- main()
1
+ import typer
2
+
3
+ from filtrix_cli import __version__
4
+ from filtrix_cli.state import set_state
5
+ from filtrix_cli.commands import backtest as backtest_cmd
6
+ from filtrix_cli.commands import screen as screen_cmd
7
+ from filtrix_cli.commands import ticker as ticker_cmd
8
+ from filtrix_cli.commands import filters as filters_cmd
9
+ from filtrix_cli.commands import account as account_cmd
10
+ from filtrix_cli.commands import keys as keys_cmd
11
+ from filtrix_cli.commands import authcmd
12
+ from filtrix_cli.commands import configcmd
13
+ from filtrix_cli.commands import llms as llms_cmd
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
17
+ from filtrix_cli.commands import scanner_backtest as scanner_backtest_cmd
18
+
19
+ app = typer.Typer(
20
+ add_completion=False,
21
+ help="FILTRIX CLI — terminal access to the FILTRIX backtest engine.",
22
+ )
23
+
24
+
25
+ @app.callback(invoke_without_command=True)
26
+ def _root(
27
+ ctx: typer.Context,
28
+ json: bool = typer.Option(False, "--json", help="Force JSON output to stdout."),
29
+ quiet: bool = typer.Option(False, "--quiet", "-q", help="Bare values only."),
30
+ no_color: bool = typer.Option(False, "--no-color", help="Disable colored output."),
31
+ profile: str = typer.Option(None, "--profile", help="Config profile to use."),
32
+ api_key: str = typer.Option(None, "--api-key", help="Override API key for this run."),
33
+ base_url: str = typer.Option(None, "--base-url", help="Override API base URL for this run."),
34
+ ) -> None:
35
+ """FILTRIX CLI — terminal access to the FILTRIX backtest engine."""
36
+ set_state(json=json, quiet=quiet, no_color=no_color,
37
+ profile=profile, api_key=api_key, base_url=base_url)
38
+ if ctx.invoked_subcommand is None:
39
+ typer.echo(ctx.get_help())
40
+
41
+
42
+ @app.command()
43
+ def version() -> None:
44
+ """Print the CLI version."""
45
+ typer.echo(f"filtrix-cli {__version__}")
46
+
47
+
48
+ app.command("backtest")(backtest_cmd.backtest)
49
+ app.command("screen")(screen_cmd.screen)
50
+ app.command("ticker")(ticker_cmd.ticker)
51
+ app.command("filters")(filters_cmd.filters)
52
+ app.command("account")(account_cmd.account)
53
+ app.add_typer(keys_cmd.app, name="keys")
54
+ app.add_typer(authcmd.app, name="auth")
55
+ app.add_typer(configcmd.app, name="config")
56
+ app.command("llms")(llms_cmd.llms)
57
+ app.command("meta")(market_cmd.meta)
58
+ app.command("coverage")(market_cmd.coverage)
59
+ app.command("overview")(market_cmd.overview)
60
+ app.command("gaps")(market_cmd.gaps)
61
+ app.command("daily")(market_cmd.daily)
62
+ app.command("premarket")(market_cmd.premarket)
63
+ app.add_typer(research_cmd.runs_app, name="runs")
64
+ app.command("simulate")(research_cmd.simulate)
65
+ app.add_typer(research_cmd.jobs_app, name="jobs")
66
+ app.add_typer(live_cmd.scanner_app, name="scanner")
67
+ app.add_typer(live_cmd.paper_app, name="paper")
68
+ app.add_typer(scanner_backtest_cmd.app, name="scanner-backtest")
69
+
70
+
71
+ def main() -> None:
72
+ app()
73
+
74
+
75
+ if __name__ == "__main__":
76
+ main()
@@ -43,6 +43,64 @@ def _is_refusal(resp: httpx.Response) -> bool:
43
43
  return 400 <= resp.status_code < 500 and resp.status_code != 429 and _paper_code(resp) is not None
44
44
 
45
45
 
46
+ # Errors that name their code ({"detail": {"error": code, "message", ...}}, the Scanner Backtest API):
47
+ # the fields worth printing, in this order, and what to do next. The HTTP status still picks the
48
+ # error type and the exit code.
49
+ ERROR_EXTRAS = ("status", "next_start_at", "reopens_at", "resets_at", "used", "limit", "active_id",
50
+ "max_months", "retry_after", "block", "code", "path")
51
+ _RETRY = "Retry after retry_after seconds."
52
+ CODE_SUGGESTIONS = {
53
+ "not_enabled": "Scanner Backtest is not open through the API for this account yet (FILTRIX enables it).",
54
+ "not_available": "Scanner Backtest is not open to this account yet.",
55
+ "verify_email": "Confirm your email at https://filtrix.net/app, then retry.",
56
+ "pro_required": "This needs a paid plan: https://filtrix.net/pricing",
57
+ "insufficient_scope": "Use an API key (or a token) with write access.",
58
+ "closed_hours": "Starts are paused while the market is open; start again at next_start_at "
59
+ "(`filtrix scanner-backtest limits`).",
60
+ "active_limit": "Follow the active one (active_id) with `filtrix scanner-backtest get` (or `simulation`), "
61
+ "or cancel it.",
62
+ "quota": "Daily Scanner Backtest quota used; `filtrix scanner-backtest limits` shows resets_at. Finished "
63
+ "runs stay free to open.",
64
+ "events_gone": "Start the backtest again with --rerun; finished months come from the cache.",
65
+ "trades_gone": "Simulate again with --rerun.",
66
+ "unsupported_columns": "These columns cannot be replayed over history: drop them from the filters.",
67
+ "period_too_long": "Shorten the period to max_months (`filtrix scanner-backtest limits`).",
68
+ "invalid_request": "Give one of --monitor or --filter, and a period of at most 10 years "
69
+ "(`filtrix scanner-backtest limits` shows max_months).",
70
+ "invalid_rules": "Check the rules and account against `filtrix scanner-backtest catalog`.",
71
+ "invalid_cursor": "Pass next_cursor of the previous page unchanged, or no --cursor for the first page.",
72
+ "not_done": "Not done yet: `filtrix scanner-backtest get ID --wait` (or `simulation ID --wait`).",
73
+ "backtest_not_done": "Wait for the backtest: `filtrix scanner-backtest get ID --wait`, then simulate.",
74
+ "queue_full": _RETRY,
75
+ "busy": _RETRY,
76
+ "unavailable": _RETRY,
77
+ "limits_unavailable": _RETRY,
78
+ }
79
+
80
+
81
+ def _coded_detail(resp: httpx.Response) -> Optional[dict]:
82
+ """The detail of an error that names its code {"detail": {"error": code, ...}}, else None."""
83
+ try:
84
+ detail = resp.json().get("detail")
85
+ except Exception:
86
+ return None
87
+ if isinstance(detail, dict) and isinstance(detail.get("error"), str) and detail["error"]:
88
+ return detail
89
+ return None
90
+
91
+
92
+ def format_coded(detail: dict) -> str:
93
+ """'message (code); key=value; column: reason' of a coded error."""
94
+ code = detail["error"]
95
+ message = str(detail.get("message") or code).rstrip(".")
96
+ parts = [f"{message} ({code})" if message != code else message]
97
+ parts.extend(f"{key}={detail[key]}" for key in ERROR_EXTRAS if detail.get(key) is not None)
98
+ reasons = detail.get("reasons")
99
+ if isinstance(reasons, dict):
100
+ parts.extend(f"{column}: {reason}" for column, reason in reasons.items())
101
+ return "; ".join(parts)
102
+
103
+
46
104
  def _safe_detail(resp: httpx.Response) -> str:
47
105
  try:
48
106
  data = resp.json()
@@ -108,19 +166,26 @@ class FiltrixClient:
108
166
  def _handle_response(self, resp: httpx.Response) -> Any:
109
167
  if resp.status_code < 400:
110
168
  return resp.json() if resp.content else {}
111
- detail = _safe_detail(resp)
169
+ coded = _coded_detail(resp)
170
+ detail = format_coded(coded) if coded else _safe_detail(resp)
171
+ more: dict = {}
172
+ hint = None
173
+ if coded:
174
+ details = {k: v for k, v in coded.items() if k not in ("error", "message")}
175
+ more = {"code": coded["error"], "details": details or None}
176
+ hint = CODE_SUGGESTIONS.get(coded["error"])
112
177
  code = resp.status_code
113
178
  if code in (401, 403):
114
179
  raise CLIError("auth_failed", detail, status=code,
115
- suggestion="Run `filtrix auth login` or check your API key.", exit_code=4)
180
+ suggestion=hint or "Run `filtrix auth login` or check your API key.", exit_code=4, **more)
116
181
  if code == 404:
117
- raise CLIError("not_found", detail, status=404, exit_code=3)
182
+ raise CLIError("not_found", detail, status=404, suggestion=hint, exit_code=3, **more)
118
183
  if code == 429:
119
184
  raise CLIError("rate_limited", detail, status=429, retryable=True,
120
- suggestion="Run `filtrix account` to see your quota.", exit_code=5)
185
+ suggestion=hint or "Run `filtrix account` to see your quota.", exit_code=5, **more)
121
186
  if 400 <= code < 500:
122
- raise CLIError("invalid_request", detail, status=code, exit_code=2)
123
- raise CLIError("server_error", detail, status=code, retryable=True, exit_code=1)
187
+ raise CLIError("invalid_request", detail, status=code, suggestion=hint, exit_code=2, **more)
188
+ raise CLIError("server_error", detail, status=code, retryable=True, suggestion=hint, exit_code=1, **more)
124
189
 
125
190
  # ---- Public API v1 ----
126
191
  def backtest(self, filters: List[dict], outcome: str = "day_close_position",