filtrix-cli 0.5.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.
- filtrix_cli-0.7.1/CHANGELOG.md +49 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/PKG-INFO +1 -1
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/pyproject.toml +1 -1
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/AGENTS.md +39 -8
- filtrix_cli-0.7.1/src/filtrix_cli/__init__.py +1 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/__main__.py +76 -74
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/client.py +76 -9
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/market.py +70 -68
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/research.py +1 -1
- filtrix_cli-0.7.1/src/filtrix_cli/commands/scanner_backtest.py +321 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/output.py +8 -0
- filtrix_cli-0.7.1/src/filtrix_cli/render.py +239 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_market.py +185 -163
- filtrix_cli-0.7.1/tests/test_cmd_scanner_backtest.py +346 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_smoke.py +1 -1
- filtrix_cli-0.5.0/CHANGELOG.md +0 -16
- filtrix_cli-0.5.0/src/filtrix_cli/__init__.py +0 -1
- filtrix_cli-0.5.0/src/filtrix_cli/render.py +0 -120
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/.gitignore +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/LICENSE +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/README.md +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/auth.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/__init__.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/_helpers.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/account.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/authcmd.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/backtest.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/configcmd.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/filters.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/keys.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/live.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/llms.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/screen.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/commands/ticker.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/config.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/filters.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/src/filtrix_cli/state.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/__init__.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_auth.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_client.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_client_register.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_auth.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_backtest_screen.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_config.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_keys.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_live.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_llms.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_profile.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_read.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_register.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_cmd_research.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_config.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_filters.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_helpers.py +0 -0
- {filtrix_cli-0.5.0 → filtrix_cli-0.7.1}/tests/test_output.py +0 -0
- {filtrix_cli-0.5.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.
|
|
@@ -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
|
|
@@ -14,7 +16,7 @@ Structured command-line access to the FILTRIX historical backtest engine.
|
|
|
14
16
|
- 3 not found
|
|
15
17
|
- 4 authentication required/failed
|
|
16
18
|
- 5 rate limited (retryable)
|
|
17
|
-
- 6 network/timeout, incl. `--wait` giving up on a job that is still running (retryable), or a paper command
|
|
19
|
+
- 6 network/timeout, incl. `--wait` giving up on a job that is still running (retryable), or a paper command
|
|
18
20
|
still pending (see Live Scanner and Paper Trading)
|
|
19
21
|
|
|
20
22
|
## Auth
|
|
@@ -75,22 +77,51 @@ Available once FILTRIX enables the live API (until then: exit 3, "not available
|
|
|
75
77
|
| reset --capital X --limits-json JSON --yes | close-all --yes
|
|
76
78
|
- filtrix paper strategy save --spec-json JSON [--id N] [--monitor-id N] | strategy archive ID --yes
|
|
77
79
|
- filtrix paper start STRATEGY_ID | pause RUN_ID | resume RUN_ID | close RUN_ID --yes
|
|
78
|
-
- filtrix paper command EVENT_ID outcome of a write that exited 6 "pending": its result, or still pending
|
|
80
|
+
- filtrix paper command EVENT_ID outcome of a write that exited 6 "pending": its result, or still pending
|
|
79
81
|
Paper money is simulated. Every paper write sends an Idempotency-Key (--idempotency-key, else a new one);
|
|
80
82
|
versions (--version, --account-version, --draft-version) are fetched from `filtrix paper account` when omitted.
|
|
81
|
-
A 409 version_conflict carries current_version. Run ids are UUIDs.
|
|
82
|
-
A write waits for the account worker (up to ~10 s on the server, then ~12 s of status reads). Still no
|
|
83
|
-
answer: stdout {"status":"pending","event_id","idempotency_key"}, exit 6; it may still apply, so read it with
|
|
84
|
-
`filtrix paper command EVENT_ID` and resend only with the same --idempotency-key. A refusal read there exits as
|
|
83
|
+
A 409 version_conflict carries current_version. Run ids are UUIDs.
|
|
84
|
+
A write waits for the account worker (up to ~10 s on the server, then ~12 s of status reads). Still no
|
|
85
|
+
answer: stdout {"status":"pending","event_id","idempotency_key"}, exit 6; it may still apply, so read it with
|
|
86
|
+
`filtrix paper command EVENT_ID` and resend only with the same --idempotency-key. A refusal read there exits as
|
|
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
|
|
91
120
|
`filtrix jobs get JOB_ID`. At most 2 jobs run at a time per account (429 otherwise).
|
|
92
121
|
A simulation's result: summary (n_trades, win_rate 0..1, profit_factor, avg_pnl / total_pnl in USD per share,
|
|
93
|
-
avg_holding_min), up to 200 trades with pnl_pct, run_id.
|
|
122
|
+
avg_holding_min), up to 200 trades with pnl_pct, run_id. Events without minute bars are not simulated;
|
|
123
|
+
missing_minute_data counts them (pending: loaded every night; unavailable: none exist).
|
|
124
|
+
Definitions: `filtrix meta --json` -> "simulation".
|
|
94
125
|
--sl / --tp are fractions (0.02 = 2%).
|
|
95
126
|
|
|
96
127
|
## Filter DSL
|
|
@@ -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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
app.command("
|
|
49
|
-
app.command("
|
|
50
|
-
app.command("
|
|
51
|
-
app.command("
|
|
52
|
-
app.
|
|
53
|
-
app.add_typer(
|
|
54
|
-
app.add_typer(
|
|
55
|
-
app.
|
|
56
|
-
app.command("
|
|
57
|
-
app.command("
|
|
58
|
-
app.command("
|
|
59
|
-
app.command("
|
|
60
|
-
app.command("
|
|
61
|
-
app.command("
|
|
62
|
-
app.
|
|
63
|
-
app.
|
|
64
|
-
app.
|
|
65
|
-
app.add_typer(
|
|
66
|
-
app.add_typer(live_cmd.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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",
|
|
@@ -165,9 +230,11 @@ class FiltrixClient:
|
|
|
165
230
|
return self._request("GET", f"/api/v1/ticker/{symbol.upper()}/overview")
|
|
166
231
|
|
|
167
232
|
def ticker_gap_stats(self, symbol: str, gap_threshold: float = 10.0,
|
|
168
|
-
direction: str = "up", stat: str = "avg") -> Any:
|
|
169
|
-
|
|
170
|
-
|
|
233
|
+
direction: str = "up", stat: str = "avg", include_events: bool = False) -> Any:
|
|
234
|
+
params = {"gap_threshold": gap_threshold, "direction": direction, "stat": stat}
|
|
235
|
+
if include_events:
|
|
236
|
+
params["include_events"] = "true"
|
|
237
|
+
return self._request("GET", f"/api/v1/ticker/{symbol.upper()}/gap-stats", params=params)
|
|
171
238
|
|
|
172
239
|
def ticker_daily(self, symbol: str, limit: int = 250) -> Any:
|
|
173
240
|
return self._request("GET", f"/api/v1/ticker/{symbol.upper()}/daily", params={"limit": limit})
|
|
@@ -1,68 +1,70 @@
|
|
|
1
|
-
"""Read-only market and ticker commands over the Public API v1."""
|
|
2
|
-
from enum import Enum
|
|
3
|
-
from typing import Optional
|
|
4
|
-
|
|
5
|
-
import typer
|
|
6
|
-
|
|
7
|
-
from filtrix_cli.commands._helpers import build_client, command, output_result
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class Direction(str, Enum):
|
|
11
|
-
up = "up"
|
|
12
|
-
down = "down"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class Stat(str, Enum):
|
|
16
|
-
avg = "avg"
|
|
17
|
-
median = "median"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@command
|
|
21
|
-
def meta() -> None:
|
|
22
|
-
"""Outcome definitions and units, limits, quotas and data coverage (free)."""
|
|
23
|
-
client, _ = build_client()
|
|
24
|
-
output_result(client.meta(), kind="meta")
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@command
|
|
28
|
-
def coverage(symbol: Optional[str] = typer.Argument(None, help="Ticker; omit for the whole dataset.")) -> None:
|
|
29
|
-
"""First/last historical event date and event counts."""
|
|
30
|
-
client, _ = build_client()
|
|
31
|
-
output_result(client.coverage(symbol), kind="coverage")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@command
|
|
35
|
-
def overview(symbol: str = typer.Argument(..., help="Ticker symbol, e.g. AAPL.")) -> None:
|
|
36
|
-
"""Ticker snapshot: last close, recent moves, 52-week range, TTM fundamentals."""
|
|
37
|
-
client, _ = build_client()
|
|
38
|
-
output_result(client.ticker_overview(symbol), kind="overview")
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
@command
|
|
42
|
-
def gaps(
|
|
43
|
-
symbol: str = typer.Argument(..., help="Ticker symbol, e.g. TSLA."),
|
|
44
|
-
threshold: float = typer.Option(10.0, "--threshold", min=0, help="Minimum gap in percent (10 = 10%)."),
|
|
45
|
-
direction: Direction = typer.Option(Direction.up, "--direction", help="Gap direction."),
|
|
46
|
-
stat: Stat = typer.Option(Stat.avg, "--stat", help="Aggregate across gap events."),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
""
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
1
|
+
"""Read-only market and ticker commands over the Public API v1."""
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from filtrix_cli.commands._helpers import build_client, command, output_result
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Direction(str, Enum):
|
|
11
|
+
up = "up"
|
|
12
|
+
down = "down"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Stat(str, Enum):
|
|
16
|
+
avg = "avg"
|
|
17
|
+
median = "median"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@command
|
|
21
|
+
def meta() -> None:
|
|
22
|
+
"""Outcome definitions and units, limits, quotas and data coverage (free)."""
|
|
23
|
+
client, _ = build_client()
|
|
24
|
+
output_result(client.meta(), kind="meta")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@command
|
|
28
|
+
def coverage(symbol: Optional[str] = typer.Argument(None, help="Ticker; omit for the whole dataset.")) -> None:
|
|
29
|
+
"""First/last historical event date and event counts."""
|
|
30
|
+
client, _ = build_client()
|
|
31
|
+
output_result(client.coverage(symbol), kind="coverage")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@command
|
|
35
|
+
def overview(symbol: str = typer.Argument(..., help="Ticker symbol, e.g. AAPL.")) -> None:
|
|
36
|
+
"""Ticker snapshot: last close, recent moves, 52-week range, TTM fundamentals."""
|
|
37
|
+
client, _ = build_client()
|
|
38
|
+
output_result(client.ticker_overview(symbol), kind="overview")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@command
|
|
42
|
+
def gaps(
|
|
43
|
+
symbol: str = typer.Argument(..., help="Ticker symbol, e.g. TSLA."),
|
|
44
|
+
threshold: float = typer.Option(10.0, "--threshold", min=0, help="Minimum gap in percent (10 = 10%)."),
|
|
45
|
+
direction: Direction = typer.Option(Direction.up, "--direction", help="Gap direction."),
|
|
46
|
+
stat: Stat = typer.Option(Stat.avg, "--stat", help="Aggregate across gap events."),
|
|
47
|
+
events: bool = typer.Option(False, "--events",
|
|
48
|
+
help="Also list every counted gap day (stats from our minute bars; long output)."),
|
|
49
|
+
) -> None:
|
|
50
|
+
"""How this ticker's own past gaps resolved (gap day and the next day)."""
|
|
51
|
+
client, _ = build_client()
|
|
52
|
+
output_result(client.ticker_gap_stats(symbol, gap_threshold=threshold, direction=direction.value,
|
|
53
|
+
stat=stat.value, include_events=events), kind="gaps")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@command
|
|
57
|
+
def daily(
|
|
58
|
+
symbol: str = typer.Argument(..., help="Ticker symbol, e.g. AAPL."),
|
|
59
|
+
limit: int = typer.Option(250, "--limit", min=1, max=500, help="Number of recent daily bars."),
|
|
60
|
+
) -> None:
|
|
61
|
+
"""Daily OHLCV bars, oldest first."""
|
|
62
|
+
client, _ = build_client()
|
|
63
|
+
output_result(client.ticker_daily(symbol, limit=limit), kind="daily")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@command
|
|
67
|
+
def premarket() -> None:
|
|
68
|
+
"""Today's premarket gappers with historical stats of similar gaps (free)."""
|
|
69
|
+
client, _ = build_client()
|
|
70
|
+
output_result(client.premarket_gappers(), kind="premarket")
|
|
@@ -124,7 +124,7 @@ def runs_save(
|
|
|
124
124
|
flat_threshold: float = typer.Option(0.002, "--flat-threshold"),
|
|
125
125
|
pos_min: Optional[float] = typer.Option(None, "--pos-min"),
|
|
126
126
|
pos_max: Optional[float] = typer.Option(None, "--pos-max"),
|
|
127
|
-
row_filter: RowFilter = typer.Option(RowFilter.all, "--row-filter", help="Which outcome rows to
|
|
127
|
+
row_filter: RowFilter = typer.Option(RowFilter.all, "--row-filter", help="Which outcome rows to store with the run; the run's statistics always use all rows."),
|
|
128
128
|
wait: bool = typer.Option(False, "--wait", help="Poll until the save finishes."),
|
|
129
129
|
timeout: float = typer.Option(600, "--timeout", min=0, help="Seconds --wait polls before giving up."),
|
|
130
130
|
) -> None:
|