capitalcom-cli 0.5.1__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 (84) hide show
  1. {capitalcom_cli-0.5.1/capitalcom_cli.egg-info → capitalcom_cli-0.6.0}/PKG-INFO +14 -11
  2. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/README.md +13 -10
  3. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/__init__.py +1 -1
  4. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/session_cmds.py +3 -10
  5. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/session.py +17 -0
  6. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/sdk/__init__.py +1 -1
  7. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/sdk/app.py +3 -3
  8. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/sdk/config.py +1 -1
  9. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0/capitalcom_cli.egg-info}/PKG-INFO +14 -11
  10. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capitalcom_cli.egg-info/SOURCES.txt +1 -0
  11. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_session_cmds.py +15 -21
  12. capitalcom_cli-0.6.0/tests/test_session_reads.py +83 -0
  13. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/LICENSE +0 -0
  14. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/NOTICE +0 -0
  15. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/__main__.py +0 -0
  16. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/__init__.py +0 -0
  17. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/account_cmds.py +0 -0
  18. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/app.py +0 -0
  19. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/context.py +0 -0
  20. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/doctor_cmds.py +0 -0
  21. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/live_guard.py +0 -0
  22. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/market_cmds.py +0 -0
  23. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/output.py +0 -0
  24. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/runner.py +0 -0
  25. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/stream_cmds.py +0 -0
  26. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/trade_cmds.py +0 -0
  27. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/cli/watchlist_cmds.py +0 -0
  28. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/__init__.py +0 -0
  29. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/audit.py +0 -0
  30. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/config.py +0 -0
  31. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/errors.py +0 -0
  32. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/http_client.py +0 -0
  33. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/models.py +0 -0
  34. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/rate_limit.py +0 -0
  35. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/risk.py +0 -0
  36. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/state.py +0 -0
  37. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/utils.py +0 -0
  38. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/core/websocket_client.py +0 -0
  39. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/sdk/risk_policy.py +0 -0
  40. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/services/__init__.py +0 -0
  41. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/services/accounts.py +0 -0
  42. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/services/confirmations.py +0 -0
  43. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/services/markets.py +0 -0
  44. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/services/streaming.py +0 -0
  45. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/services/trading.py +0 -0
  46. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capital_cli/services/watchlists.py +0 -0
  47. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capitalcom_cli.egg-info/dependency_links.txt +0 -0
  48. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capitalcom_cli.egg-info/entry_points.txt +0 -0
  49. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capitalcom_cli.egg-info/requires.txt +0 -0
  50. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/capitalcom_cli.egg-info/top_level.txt +0 -0
  51. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/pyproject.toml +0 -0
  52. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/setup.cfg +0 -0
  53. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_account_cmds.py +0 -0
  54. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_app.py +0 -0
  55. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_audit.py +0 -0
  56. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_build_broker_request.py +0 -0
  57. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_cli_usage_errors.py +0 -0
  58. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_config_errors.py +0 -0
  59. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_core_port.py +0 -0
  60. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_coverage_doc_in_sync.py +0 -0
  61. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_credential_cmd.py +0 -0
  62. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_doctor.py +0 -0
  63. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_errors.py +0 -0
  64. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_global_flag_hoist.py +0 -0
  65. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_http_client.py +0 -0
  66. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_init_state_singletons.py +0 -0
  67. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_live_guard.py +0 -0
  68. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_market_cmds.py +0 -0
  69. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_output.py +0 -0
  70. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_output_color.py +0 -0
  71. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_output_plain.py +0 -0
  72. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_redaction.py +0 -0
  73. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_risk.py +0 -0
  74. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_runner.py +0 -0
  75. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_session_persistence.py +0 -0
  76. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_state.py +0 -0
  77. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_stream_cmds.py +0 -0
  78. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_trade_cmds.py +0 -0
  79. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_trade_limit.py +0 -0
  80. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_tz_datetimes.py +0 -0
  81. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_utils.py +0 -0
  82. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_version.py +0 -0
  83. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/tests/test_watchlist_cmds.py +0 -0
  84. {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.0}/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.1
3
+ Version: 0.6.0
4
4
  Summary: Command-line client for the Capital.com Open API
5
5
  Author: Simon Tarara
6
6
  License: Apache-2.0
