filtrix-cli 0.5.0__tar.gz → 0.6.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.
Files changed (52) hide show
  1. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/CHANGELOG.md +9 -0
  2. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/PKG-INFO +1 -1
  3. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/pyproject.toml +1 -1
  4. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/AGENTS.md +9 -7
  5. filtrix_cli-0.6.0/src/filtrix_cli/__init__.py +1 -0
  6. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/client.py +5 -3
  7. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/market.py +70 -68
  8. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/research.py +1 -1
  9. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_market.py +185 -163
  10. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_smoke.py +1 -1
  11. filtrix_cli-0.5.0/src/filtrix_cli/__init__.py +0 -1
  12. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/.gitignore +0 -0
  13. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/LICENSE +0 -0
  14. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/README.md +0 -0
  15. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/__main__.py +0 -0
  16. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/auth.py +0 -0
  17. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/__init__.py +0 -0
  18. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/_helpers.py +0 -0
  19. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/account.py +0 -0
  20. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/authcmd.py +0 -0
  21. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/backtest.py +0 -0
  22. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/configcmd.py +0 -0
  23. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/filters.py +0 -0
  24. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/keys.py +0 -0
  25. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/live.py +0 -0
  26. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/llms.py +0 -0
  27. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/screen.py +0 -0
  28. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/commands/ticker.py +0 -0
  29. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/config.py +0 -0
  30. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/filters.py +0 -0
  31. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/output.py +0 -0
  32. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/render.py +0 -0
  33. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/src/filtrix_cli/state.py +0 -0
  34. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/__init__.py +0 -0
  35. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_auth.py +0 -0
  36. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_client.py +0 -0
  37. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_client_register.py +0 -0
  38. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_auth.py +0 -0
  39. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_backtest_screen.py +0 -0
  40. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_config.py +0 -0
  41. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_keys.py +0 -0
  42. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_live.py +0 -0
  43. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_llms.py +0 -0
  44. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_profile.py +0 -0
  45. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_read.py +0 -0
  46. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_register.py +0 -0
  47. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_cmd_research.py +0 -0
  48. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_config.py +0 -0
  49. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_filters.py +0 -0
  50. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_helpers.py +0 -0
  51. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_output.py +0 -0
  52. {filtrix_cli-0.5.0 → filtrix_cli-0.6.0}/tests/test_render.py +0 -0
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0 (2026-11-30)
4
+
5
+ - `filtrix gaps`: the statistics come from FILTRIX's own 1-minute bars since Nov 2016 for tickers in that
6
+ universe (`meta.source` `"filtrix_minute_bars"`), Trade-Ideas alert days otherwise. New `--events` also
7
+ lists every counted gap day (long output).
8
+ - `filtrix runs save --row-filter` help: it picks which rows are stored with the run; the run's statistics
9
+ always use all rows.
10
+ - Agent guide: events without minute bars are not simulated; `missing_minute_data` counts them.
11
+
3
12
  ## 0.5.0 (2026-11-11)
4
13
 
5
14
  - A paper write the account worker has not answered within the server's 10 s wait comes back
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: filtrix-cli
3
- Version: 0.5.0
3
+ Version: 0.6.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/
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "filtrix-cli"
7
- version = "0.5.0"
7
+ version = "0.6.0"
8
8
  description = "Agent-first command-line interface for the FILTRIX backtest engine."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -14,7 +14,7 @@ Structured command-line access to the FILTRIX historical backtest engine.
14
14
  - 3 not found
15
15
  - 4 authentication required/failed
16
16
  - 5 rate limited (retryable)
17
- - 6 network/timeout, incl. `--wait` giving up on a job that is still running (retryable), or a paper command
17
+ - 6 network/timeout, incl. `--wait` giving up on a job that is still running (retryable), or a paper command
18
18
  still pending (see Live Scanner and Paper Trading)
19
19
 
20
20
  ## Auth
