capitalcom-cli 0.5.0__tar.gz → 0.5.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 (83) hide show
  1. {capitalcom_cli-0.5.0/capitalcom_cli.egg-info → capitalcom_cli-0.5.1}/PKG-INFO +12 -6
  2. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/README.md +11 -5
  3. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/__init__.py +1 -1
  4. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/risk.py +4 -0
  5. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1/capitalcom_cli.egg-info}/PKG-INFO +12 -6
  6. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capitalcom_cli.egg-info/SOURCES.txt +1 -0
  7. capitalcom_cli-0.5.1/tests/test_coverage_doc_in_sync.py +35 -0
  8. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_risk.py +48 -0
  9. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/LICENSE +0 -0
  10. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/NOTICE +0 -0
  11. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/__main__.py +0 -0
  12. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/__init__.py +0 -0
  13. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/account_cmds.py +0 -0
  14. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/app.py +0 -0
  15. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/context.py +0 -0
  16. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/doctor_cmds.py +0 -0
  17. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/live_guard.py +0 -0
  18. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/market_cmds.py +0 -0
  19. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/output.py +0 -0
  20. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/runner.py +0 -0
  21. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/session_cmds.py +0 -0
  22. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/stream_cmds.py +0 -0
  23. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/trade_cmds.py +0 -0
  24. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/cli/watchlist_cmds.py +0 -0
  25. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/__init__.py +0 -0
  26. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/audit.py +0 -0
  27. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/config.py +0 -0
  28. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/errors.py +0 -0
  29. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/http_client.py +0 -0
  30. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/models.py +0 -0
  31. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/rate_limit.py +0 -0
  32. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/session.py +0 -0
  33. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/state.py +0 -0
  34. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/utils.py +0 -0
  35. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/core/websocket_client.py +0 -0
  36. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/sdk/__init__.py +0 -0
  37. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/sdk/app.py +0 -0
  38. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/sdk/config.py +0 -0
  39. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/sdk/risk_policy.py +0 -0
  40. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/services/__init__.py +0 -0
  41. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/services/accounts.py +0 -0
  42. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/services/confirmations.py +0 -0
  43. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/services/markets.py +0 -0
  44. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/services/streaming.py +0 -0
  45. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/services/trading.py +0 -0
  46. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capital_cli/services/watchlists.py +0 -0
  47. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capitalcom_cli.egg-info/dependency_links.txt +0 -0
  48. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capitalcom_cli.egg-info/entry_points.txt +0 -0
  49. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capitalcom_cli.egg-info/requires.txt +0 -0
  50. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/capitalcom_cli.egg-info/top_level.txt +0 -0
  51. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/pyproject.toml +0 -0
  52. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/setup.cfg +0 -0
  53. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_account_cmds.py +0 -0
  54. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_app.py +0 -0
  55. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_audit.py +0 -0
  56. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_build_broker_request.py +0 -0
  57. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_cli_usage_errors.py +0 -0
  58. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_config_errors.py +0 -0
  59. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_core_port.py +0 -0
  60. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_credential_cmd.py +0 -0
  61. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_doctor.py +0 -0
  62. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_errors.py +0 -0
  63. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_global_flag_hoist.py +0 -0
  64. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_http_client.py +0 -0
  65. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_init_state_singletons.py +0 -0
  66. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_live_guard.py +0 -0
  67. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_market_cmds.py +0 -0
  68. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_output.py +0 -0
  69. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_output_color.py +0 -0
  70. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_output_plain.py +0 -0
  71. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_redaction.py +0 -0
  72. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_runner.py +0 -0
  73. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_session_cmds.py +0 -0
  74. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_session_persistence.py +0 -0
  75. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_state.py +0 -0
  76. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_stream_cmds.py +0 -0
  77. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_trade_cmds.py +0 -0
  78. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_trade_limit.py +0 -0
  79. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_tz_datetimes.py +0 -0
  80. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_utils.py +0 -0
  81. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_version.py +0 -0
  82. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_watchlist_cmds.py +0 -0
  83. {capitalcom_cli-0.5.0 → capitalcom_cli-0.5.1}/tests/test_websocket_parsing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: capitalcom-cli
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Command-line client for the Capital.com Open API
5
5
  Author: Simon Tarara
6
6
  License: Apache-2.0