@@ -38,7 +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
+ [![CLI + SDK coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/SimonTarara62/capitalcom-cli/main/docs/coverage-badge.json)](docs/api-coverage.md)
42
42
 
43
43
  ```text
44
44
  $ capctl market search "gold"
@@ -68,8 +68,8 @@ The Capital.com web platform is built for clicking; `capctl` is built for **repe
68
68
  See [practical use cases](docs/use-cases.md) for worked, copy-pasteable scenarios.
69
69
 
70
70
  **Scope:** `capctl` is first and foremost a command-line application, but the same
71
- tested broker engine is also embeddable as an **experimental** Python SDK — see
72
- [Use as a library](#use-as-a-library-experimental) and [docs/sdk.md](docs/sdk.md).
71
+ tested broker engine is also embeddable as a Python SDK — see
72
+ [Use as a library](#use-as-a-library) and [docs/sdk.md](docs/sdk.md).
73
73
  The `capital_cli.core.*` internals remain private and may change between releases.
74
74
  The CLI itself is short-lived: each command runs as its own process. By default
75
75
  (`CAP_PERSIST_SESSION=true`) the short-lived session tokens are cached so
@@ -79,7 +79,7 @@ session login` is mainly a connectivity/account check.
79
79
 
80
80
  ## Features
81
81
 
82
- - **Six command groups** covering the main Capital.com Open API workflows — `session`, `market`, `account`, `trade`, `watchlist`, `stream` (see the [API coverage table](docs/api-coverage.md))
82
+ - **Six command groups** covering the **full** Capital.com Open API surface — `session`, `market`, `account`, `trade`, `watchlist`, `stream` — verified by an automated [coverage matrix](docs/api-coverage.md)
83
83
  - **Safety-first trading** — trading is off by default; enabling it requires an explicit EPIC allowlist, every execution goes through a two-phase *preview → execute* flow with risk checks, and mutating commands require `--yes`
84
84
  - **`--json` everywhere** — every command can emit raw JSON for piping into `jq`, scripts, or CI jobs
85
85
  - **Distinct exit codes per failure class** — scripts can branch on *why* a command failed (auth vs. risk-block vs. upstream error)
@@ -87,7 +87,7 @@ session login` is mainly a connectivity/account check.
87
87
  - **Demo and live environments** — defaults to demo; live requires explicit opt-in
88
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
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)
90
+ - **Embeddable SDK** — the same broker engine ships as an async Python library with a stable 0.x surface; see [Use as a library](#use-as-a-library)
91
91
 
92
92
  ## Installation
93
93
 
@@ -396,7 +396,7 @@ capctl stream alerts BTCUSD 75000 --direction ABOVE --duration 3600
396
396
  */15 * * * * capctl --json trade positions >> ~/logs/positions.jsonl 2>&1
397
397
  ```
398
398
 
399
- ## Use as a library (experimental)
399
+ ## Use as a library
400
400
 
401
401
  Beyond the CLI, the same broker engine — risk policy, two-phase preview→execute,
402
402
  rate limiting, WebSocket streaming — is available as an embeddable async SDK.
@@ -419,9 +419,12 @@ async def main():
419
419
  asyncio.run(main())
420
420
  ```
421
421
 
422
- The SDK is **experimental** until 1.0: import paths and the pydantic models are
423
- intended-stable but may shift between 0.x minors. See [docs/sdk.md](docs/sdk.md)
424
- for read-only, preview→execute, streaming, and risk-policy examples.
422
+ **Stability:** the documented SDK surface — `CapitalComApp`, `CapitalComConfig`,
423
+ `RiskPolicy`, the service classes, and the `capital_cli.core.models` pydantic
424
+ models — is **stable**: no breaking changes within the 0.x series without a
425
+ deprecation cycle; breaking changes are reserved for a future 1.0. The
426
+ `capital_cli.core.*` internals remain private. See [docs/sdk.md](docs/sdk.md) for
427
+ read-only, preview→execute, streaming, and risk-policy examples.
425
428
 
426
429
  ## Exit codes
427
430
 
@@ -488,7 +491,7 @@ Or use the task runner: `make check` (lint + typecheck + test), `make docs`, `ma
488
491
  ## Documentation
489
492
 
490
493
  - [Full CLI reference](docs/CLI.md) — every command and option (auto-generated)