@@ -75,13 +75,13 @@ Available once FILTRIX enables the live API (until then: exit 3, "not available
75
75
  | reset --capital X --limits-json JSON --yes | close-all --yes
76
76
  - filtrix paper strategy save --spec-json JSON [--id N] [--monitor-id N] | strategy archive ID --yes
77
77
  - 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
78
+ - filtrix paper command EVENT_ID outcome of a write that exited 6 "pending": its result, or still pending
79
79
  Paper money is simulated. Every paper write sends an Idempotency-Key (--idempotency-key, else a new one);
80
80
  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
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
85
85
  a direct one would (e.g. 409 version_conflict, exit 2). A 500 internal_error is
86
86
  retried once with the same key and body.
87
87
 
@@ -90,7 +90,9 @@ retried once with the same key and body.
90
90
  (prints the finished job; a failed job exits 1, `--timeout` seconds without an end exits 6), or poll with
91
91
  `filtrix jobs get JOB_ID`. At most 2 jobs run at a time per account (429 otherwise).
92
92
  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. Definitions: `filtrix meta --json` -> "simulation".
93
+ avg_holding_min), up to 200 trades with pnl_pct, run_id. Events without minute bars are not simulated;
94
+ missing_minute_data counts them (pending: loaded every night; unavailable: none exist).
95
+ Definitions: `filtrix meta --json` -> "simulation".
94
96
  --sl / --tp are fractions (0.02 = 2%).
95
97
 
96
98
  ## Filter DSL
@@ -0,0 +1 @@
1
+ __version__ = "0.6.0"
@@ -165,9 +165,11 @@ class FiltrixClient:
165
165
  return self._request("GET", f"/api/v1/ticker/{symbol.upper()}/overview")
166
166
 
167
167
  def ticker_gap_stats(self, symbol: str, gap_threshold: float = 10.0,
168
- direction: str = "up", stat: str = "avg") -> Any:
169
- return self._request("GET", f"/api/v1/ticker/{symbol.upper()}/gap-stats",
170
- params={"gap_threshold": gap_threshold, "direction": direction, "stat": stat})
168
+ direction: str = "up", stat: str = "avg", include_events: bool = False) -> Any:
169
+ params = {"gap_threshold": gap_threshold, "direction": direction, "stat": stat}
170
+ if include_events:
171
+ params["include_events"] = "true"
172
+ return self._request("GET", f"/api/v1/ticker/{symbol.upper()}/gap-stats", params=params)
171
173
 
172
174
  def ticker_daily(self, symbol: str, limit: int = 250) -> Any:
173
175
  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