@@ -38,6 +38,7 @@ Browse markets, manage accounts and watchlists, preview and execute trades behin
38
38
  [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
39
39
  [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
40
40
  [![Release](https://img.shields.io/github/v/release/SimonTarara62/capitalcom-cli?sort=semver)](https://github.com/SimonTarara62/capitalcom-cli/releases)
41
+ [![API coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/SimonTarara62/capitalcom-cli/main/docs/coverage-badge.json)](docs/api-coverage.md)
41
42
 
42
43
  ```text
43
44
  $ capctl market search "gold"
@@ -70,9 +71,11 @@ See [practical use cases](docs/use-cases.md) for worked, copy-pasteable scenario
70
71
  tested broker engine is also embeddable as an **experimental** Python SDK — see
71
72
  [Use as a library](#use-as-a-library-experimental) and [docs/sdk.md](docs/sdk.md).
72
73
  The `capital_cli.core.*` internals remain private and may change between releases.
73
- The CLI itself is short-lived: each command runs as its own process and may create
74
- its own API session. `capctl session login` is mainly a connectivity/account check;
75
- session tokens are not persisted between separate invocations.
74
+ The CLI itself is short-lived: each command runs as its own process. By default
75
+ (`CAP_PERSIST_SESSION=true`) the short-lived session tokens are cached so
76
+ back-to-back commands reuse one login instead of re-authenticating each time
77
+ (which can trip Capital.com's login-rate limit and return HTTP 429); `capctl
78
+ session login` is mainly a connectivity/account check.
76
79
 
77
80
  ## Features
78
81
 
@@ -83,6 +86,8 @@ session tokens are not persisted between separate invocations.
83
86
  - **Real-time streaming** — live price tables, price-level alerts, and portfolio snapshots over WebSocket
84
87
  - **Demo and live environments** — defaults to demo; live requires explicit opt-in
85
88
  - **Built-in rate limiting** — client-side token buckets respect Capital.com's 10 req/s global, 1 req/s session, and trading-burst limits
89
+ - **Session-token caching** — back-to-back commands reuse one login instead of re-authenticating (avoids HTTP 429); on by default, opt out with `CAP_PERSIST_SESSION=false`
90
+ - **Embeddable SDK (experimental)** — the same broker engine ships as an async Python library; see [Use as a library](#use-as-a-library-experimental)
86
91
 
87
92
  ## Installation
88
93
 
@@ -173,6 +178,7 @@ Main settings and their defaults:
173
178
  | `CAP_REQUIRE_EXPLICIT_CONFIRM` | `true` | Mutations need `--yes` |
174
179
  | `CAP_DRY_RUN` | `false` | Block all executions regardless of other flags |
175
180
  | `CAP_DEFAULT_ACCOUNT_ID` | (none) | Account selected after login |
181
+ | `CAP_PERSIST_SESSION` | `true` | Cache short-lived session tokens in the state file so back-to-back commands reuse one login (avoids HTTP 429); set `false` to keep tokens in-process only |
176
182
  | `CAP_HTTP_TIMEOUT_S` | `15` | HTTP timeout |
177
183
  | `CAP_LOG_LEVEL` | `WARNING` | `DEBUG` … `CRITICAL` |
178
184
  | `CAP_WS_ENABLED` | `false` | Required for `capctl stream …` |
@@ -272,9 +278,9 @@ capctl account topup 1000 --yes # demo environment only
272
278
  Read-only:
273
279
 
274
280
  ```bash
275
- capctl trade positions
281
+ capctl trade positions [--limit 10] # -n/--limit caps rows shown
276
282
  capctl trade position DEAL_ID
277
- capctl trade orders
283
+ capctl trade orders [--limit 10] # -n/--limit caps rows shown
278
284
  capctl trade confirm DEAL_REFERENCE [--wait --timeout 30]
279
285
  ```
280
286
 
@@ -9,6 +9,7 @@ Browse markets, manage accounts and watchlists, preview and execute trades behin
9
9
  [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
10
10
  [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
11
11
  [![Release](https://img.shields.io/github/v/release/SimonTarara62/capitalcom-cli?sort=semver)](https://github.com/SimonTarara62/capitalcom-cli/releases)
12
+ [![API coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/SimonTarara62/capitalcom-cli/main/docs/coverage-badge.json)](docs/api-coverage.md)
12
13
 
13
14
  ```text
14
15
  $ capctl market search "gold"
@@ -41,9 +42,11 @@ See [practical use cases](docs/use-cases.md) for worked, copy-pasteable scenario
41
42
  tested broker engine is also embeddable as an **experimental** Python SDK — see
42
43
  [Use as a library](#use-as-a-library-experimental) and [docs/sdk.md](docs/sdk.md).
43
44
  The `capital_cli.core.*` internals remain private and may change between releases.
44
- The CLI itself is short-lived: each command runs as its own process and may create
45
- its own API session. `capctl session login` is mainly a connectivity/account check;
46
- session tokens are not persisted between separate invocations.
45
+ The CLI itself is short-lived: each command runs as its own process. By default
46
+ (`CAP_PERSIST_SESSION=true`) the short-lived session tokens are cached so
47
+ back-to-back commands reuse one login instead of re-authenticating each time
48
+ (which can trip Capital.com's login-rate limit and return HTTP 429); `capctl
49
+ session login` is mainly a connectivity/account check.
47
50
 
48
51
  ## Features
49
52
 
@@ -54,6 +57,8 @@ session tokens are not persisted between separate invocations.
54
57
  - **Real-time streaming** — live price tables, price-level alerts, and portfolio snapshots over WebSocket
55
58
  - **Demo and live environments** — defaults to demo; live requires explicit opt-in
56
59
  - **Built-in rate limiting** — client-side token buckets respect Capital.com's 10 req/s global, 1 req/s session, and trading-burst limits
60
+ - **Session-token caching** — back-to-back commands reuse one login instead of re-authenticating (avoids HTTP 429); on by default, opt out with `CAP_PERSIST_SESSION=false`
61
+ - **Embeddable SDK (experimental)** — the same broker engine ships as an async Python library; see [Use as a library](#use-as-a-library-experimental)
57
62
 
58
63
  ## Installation
59
64
 
@@ -144,6 +149,7 @@ Main settings and their defaults:
144
149
  | `CAP_REQUIRE_EXPLICIT_CONFIRM` | `true` | Mutations need `--yes` |
145
150
  | `CAP_DRY_RUN` | `false` | Block all executions regardless of other flags |
146
151
  | `CAP_DEFAULT_ACCOUNT_ID` | (none) | Account selected after login |
152
+ | `CAP_PERSIST_SESSION` | `true` | Cache short-lived session tokens in the state file so back-to-back commands reuse one login (avoids HTTP 429); set `false` to keep tokens in-process only |
147
153
  | `CAP_HTTP_TIMEOUT_S` | `15` | HTTP timeout |
148
154
  | `CAP_LOG_LEVEL` | `WARNING` | `DEBUG` … `CRITICAL` |
149
155
  | `CAP_WS_ENABLED` | `false` | Required for `capctl stream …` |
@@ -243,9 +249,9 @@ capctl account topup 1000 --yes # demo environment only
243
249
  Read-only:
244
250
 
245
251
  ```bash
246
- capctl trade positions
252
+ capctl trade positions [--limit 10] # -n/--limit caps rows shown
247
253
  capctl trade position DEAL_ID
248
- capctl trade orders
254
+ capctl trade orders [--limit 10] # -n/--limit caps rows shown
249
255
  capctl trade confirm DEAL_REFERENCE [--wait --timeout 30]
250
256
  ```
251
257
 
@@ -1,3 +1,3 @@
1
1
  """Capital.com command-line client."""
2
2
 
3
- __version__ = "0.5.0"
3
+ __version__ = "0.5.1"
@@ -377,6 +377,10 @@ class RiskEngine:
377
377
  result.normalized_request["level"] = request.level
378
378
  if request.good_till_date:
379
379
  result.normalized_request["good_till_date"] = request.good_till_date
380
+ # preview_position already persisted this preview WITHOUT the working
381
+ # order fields; re-save so the CLI's separate execute-order process
382
+ # (which loads from the state file) sees type/level. (#working-order-exec)
383
+ self.state.save_preview(result)
380
384
 
381
385
  return result
382
386
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: capitalcom-cli
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Command-line client for the Capital.com Open API
5
5
  Author: Simon Tarara
6
6
  License: Apache-2.0
@@ -38,6 +38,7 @@ Browse markets, manage accounts and watchlists, preview and execute trades behin
38
38
  [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
39
39
  [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
40
40
  [![Release](https://img.shields.io/github/v/release/SimonTarara62/capitalcom-cli?sort=semver)](https://github.com/SimonTarara62/capitalcom-cli/releases)
41
+ [![API coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/SimonTarara62/capitalcom-cli/main/docs/coverage-badge.json)](docs/api-coverage.md)
41
42
 
42
43
  ```text
43
44
  $ capctl market search "gold"
@@ -70,9 +71,11 @@ See [practical use cases](docs/use-cases.md) for worked, copy-pasteable scenario
70
71
  tested broker engine is also embeddable as an **experimental** Python SDK — see
71
72
  [Use as a library](#use-as-a-library-experimental) and [docs/sdk.md](docs/sdk.md).
72
73
  The `capital_cli.core.*` internals remain private and may change between releases.
73
- The CLI itself is short-lived: each command runs as its own process and may create
74
- its own API session. `capctl session login` is mainly a connectivity/account check;
75
- session tokens are not persisted between separate invocations.
74
+ The CLI itself is short-lived: each command runs as its own process. By default
75
+ (`CAP_PERSIST_SESSION=true`) the short-lived session tokens are cached so
76
+ back-to-back commands reuse one login instead of re-authenticating each time
77
+ (which can trip Capital.com's login-rate limit and return HTTP 429); `capctl
78
+ session login` is mainly a connectivity/account check.
76
79
 
77
80
  ## Features
78
81
 
@@ -83,6 +86,8 @@ session tokens are not persisted between separate invocations.
83
86
  - **Real-time streaming** — live price tables, price-level alerts, and portfolio snapshots over WebSocket
84
87
  - **Demo and live environments** — defaults to demo; live requires explicit opt-in
85
88
  - **Built-in rate limiting** — client-side token buckets respect Capital.com's 10 req/s global, 1 req/s session, and trading-burst limits
89
+ - **Session-token caching** — back-to-back commands reuse one login instead of re-authenticating (avoids HTTP 429); on by default, opt out with `CAP_PERSIST_SESSION=false`
90
+ - **Embeddable SDK (experimental)** — the same broker engine ships as an async Python library; see [Use as a library](#use-as-a-library-experimental)
86
91
 
87
92
  ## Installation
88
93
 
@@ -173,6 +178,7 @@ Main settings and their defaults:
173
178
  | `CAP_REQUIRE_EXPLICIT_CONFIRM` | `true` | Mutations need `--yes` |
174
179
  | `CAP_DRY_RUN` | `false` | Block all executions regardless of other flags |
175
180
  | `CAP_DEFAULT_ACCOUNT_ID` | (none) | Account selected after login |
181
+ | `CAP_PERSIST_SESSION` | `true` | Cache short-lived session tokens in the state file so back-to-back commands reuse one login (avoids HTTP 429); set `false` to keep tokens in-process only |
176
182
  | `CAP_HTTP_TIMEOUT_S` | `15` | HTTP timeout |
177
183
  | `CAP_LOG_LEVEL` | `WARNING` | `DEBUG` … `CRITICAL` |
178
184
  | `CAP_WS_ENABLED` | `false` | Required for `capctl stream …` |
@@ -272,9 +278,9 @@ capctl account topup 1000 --yes # demo environment only
272
278
  Read-only:
273
279
 
274
280
  ```bash
275
- capctl trade positions
281
+ capctl trade positions [--limit 10] # -n/--limit caps rows shown
276
282
  capctl trade position DEAL_ID
277
- capctl trade orders
283
+ capctl trade orders [--limit 10] # -n/--limit caps rows shown
278
284
  capctl trade confirm DEAL_REFERENCE [--wait --timeout 30]
279
285
  ```
280
286
 
@@ -53,6 +53,7 @@ tests/test_build_broker_request.py
53
53
  tests/test_cli_usage_errors.py
54
54
  tests/test_config_errors.py
55
55
  tests/test_core_port.py
56
+ tests/test_coverage_doc_in_sync.py
56
57
  tests/test_credential_cmd.py
57
58
  tests/test_doctor.py
58
59
  tests/test_errors.py
@@ -0,0 +1,35 @@
1
+ """Assert the committed coverage matrix + badge match the registry renderer, so
2
+ docs/api-coverage.md and docs/coverage-badge.json can never silently rot."""
3
+
4
+ import json
5
+ from pathlib import Path
6
+
7
+ from tools.render_coverage import MARKER, render
8
+
9
+ REPO = Path(__file__).resolve().parents[1]
10
+
11
+
12
+ def test_matrix_table_in_sync():
13
+ table_md, _ = render()
14
+ # UTF-8 explicit: the matrix uses non-ASCII (— / − headers); the default
15
+ # encoding is cp1252 on Windows, which would mangle them and fail the compare.
16
+ committed = (REPO / "docs" / "api-coverage.md").read_text(encoding="utf-8")
17
+ assert MARKER in committed, "run: python tools/render_coverage.py"
18
+ assert committed.split(MARKER, 1)[1].strip() == table_md.split(MARKER, 1)[1].strip(), (
19
+ "docs/api-coverage.md is stale — run: python tools/render_coverage.py"
20
+ )
21
+
22
+
23
+ def test_badge_json_in_sync():
24
+ _, badge_json = render()
25
+ committed = (REPO / "docs" / "coverage-badge.json").read_text(encoding="utf-8")
26
+ assert json.loads(committed) == json.loads(badge_json), (
27
+ "docs/coverage-badge.json is stale — run: python tools/render_coverage.py"
28
+ )
29
+
30
+
31
+ def test_full_coverage_reached():
32
+ _, badge_json = render()
33
+ assert json.loads(badge_json)["message"].endswith("(100%)"), (
34
+ "coverage matrix is not 100% — fill remaining cells"
35
+ )
@@ -232,3 +232,51 @@ def test_validate_size_guards_non_positive_increment():
232
232
  assert check.passed is True
233
233
  effective, check = engine._validate_size(1.0, 0.1, 1000.0, -1.0, auto_normalize=False)
234
234
  assert check.passed is True
235
+
236
+
237
+ async def test_working_order_preview_persists_type_level_to_state_file(tmp_path):
238
+ """A passing working-order preview must persist type/level to the state file.
239
+
240
+ The CLI's `trade execute-order` runs in a separate process that loads the
241
+ preview from the state file. Regression for the `'type'` KeyError raised when
242
+ the working-order fields were only mutated in-memory and never re-saved.
243
+ """
244
+ from capital_cli.core.config import get_config
245
+ from capital_cli.core.models import Direction, PreviewWorkingOrderRequest, WorkingOrderType
246
+ from capital_cli.core.state import StateStore
247
+ from capital_cli.services.confirmations import build_broker_request
248
+
249
+ cfg = get_config()
250
+ cfg.cap_allow_trading = True
251
+ cfg.cap_allowed_epics = "ALL"
252
+ cfg.cap_max_position_size = 100.0
253
+ cfg.cap_max_working_order_size = 100.0
254
+ try:
255
+ engine = RiskEngine()
256
+ # Real temp-file-backed state store so save/load round-trips through JSON.
257
+ engine.state = StateStore(path=tmp_path / "state.json")
258
+ _arm_market_details(engine)
259
+ request = PreviewWorkingOrderRequest(
260
+ epic="GOLD",
261
+ direction=Direction.BUY,
262
+ type=WorkingOrderType.LIMIT,
263
+ level=1900.0, # far from market (bid 2000 / offer 2001)
264
+ size=0.5,
265
+ )
266
+ result = await engine.preview_working_order(request)
267
+ assert result.all_checks_passed is True
268
+
269
+ # Simulate a fresh process: drop the in-memory cache so we load from disk.
270
+ engine._preview_cache.clear()
271
+ reloaded = engine.get_preview(result.preview_id)
272
+
273
+ assert reloaded.normalized_request.get("type") == "LIMIT"
274
+ assert "level" in reloaded.normalized_request
275
+
276
+ body = build_broker_request(reloaded.normalized_request, include_order_fields=True)
277
+ assert body["type"] == "LIMIT"
278
+ finally:
279
+ cfg.cap_allow_trading = False
280
+ cfg.cap_allowed_epics = ""
281
+ cfg.cap_max_position_size = 1.0
282
+ cfg.cap_max_working_order_size = 1.0
File without changes
File without changes
File without changes