491
- - [Using capctl as a Python SDK](docs/sdk.md) — experimental async SDK, import paths, examples, versioning
494
+ - [Using capctl as a Python SDK](docs/sdk.md) — stable async SDK, import paths, examples, versioning
492
495
  - [Scripting & automation](docs/scripting.md) — CI credentials, exit codes, jq recipes
493
496
  - [Getting started from zero](docs/getting-started.md) — account, API key, install, first trade
494
497
  - [Practical use cases](docs/use-cases.md) — what people actually do with capctl, with copy-pasteable scenarios
@@ -9,7 +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
+ [![CLI + SDK coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/SimonTarara62/capitalcom-cli/main/docs/coverage-badge.json)](docs/api-coverage.md)
13
13
 
14
14
  ```text
15
15
  $ capctl market search "gold"
@@ -39,8 +39,8 @@ The Capital.com web platform is built for clicking; `capctl` is built for **repe
39
39
  See [practical use cases](docs/use-cases.md) for worked, copy-pasteable scenarios.
40
40
 
41
41
  **Scope:** `capctl` is first and foremost a command-line application, but the same
42
- tested broker engine is also embeddable as an **experimental** Python SDK — see
43
- [Use as a library](#use-as-a-library-experimental) and [docs/sdk.md](docs/sdk.md).
42
+ tested broker engine is also embeddable as a Python SDK — see
43
+ [Use as a library](#use-as-a-library) and [docs/sdk.md](docs/sdk.md).
44
44
  The `capital_cli.core.*` internals remain private and may change between releases.
45
45
  The CLI itself is short-lived: each command runs as its own process. By default
46
46
  (`CAP_PERSIST_SESSION=true`) the short-lived session tokens are cached so
@@ -50,7 +50,7 @@ session login` is mainly a connectivity/account check.
50
50
 
51
51
  ## Features
52
52
 
53
- - **Six command groups** covering the main Capital.com Open API workflows — `session`, `market`, `account`, `trade`, `watchlist`, `stream` (see the [API coverage table](docs/api-coverage.md))
53
+ - **Six command groups** covering the **full** Capital.com Open API surface — `session`, `market`, `account`, `trade`, `watchlist`, `stream` — verified by an automated [coverage matrix](docs/api-coverage.md)
54
54
  - **Safety-first trading** — trading is off by default; enabling it requires an explicit EPIC allowlist, every execution goes through a two-phase *preview → execute* flow with risk checks, and mutating commands require `--yes`
55
55
  - **`--json` everywhere** — every command can emit raw JSON for piping into `jq`, scripts, or CI jobs
56
56
  - **Distinct exit codes per failure class** — scripts can branch on *why* a command failed (auth vs. risk-block vs. upstream error)
@@ -58,7 +58,7 @@ session login` is mainly a connectivity/account check.
58
58
  - **Demo and live environments** — defaults to demo; live requires explicit opt-in
59
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
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)
61
+ - **Embeddable SDK** — the same broker engine ships as an async Python library with a stable 0.x surface; see [Use as a library](#use-as-a-library)
62
62
 
63
63
  ## Installation
64
64
 
@@ -367,7 +367,7 @@ capctl stream alerts BTCUSD 75000 --direction ABOVE --duration 3600
367
367
  */15 * * * * capctl --json trade positions >> ~/logs/positions.jsonl 2>&1
368
368
  ```
369
369
 
370
- ## Use as a library (experimental)
370
+ ## Use as a library
371
371
 
372
372
  Beyond the CLI, the same broker engine — risk policy, two-phase preview→execute,
373
373
  rate limiting, WebSocket streaming — is available as an embeddable async SDK.
@@ -390,9 +390,12 @@ async def main():
390
390
  asyncio.run(main())
391
391
  ```
392
392
 
393
- The SDK is **experimental** until 1.0: import paths and the pydantic models are
394
- intended-stable but may shift between 0.x minors. See [docs/sdk.md](docs/sdk.md)
395
- for read-only, preview→execute, streaming, and risk-policy examples.
393
+ **Stability:** the documented SDK surface — `CapitalComApp`, `CapitalComConfig`,
394
+ `RiskPolicy`, the service classes, and the `capital_cli.core.models` pydantic
395
+ models — is **stable**: no breaking changes within the 0.x series without a
396
+ deprecation cycle; breaking changes are reserved for a future 1.0. The
397
+ `capital_cli.core.*` internals remain private. See [docs/sdk.md](docs/sdk.md) for
398
+ read-only, preview→execute, streaming, and risk-policy examples.
396
399
 
397
400
  ## Exit codes
398
401
 
@@ -459,7 +462,7 @@ Or use the task runner: `make check` (lint + typecheck + test), `make docs`, `ma
459
462
  ## Documentation