- ) -> None:
48
- """How this ticker's own past gaps resolved (gap day and the next day)."""
49
- client, _ = build_client()
50
- output_result(client.ticker_gap_stats(symbol, gap_threshold=threshold,
51
- direction=direction.value, stat=stat.value), kind="gaps")
52
-
53
-
54
- @command
55
- def daily(
56
- symbol: str = typer.Argument(..., help="Ticker symbol, e.g. AAPL."),
57
- limit: int = typer.Option(250, "--limit", min=1, max=500, help="Number of recent daily bars."),
58
- ) -> None:
59
- """Daily OHLCV bars, oldest first."""
60
- client, _ = build_client()
61
- output_result(client.ticker_daily(symbol, limit=limit), kind="daily")
62
-
63
-
64
- @command
65
- def premarket() -> None:
66
- """Today's premarket gappers with historical stats of similar gaps (free)."""
67
- client, _ = build_client()
68
- output_result(client.premarket_gappers(), kind="premarket")
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 keep."),
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:
@@ -1,163 +1,185 @@
1
- import json
2
-
3
- import respx
4
- from httpx import Response
5
- from typer.testing import CliRunner
6
-
7
- from filtrix_cli.__main__ import app
8
- from filtrix_cli.state import reset_state
9
-
10
- runner = CliRunner()
11
- BASE = "https://api.test"
12
-
13
-
14
- def setup_function():
15
- reset_state()
16
-
17
-
18
- def _env(monkeypatch):
19
- monkeypatch.setenv("FILTRIX_API_KEY", "flt_x")
20
- monkeypatch.setenv("FILTRIX_BASE_URL", BASE)
21
-
22
-
23
- @respx.mock
24
- def test_meta(monkeypatch):
25
- _env(monkeypatch)
26
- respx.get(f"{BASE}/api/v1/meta").mock(return_value=Response(200, json={"api_version": "1"}))
27
-
28
- result = runner.invoke(app, ["meta"])
29
-
30
- assert result.exit_code == 0
31
- assert json.loads(result.stdout)["api_version"] == "1"
32
-
33
-
34
- @respx.mock
35
- def test_coverage_with_symbol(monkeypatch):
36
- _env(monkeypatch)
37
- route = respx.get(f"{BASE}/api/v1/coverage").mock(return_value=Response(200, json={"events_for_symbol": 4}))
38
-
39
- result = runner.invoke(app, ["coverage", "tsla"])
40
-
41
- assert result.exit_code == 0
42
- assert route.calls.last.request.url.params["symbol"] == "TSLA"
43
-
44
-
45
- @respx.mock
46
- def test_coverage_without_symbol_sends_no_param(monkeypatch):
47
- _env(monkeypatch)
48
- route = respx.get(f"{BASE}/api/v1/coverage").mock(return_value=Response(200, json={"total_events": 9}))
49
-
50
- result = runner.invoke(app, ["coverage"])
51
-
52
- assert result.exit_code == 0
53
- assert "symbol" not in route.calls.last.request.url.params
54
-
55
-
56
- @respx.mock
57
- def test_overview(monkeypatch):
58
- _env(monkeypatch)
59
- respx.get(f"{BASE}/api/v1/ticker/AAPL/overview").mock(return_value=Response(200, json={"last_close": 200.0}))
60
-
61
- result = runner.invoke(app, ["overview", "aapl"])
62
-
63
- assert result.exit_code == 0
64
- assert json.loads(result.stdout)["last_close"] == 200.0
65
-
66
-
67
- @respx.mock
68
- def test_gaps_options(monkeypatch):
69
- _env(monkeypatch)
70
- route = respx.get(f"{BASE}/api/v1/ticker/TSLA/gap-stats").mock(return_value=Response(200, json={"overview": {}}))
71
-
72
- result = runner.invoke(app, ["gaps", "TSLA", "--threshold", "15", "--direction", "down", "--stat", "median"])
73
-
74
- assert result.exit_code == 0
75
- params = route.calls.last.request.url.params
76
- assert (params["gap_threshold"], params["direction"], params["stat"]) == ("15.0", "down", "median")
77
-
78
-
79
- def test_gaps_rejects_bad_direction(monkeypatch):
80
- _env(monkeypatch)
81
-
82
- result = runner.invoke(app, ["gaps", "TSLA", "--direction", "sideways"])
83
-
84
- assert result.exit_code == 2
85
-
86
-
87
- @respx.mock
88
- def test_daily_limit(monkeypatch):
89
- _env(monkeypatch)
90
- route = respx.get(f"{BASE}/api/v1/ticker/AAPL/daily").mock(return_value=Response(200, json={"data": []}))
91
-
92
- result = runner.invoke(app, ["daily", "AAPL", "--limit", "30"])
93
-
94
- assert result.exit_code == 0
95
- assert route.calls.last.request.url.params["limit"] == "30"
96
-
97
-
98
- @respx.mock
99
- def test_premarket(monkeypatch):
100
- _env(monkeypatch)
101
- respx.get(f"{BASE}/api/v1/premarket/gappers").mock(return_value=Response(200, json={"rows": [{"ticker": "X"}]}))
102
-
103
- result = runner.invoke(app, ["premarket"])
104
-
105
- assert result.exit_code == 0
106
- assert json.loads(result.stdout)["rows"][0]["ticker"] == "X"
107
-
108
-
109
- @respx.mock
110
- def test_filters_search_is_server_side(monkeypatch):
111
- monkeypatch.setenv("FILTRIX_BASE_URL", BASE)
112
- route = respx.get(f"{BASE}/api/v1/filters").mock(return_value=Response(200, json={"total": 1, "columns": [
113
- {"column": "rv_computed", "value_type": "number", "operators": []}]}))
114
-
115
- result = runner.invoke(app, ["filters", "--search", "relative volume", "--type", "number"])
116
-
117
- assert result.exit_code == 0
118
- params = route.calls.last.request.url.params
119
- assert params["q"] == "relative volume"
120
- assert params["type"] == "number"
121
- assert [c["column"] for c in json.loads(result.stdout)["columns"]] == ["rv_computed"]
122
-
123
-
124
- @respx.mock
125
- def test_backtest_new_flags(monkeypatch):
126
- _env(monkeypatch)
127
- route = respx.post(f"{BASE}/api/v1/backtest").mock(return_value=Response(200, json={"n": 1, "summary": {}}))
128
-
129
- result = runner.invoke(app, ["backtest", "-f", "gap_gup>=10", "--threshold", "0.6",
130
- "--pos-min", "0.3", "--pos-max", "0.9", "--sample", "5"])
131
-
132
- assert result.exit_code == 0
133
- sent = json.loads(route.calls.last.request.content)
134
- assert (sent["threshold"], sent["pos_min"], sent["pos_max"], sent["sample_limit"]) == (0.6, 0.3, 0.9, 5)
135
-
136
-
137
- @respx.mock
138
- def test_backtest_defaults_send_no_band(monkeypatch):
139
- _env(monkeypatch)
140
- route = respx.post(f"{BASE}/api/v1/backtest").mock(return_value=Response(200, json={"n": 1, "summary": {}}))
141
-
142
- runner.invoke(app, ["backtest", "-f", "gap_gup>=10"])
143
-
144
- sent = json.loads(route.calls.last.request.content)
145
- assert "pos_min" not in sent and "pos_max" not in sent
146
- assert sent["sample_limit"] == 0
147
-
148
-
149
- @respx.mock
150
- def test_screen_field_flag(monkeypatch):
151
- _env(monkeypatch)
152
- route = respx.post(f"{BASE}/api/v1/screen").mock(return_value=Response(200, json={"total": 0, "results": []}))
153
-
154
- result = runner.invoke(app, ["screen", "-f", "gap_gup>=10", "--field", "rv_computed", "--field", "sector_name"])
155
-
156
- assert result.exit_code == 0
157
- assert json.loads(route.calls.last.request.content)["fields"] == ["rv_computed", "sector_name"]
158
-
159
-
160
- def test_backtest_threshold_help_states_unit():
161
- result = runner.invoke(app, ["backtest", "--help"], env={"COLUMNS": "200"})
162
-
163
- assert "outcome's unit" in result.stdout
1
+ import json
2
+
3
+ import respx
4
+ from httpx import Response
5
+ from typer.testing import CliRunner
6
+
7
+ from filtrix_cli.__main__ import app
8
+ from filtrix_cli.state import reset_state
9
+
10
+ runner = CliRunner()
11
+ BASE = "https://api.test"
12
+
13
+
14
+ def setup_function():
15
+ reset_state()
16
+
17
+
18
+ def _env(monkeypatch):
19
+ monkeypatch.setenv("FILTRIX_API_KEY", "flt_x")
20
+ monkeypatch.setenv("FILTRIX_BASE_URL", BASE)
21
+
22
+
23
+ @respx.mock
24
+ def test_meta(monkeypatch):
25
+ _env(monkeypatch)
26
+ respx.get(f"{BASE}/api/v1/meta").mock(return_value=Response(200, json={"api_version": "1"}))
27
+
28
+ result = runner.invoke(app, ["meta"])
29
+
30
+ assert result.exit_code == 0
31
+ assert json.loads(result.stdout)["api_version"] == "1"
32
+
33
+
34
+ @respx.mock
35
+ def test_coverage_with_symbol(monkeypatch):
36
+ _env(monkeypatch)
37
+ route = respx.get(f"{BASE}/api/v1/coverage").mock(return_value=Response(200, json={"events_for_symbol": 4}))
38
+
39
+ result = runner.invoke(app, ["coverage", "tsla"])
40
+
41
+ assert result.exit_code == 0
42
+ assert route.calls.last.request.url.params["symbol"] == "TSLA"
43
+
44
+
45
+ @respx.mock
46
+ def test_coverage_without_symbol_sends_no_param(monkeypatch):
47
+ _env(monkeypatch)
48
+ route = respx.get(f"{BASE}/api/v1/coverage").mock(return_value=Response(200, json={"total_events": 9}))
49
+
50
+ result = runner.invoke(app, ["coverage"])
51
+
52
+ assert result.exit_code == 0
53
+ assert "symbol" not in route.calls.last.request.url.params
54
+
55
+
56
+ @respx.mock
57
+ def test_overview(monkeypatch):
58
+ _env(monkeypatch)
59
+ respx.get(f"{BASE}/api/v1/ticker/AAPL/overview").mock(return_value=Response(200, json={"last_close": 200.0}))
60
+
61
+ result = runner.invoke(app, ["overview", "aapl"])
62
+
63
+ assert result.exit_code == 0
64
+ assert json.loads(result.stdout)["last_close"] == 200.0
65
+
66
+
67
+ @respx.mock
68
+ def test_gaps_options(monkeypatch):
69
+ _env(monkeypatch)
70
+ route = respx.get(f"{BASE}/api/v1/ticker/TSLA/gap-stats").mock(return_value=Response(200, json={"overview": {}}))
71
+
72
+ result = runner.invoke(app, ["gaps", "TSLA", "--threshold", "15", "--direction", "down", "--stat", "median"])
73
+
74
+ assert result.exit_code == 0
75
+ params = route.calls.last.request.url.params
76
+ assert (params["gap_threshold"], params["direction"], params["stat"]) == ("15.0", "down", "median")
77
+
78
+
79
+ @respx.mock
80
+ def test_gaps_leaves_events_out_by_default(monkeypatch):
81
+ _env(monkeypatch)
82
+ route = respx.get(f"{BASE}/api/v1/ticker/TSLA/gap-stats").mock(return_value=Response(200, json={"overview": {}}))
83
+
84
+ result = runner.invoke(app, ["gaps", "TSLA"])
85
+
86
+ assert result.exit_code == 0
87
+ assert "include_events" not in route.calls.last.request.url.params
88
+
89
+
90
+ @respx.mock
91
+ def test_gaps_events_flag(monkeypatch):
92
+ _env(monkeypatch)
93
+ route = respx.get(f"{BASE}/api/v1/ticker/TSLA/gap-stats").mock(return_value=Response(200, json={"overview": {}}))
94
+
95
+ result = runner.invoke(app, ["gaps", "TSLA", "--events"])
96
+
97
+ assert result.exit_code == 0
98
+ assert route.calls.last.request.url.params["include_events"] == "true"
99
+
100
+
101
+ def test_gaps_rejects_bad_direction(monkeypatch):
102
+ _env(monkeypatch)
103
+
104
+ result = runner.invoke(app, ["gaps", "TSLA", "--direction", "sideways"])
105
+
106
+ assert result.exit_code == 2
107
+
108
+
109
+ @respx.mock
110
+ def test_daily_limit(monkeypatch):
111
+ _env(monkeypatch)
112
+ route = respx.get(f"{BASE}/api/v1/ticker/AAPL/daily").mock(return_value=Response(200, json={"data": []}))
113
+
114
+ result = runner.invoke(app, ["daily", "AAPL", "--limit", "30"])
115
+
116
+ assert result.exit_code == 0
117
+ assert route.calls.last.request.url.params["limit"] == "30"
118
+
119
+
120
+ @respx.mock
121
+ def test_premarket(monkeypatch):
122
+ _env(monkeypatch)
123
+ respx.get(f"{BASE}/api/v1/premarket/gappers").mock(return_value=Response(200, json={"rows": [{"ticker": "X"}]}))
124
+
125
+ result = runner.invoke(app, ["premarket"])
126
+
127
+ assert result.exit_code == 0
128
+ assert json.loads(result.stdout)["rows"][0]["ticker"] == "X"
129
+
130
+
131
+ @respx.mock
132
+ def test_filters_search_is_server_side(monkeypatch):
133
+ monkeypatch.setenv("FILTRIX_BASE_URL", BASE)
134
+ route = respx.get(f"{BASE}/api/v1/filters").mock(return_value=Response(200, json={"total": 1, "columns": [
135
+ {"column": "rv_computed", "value_type": "number", "operators": []}]}))
136
+
137
+ result = runner.invoke(app, ["filters", "--search", "relative volume", "--type", "number"])
138
+
139
+ assert result.exit_code == 0
140
+ params = route.calls.last.request.url.params
141
+ assert params["q"] == "relative volume"
142
+ assert params["type"] == "number"
143
+ assert [c["column"] for c in json.loads(result.stdout)["columns"]] == ["rv_computed"]
144
+
145
+
146
+ @respx.mock
147
+ def test_backtest_new_flags(monkeypatch):
148
+ _env(monkeypatch)
149
+ route = respx.post(f"{BASE}/api/v1/backtest").mock(return_value=Response(200, json={"n": 1, "summary": {}}))
150
+
151
+ result = runner.invoke(app, ["backtest", "-f", "gap_gup>=10", "--threshold", "0.6",
152
+ "--pos-min", "0.3", "--pos-max", "0.9", "--sample", "5"])
153
+
154
+ assert result.exit_code == 0
155
+ sent = json.loads(route.calls.last.request.content)
156
+ assert (sent["threshold"], sent["pos_min"], sent["pos_max"], sent["sample_limit"]) == (0.6, 0.3, 0.9, 5)
157
+
158
+
159
+ @respx.mock
160
+ def test_backtest_defaults_send_no_band(monkeypatch):
161
+ _env(monkeypatch)
162
+ route = respx.post(f"{BASE}/api/v1/backtest").mock(return_value=Response(200, json={"n": 1, "summary": {}}))
163
+
164
+ runner.invoke(app, ["backtest", "-f", "gap_gup>=10"])
165
+
166
+ sent = json.loads(route.calls.last.request.content)
167
+ assert "pos_min" not in sent and "pos_max" not in sent
168
+ assert sent["sample_limit"] == 0
169
+
170
+
171
+ @respx.mock
172
+ def test_screen_field_flag(monkeypatch):
173
+ _env(monkeypatch)
174
+ route = respx.post(f"{BASE}/api/v1/screen").mock(return_value=Response(200, json={"total": 0, "results": []}))
175
+
176
+ result = runner.invoke(app, ["screen", "-f", "gap_gup>=10", "--field", "rv_computed", "--field", "sector_name"])
177
+
178
+ assert result.exit_code == 0
179
+ assert json.loads(route.calls.last.request.content)["fields"] == ["rv_computed", "sector_name"]
180
+
181
+
182
+ def test_backtest_threshold_help_states_unit():
183
+ result = runner.invoke(app, ["backtest", "--help"], env={"COLUMNS": "200"})
184
+
185
+ assert "outcome's unit" in result.stdout
@@ -9,7 +9,7 @@ runner = CliRunner()
9
9
  def test_version_prints_semver():
10
10
  result = runner.invoke(app, ["version"])
11
11
  assert result.exit_code == 0
12
- assert "filtrix-cli 0.5.0" in result.stdout
12
+ assert "filtrix-cli 0.6.0" in result.stdout
13
13
 
14
14
 
15
15
  def test_no_args_shows_help():
@@ -1 +0,0 @@
1
- __version__ = "0.5.0"
File without changes
File without changes
File without changes