460
463
 
461
464
  - [Full CLI reference](docs/CLI.md) — every command and option (auto-generated)
462
- - [Using capctl as a Python SDK](docs/sdk.md) — experimental async SDK, import paths, examples, versioning
465
+ - [Using capctl as a Python SDK](docs/sdk.md) — stable async SDK, import paths, examples, versioning
463
466
  - [Scripting & automation](docs/scripting.md) — CI credentials, exit codes, jq recipes
464
467
  - [Getting started from zero](docs/getting-started.md) — account, API key, install, first trade
465
468
  - [Practical use cases](docs/use-cases.md) — what people actually do with capctl, with copy-pasteable scenarios
@@ -1,3 +1,3 @@
1
1
  """Capital.com command-line client."""
2
2
 
3
- __version__ = "0.5.1"
3
+ __version__ = "0.6.0"
@@ -7,7 +7,6 @@ from typing import Any
7
7
  import typer
8
8
 
9
9
  from capital_cli.cli.runner import run
10
- from capital_cli.core.http_client import get_client
11
10
  from capital_cli.core.session import get_session_manager
12
11
 
13
12
  app = typer.Typer(no_args_is_help=True, help="Session lifecycle: login, ping, logout.")
@@ -98,9 +97,7 @@ def time(ctx: typer.Context) -> None:
98
97
  out = ctx.obj.out
99
98
 
100
99
  async def _do() -> dict[str, Any]:
101
- client = get_client()
102
- data = (await client.get("/time")).json()
103
- return data if isinstance(data, dict) else {"serverTime": data}
100
+ return await get_session_manager().server_time()
104
101
 
105
102
  out.record(run(out, _do, label="session time"), title="Server time")
106
103
 
@@ -111,10 +108,7 @@ def details(ctx: typer.Context) -> None:
111
108
  out = ctx.obj.out
112
109
 
113
110
  async def _do() -> dict[str, Any]:
114
- sm = get_session_manager()
115
- client = get_client()
116
- await sm.ensure_logged_in()
117
- return (await client.get("/session")).json()
111
+ return await get_session_manager().details()
118
112
 
119
113
  out.record(run(out, _do, label="session details"), title="Session details")
120
114
 
@@ -125,7 +119,6 @@ def encryption_key(ctx: typer.Context) -> None:
125
119
  out = ctx.obj.out
126
120
 
127
121
  async def _do() -> dict[str, Any]:
128
- client = get_client()
129
- return (await client.get("/session/encryptionKey")).json()
122
+ return await get_session_manager().encryption_key()
130
123
 
131
124
  out.record(run(out, _do, label="session encryption-key"), title="Encryption key")
@@ -187,6 +187,23 @@ class SessionManager:
187
187
  response = await self.client.get("/ping")
188
188
  return response.json() if response.text else {"status": "ok"}
189
189
 
190
+ async def server_time(self) -> dict[str, Any]:
191
+ """Return the broker's current server time. No authentication required."""
192
+ response = await self.client.get("/time")
193
+ data = response.json() if response.text else {}
194
+ return data if isinstance(data, dict) else {"serverTime": data}
195
+
196
+ async def details(self) -> dict[str, Any]:
197
+ """Return server-side session details (client id, account id, currency, timezone)."""
198
+ await self.ensure_logged_in()
199
+ response = await self.client.get("/session")
200
+ return response.json() if response.text else {}
201
+
202
+ async def encryption_key(self) -> dict[str, Any]:
203
+ """Fetch the API encryption key and timestamp (encrypted-password login)."""
204
+ response = await self.client.get("/session/encryptionKey")
205
+ return response.json() if response.text else {}
206
+
190
207
  async def logout(self) -> None:
191
208
  """End session and clear tokens."""
192
209
  if not self.tokens:
@@ -1,4 +1,4 @@
1
- """Capital.com SDK — experimental public API (paths/models stable from 1.0).
1
+ """Capital.com SDK — public API, stable within 0.x (frozen at 1.0).
2
2
 
3
3
  from capital_cli.sdk import CapitalComApp, CapitalComConfig, RiskPolicy
4
4
  """
@@ -1,8 +1,8 @@
1
1
  """CapitalComApp — the SDK facade wiring config + services + risk policy.
2
2
 
3
- EXPERIMENTAL (0.x): one app per process. The underlying services use
4
- process-global singletons, so constructing a second CapitalComApp with a
5
- different config in the same process is not supported yet.
3
+ Note (0.x): one app per process. The underlying services use process-global
4
+ singletons, so constructing a second CapitalComApp with a different config in the
5
+ same process is not supported yet.
6
6
  """
7
7
 
8
8
  from __future__ import annotations
@@ -1,4 +1,4 @@
1
- """Public configuration type for the Capital.com SDK (experimental until 1.0)."""
1
+ """Public configuration type for the Capital.com SDK (stable within 0.x)."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: capitalcom-cli
3
- Version: 0.5.1
3
+ Version: 0.6.0
4
4
  Summary: Command-line client for the Capital.com Open API
5
5
  Author: Simon Tarara
6
6
  License: Apache-2.0
@@ -38,7 +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
+ [![CLI + SDK coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/SimonTarara62/capitalcom-cli/main/docs/coverage-badge.json)](docs/api-coverage.md)
42
42
 
43
43
  ```text
44
44
  $ capctl market search "gold"
@@ -68,8 +68,8 @@ The Capital.com web platform is built for clicking; `capctl` is built for **repe
68
68
  See [practical use cases](docs/use-cases.md) for worked, copy-pasteable scenarios.
69
69
 
70
70
  **Scope:** `capctl` is first and foremost a command-line application, but the same
71
- tested broker engine is also embeddable as an **experimental** Python SDK — see
72
- [Use as a library](#use-as-a-library-experimental) and [docs/sdk.md](docs/sdk.md).
71
+ tested broker engine is also embeddable as a Python SDK — see
72
+ [Use as a library](#use-as-a-library) and [docs/sdk.md](docs/sdk.md).
73
73
  The `capital_cli.core.*` internals remain private and may change between releases.
74
74
  The CLI itself is short-lived: each command runs as its own process. By default
75
75
  (`CAP_PERSIST_SESSION=true`) the short-lived session tokens are cached so
@@ -79,7 +79,7 @@ session login` is mainly a connectivity/account check.
79
79
 
80
80
  ## Features
81
81
 
82
- - **Six command groups** covering the main Capital.com Open API workflows — `session`, `market`, `account`, `trade`, `watchlist`, `stream` (see the [API coverage table](docs/api-coverage.md))
82
+ - **Six command groups** covering the **full** Capital.com Open API surface — `session`, `market`, `account`, `trade`, `watchlist`, `stream` — verified by an automated [coverage matrix](docs/api-coverage.md)
83
83
  - **Safety-first trading** — trading is off by default; enabling it requires an explicit EPIC allowlist, every execution goes through a two-phase *preview → execute* flow with risk checks, and mutating commands require `--yes`
84
84
  - **`--json` everywhere** — every command can emit raw JSON for piping into `jq`, scripts, or CI jobs
85
85
  - **Distinct exit codes per failure class** — scripts can branch on *why* a command failed (auth vs. risk-block vs. upstream error)
@@ -87,7 +87,7 @@ session login` is mainly a connectivity/account check.
87
87
  - **Demo and live environments** — defaults to demo; live requires explicit opt-in
88
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
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)
90
+ - **Embeddable SDK** — the same broker engine ships as an async Python library with a stable 0.x surface; see [Use as a library](#use-as-a-library)
91
91
 
92
92
  ## Installation
93
93
 
@@ -396,7 +396,7 @@ capctl stream alerts BTCUSD 75000 --direction ABOVE --duration 3600
396
396
  */15 * * * * capctl --json trade positions >> ~/logs/positions.jsonl 2>&1
397
397
  ```
398
398
 
399
- ## Use as a library (experimental)
399
+ ## Use as a library
400
400
 
401
401
  Beyond the CLI, the same broker engine — risk policy, two-phase preview→execute,
402
402
  rate limiting, WebSocket streaming — is available as an embeddable async SDK.
@@ -419,9 +419,12 @@ async def main():
419
419
  asyncio.run(main())
420
420
  ```
421
421
 
422
- The SDK is **experimental** until 1.0: import paths and the pydantic models are
423
- intended-stable but may shift between 0.x minors. See [docs/sdk.md](docs/sdk.md)
424
- for read-only, preview→execute, streaming, and risk-policy examples.
422
+ **Stability:** the documented SDK surface — `CapitalComApp`, `CapitalComConfig`,
423
+ `RiskPolicy`, the service classes, and the `capital_cli.core.models` pydantic
424
+ models — is **stable**: no breaking changes within the 0.x series without a
425
+ deprecation cycle; breaking changes are reserved for a future 1.0. The
426
+ `capital_cli.core.*` internals remain private. See [docs/sdk.md](docs/sdk.md) for
427
+ read-only, preview→execute, streaming, and risk-policy examples.
425
428
 
426
429
  ## Exit codes
427
430
 
@@ -488,7 +491,7 @@ Or use the task runner: `make check` (lint + typecheck + test), `make docs`, `ma
488
491
  ## Documentation
489
492
 
490
493
  - [Full CLI reference](docs/CLI.md) — every command and option (auto-generated)
491
- - [Using capctl as a Python SDK](docs/sdk.md) — experimental async SDK, import paths, examples, versioning
494
+ - [Using capctl as a Python SDK](docs/sdk.md) — stable async SDK, import paths, examples, versioning
492
495
  - [Scripting & automation](docs/scripting.md) — CI credentials, exit codes, jq recipes
493
496
  - [Getting started from zero](docs/getting-started.md) — account, API key, install, first trade
494
497
  - [Practical use cases](docs/use-cases.md) — what people actually do with capctl, with copy-pasteable scenarios
@@ -70,6 +70,7 @@ tests/test_risk.py
70
70
  tests/test_runner.py
71
71
  tests/test_session_cmds.py
72
72
  tests/test_session_persistence.py
73
+ tests/test_session_reads.py
73
74
  tests/test_state.py
74
75
  tests/test_stream_cmds.py
75
76
  tests/test_trade_cmds.py
@@ -45,44 +45,38 @@ def test_switch(runner, mock_session):
45
45
 
46
46
  @pytest.fixture
47
47
  def mock_session_client(monkeypatch):
48
- """Patch get_client (and get_session_manager) used by the new session commands."""
48
+ """Patch the SessionManager read methods backing the session commands.
49
+
50
+ The CLI now delegates to ``get_session_manager().server_time()`` etc. rather
51
+ than calling the HTTP client inline, so we stub those passthroughs.
52
+ """
49
53
  sm = MagicMock()
50
54
  sm.ensure_logged_in = AsyncMock()
55
+ sm.server_time = AsyncMock(return_value={})
56
+ sm.details = AsyncMock(return_value={})
57
+ sm.encryption_key = AsyncMock(return_value={})
51
58
  monkeypatch.setattr("capital_cli.cli.session_cmds.get_session_manager", lambda: sm)
52
-
53
- client = MagicMock()
54
- resp = MagicMock()
55
- resp.json = MagicMock(return_value={})
56
- client.get = AsyncMock(return_value=resp)
57
- monkeypatch.setattr("capital_cli.cli.session_cmds.get_client", lambda: client)
58
- return client
59
+ return sm
59
60
 
60
61
 
61
62
  def test_time(runner, mock_session_client):
62
- mock_session_client.get.return_value.json.return_value = {"serverTime": 1700000000000}
63
- result = runner.invoke(app, ["--json", "session", "time"])
64
- assert result.exit_code == 0
65
- assert json.loads(result.stdout)["serverTime"] == 1700000000000
66
- assert mock_session_client.get.await_args.args[0] == "/time"
67
-
68
-
69
- def test_time_wraps_bare_value(runner, mock_session_client):
70
- mock_session_client.get.return_value.json.return_value = 1700000000000
63
+ mock_session_client.server_time.return_value = {"serverTime": 1700000000000}
71
64
  result = runner.invoke(app, ["--json", "session", "time"])
72
65
  assert result.exit_code == 0
73
66
  assert json.loads(result.stdout)["serverTime"] == 1700000000000
67
+ mock_session_client.server_time.assert_awaited_once()
74
68
 
75
69
 
76
70
  def test_details(runner, mock_session_client):
77
- mock_session_client.get.return_value.json.return_value = {"clientId": "C1", "accountId": "A1"}
71
+ mock_session_client.details.return_value = {"clientId": "C1", "accountId": "A1"}
78
72
  result = runner.invoke(app, ["--json", "session", "details"])
79
73
  assert result.exit_code == 0
80
74
  assert json.loads(result.stdout)["clientId"] == "C1"
81
- assert mock_session_client.get.await_args.args[0] == "/session"
75
+ mock_session_client.details.assert_awaited_once()
82
76
 
83
77
 
84
78
  def test_encryption_key(runner, mock_session_client):
85
- mock_session_client.get.return_value.json.return_value = {"encryptionKey": "K", "timeStamp": 1}
79
+ mock_session_client.encryption_key.return_value = {"encryptionKey": "K", "timeStamp": 1}
86
80
  result = runner.invoke(app, ["session", "encryption-key"])
87
81
  assert result.exit_code == 0
88
- assert mock_session_client.get.await_args.args[0] == "/session/encryptionKey"
82
+ mock_session_client.encryption_key.assert_awaited_once()
@@ -0,0 +1,83 @@
1
+ """Unit tests for the SessionManager read passthroughs (server_time / details /
2
+ encryption_key) that back both the CLI session commands and the SDK."""
3
+
4
+ import asyncio
5
+
6
+ import pytest
7
+
8
+
9
+ @pytest.fixture
10
+ def _demo_env(monkeypatch):
11
+ monkeypatch.setenv("CAP_ENV", "demo")
12
+ monkeypatch.setenv("CAP_API_KEY", "k")
13
+ monkeypatch.setenv("CAP_IDENTIFIER", "id@example.com")
14
+ monkeypatch.setenv("CAP_API_PASSWORD", "pw")
15
+ from capital_cli.core.config import reset_config
16
+
17
+ reset_config()
18
+ yield
19
+ from capital_cli.core.config import reset_config as _rc
20
+
21
+ _rc()
22
+
23
+
24
+ class _FakeResp:
25
+ def __init__(self, payload):
26
+ self._payload = payload
27
+ self.text = "x"
28
+
29
+ def json(self):
30
+ return self._payload
31
+
32
+
33
+ class _FakeClient:
34
+ def __init__(self, payload):
35
+ self._payload = payload
36
+ self.path = None
37
+
38
+ def set_relogin(self, *_a):
39
+ pass
40
+
41
+ async def get(self, path):
42
+ self.path = path
43
+ return _FakeResp(self._payload)
44
+
45
+
46
+ def _make_sm(payload):
47
+ from capital_cli.core.session import SessionManager
48
+
49
+ sm = SessionManager()
50
+ sm.client = _FakeClient(payload)
51
+ return sm
52
+
53
+
54
+ def test_server_time_hits_time_endpoint(_demo_env):
55
+ sm = _make_sm({"serverTime": "2026-06-14T00:00:00"})
56
+ out = asyncio.run(sm.server_time())
57
+ assert sm.client.path == "/time"
58
+ assert out == {"serverTime": "2026-06-14T00:00:00"}
59
+
60
+
61
+ def test_server_time_wraps_bare_value(_demo_env):
62
+ sm = _make_sm(1700000000000)
63
+ out = asyncio.run(sm.server_time())
64
+ assert out == {"serverTime": 1700000000000}
65
+
66
+
67
+ def test_encryption_key_hits_endpoint(_demo_env):
68
+ sm = _make_sm({"encryptionKey": "abc", "timeStamp": 1})
69
+ out = asyncio.run(sm.encryption_key())
70
+ assert sm.client.path == "/session/encryptionKey"
71
+ assert out["encryptionKey"] == "abc"
72
+
73
+
74
+ def test_details_logs_in_then_hits_session(_demo_env, monkeypatch):
75
+ sm = _make_sm({"clientId": "c", "accountId": "a"})
76
+
77
+ async def _noop():
78
+ return None
79
+
80
+ monkeypatch.setattr(sm, "ensure_logged_in", _noop)
81
+ out = asyncio.run(sm.details())
82
+ assert sm.client.path == "/session"
83
+ assert out["accountId"] == "a"
File without changes
File without changes
File without changes