capitalcom-cli 0.5.1__tar.gz → 0.6.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.
- {capitalcom_cli-0.5.1/capitalcom_cli.egg-info → capitalcom_cli-0.6.1}/PKG-INFO +17 -14
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/README.md +15 -12
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/__init__.py +1 -1
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/app.py +1 -1
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/session_cmds.py +3 -10
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/session.py +17 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/sdk/__init__.py +1 -1
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/sdk/app.py +3 -3
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/sdk/config.py +1 -1
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1/capitalcom_cli.egg-info}/PKG-INFO +17 -14
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capitalcom_cli.egg-info/SOURCES.txt +1 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/pyproject.toml +1 -1
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_session_cmds.py +15 -21
- capitalcom_cli-0.6.1/tests/test_session_reads.py +83 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/LICENSE +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/NOTICE +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/__main__.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/__init__.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/account_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/context.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/doctor_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/live_guard.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/market_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/output.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/runner.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/stream_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/trade_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/cli/watchlist_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/__init__.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/audit.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/config.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/errors.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/http_client.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/models.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/rate_limit.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/risk.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/state.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/utils.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/core/websocket_client.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/sdk/risk_policy.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/services/__init__.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/services/accounts.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/services/confirmations.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/services/markets.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/services/streaming.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/services/trading.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capital_cli/services/watchlists.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capitalcom_cli.egg-info/dependency_links.txt +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capitalcom_cli.egg-info/entry_points.txt +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capitalcom_cli.egg-info/requires.txt +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/capitalcom_cli.egg-info/top_level.txt +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/setup.cfg +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_account_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_app.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_audit.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_build_broker_request.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_cli_usage_errors.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_config_errors.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_core_port.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_coverage_doc_in_sync.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_credential_cmd.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_doctor.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_errors.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_global_flag_hoist.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_http_client.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_init_state_singletons.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_live_guard.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_market_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_output.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_output_color.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_output_plain.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_redaction.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_risk.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_runner.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_session_persistence.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_state.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_stream_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_trade_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_trade_limit.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_tz_datetimes.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_utils.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_version.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_watchlist_cmds.py +0 -0
- {capitalcom_cli-0.5.1 → capitalcom_cli-0.6.1}/tests/test_websocket_parsing.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: capitalcom-cli
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.6.1
|
|
4
|
+
Summary: Unofficial command-line client for the Capital.com Open API
|
|
5
5
|
Author: Simon Tarara
|
|
6
6
|
License: Apache-2.0
|
|
7
7
|
Project-URL: Homepage, https://github.com/SimonTarara62/capitalcom-cli
|
|
@@ -27,9 +27,9 @@ Requires-Dist: mypy>=1.9.0; extra == "dev"
|
|
|
27
27
|
Requires-Dist: build>=1.2.0; extra == "dev"
|
|
28
28
|
Dynamic: license-file
|
|
29
29
|
|
|
30
|
-
# capctl — Capital.com CLI
|
|
30
|
+
# capctl — unofficial Capital.com CLI
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
An **unofficial**, fast, scriptable command-line client for the [Capital.com](https://capital.com) Open API, built with Typer and Rich. Independent project — not affiliated with or endorsed by Capital.com.
|
|
33
33
|
|
|
34
34
|
Browse markets, manage accounts and watchlists, preview and execute trades behind multiple safety guardrails, and stream real-time prices — from your terminal, in human-readable tables or raw JSON for automation.
|
|
35
35
|
|
|
@@ -38,7 +38,7 @@ Browse markets, manage accounts and watchlists, preview and execute trades behin
|
|
|
38
38
|
[](LICENSE)
|
|
39
39
|
[](https://www.python.org/downloads/)
|
|
40
40
|
[](https://github.com/SimonTarara62/capitalcom-cli/releases)
|
|
41
|
-
[](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
|
|
72
|
-
[Use as a library](#use-as-a-library
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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) —
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# capctl — Capital.com CLI
|
|
1
|
+
# capctl — unofficial Capital.com CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An **unofficial**, fast, scriptable command-line client for the [Capital.com](https://capital.com) Open API, built with Typer and Rich. Independent project — not affiliated with or endorsed by Capital.com.
|
|
4
4
|
|
|
5
5
|
Browse markets, manage accounts and watchlists, preview and execute trades behind multiple safety guardrails, and stream real-time prices — from your terminal, in human-readable tables or raw JSON for automation.
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ Browse markets, manage accounts and watchlists, preview and execute trades behin
|
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
[](https://www.python.org/downloads/)
|
|
11
11
|
[](https://github.com/SimonTarara62/capitalcom-cli/releases)
|
|
12
|
-
[](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
|
|
43
|
-
[Use as a library](#use-as-a-library
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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) —
|
|
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
|
|
@@ -23,7 +23,7 @@ from capital_cli.cli.context import init_state
|
|
|
23
23
|
app = typer.Typer(
|
|
24
24
|
no_args_is_help=True,
|
|
25
25
|
add_completion=True,
|
|
26
|
-
help="capctl — command-line client for the Capital.com Open API.",
|
|
26
|
+
help="capctl — unofficial command-line client for the Capital.com Open API (not affiliated with Capital.com).",
|
|
27
27
|
epilog=(
|
|
28
28
|
"Getting started:\n"
|
|
29
29
|
" capctl doctor # check env, credentials, and trading status\n"
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,8 +1,8 @@
|
|
|
1
1
|
"""CapitalComApp — the SDK facade wiring config + services + risk policy.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: capitalcom-cli
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.6.1
|
|
4
|
+
Summary: Unofficial command-line client for the Capital.com Open API
|
|
5
5
|
Author: Simon Tarara
|
|
6
6
|
License: Apache-2.0
|
|
7
7
|
Project-URL: Homepage, https://github.com/SimonTarara62/capitalcom-cli
|
|
@@ -27,9 +27,9 @@ Requires-Dist: mypy>=1.9.0; extra == "dev"
|
|
|
27
27
|
Requires-Dist: build>=1.2.0; extra == "dev"
|
|
28
28
|
Dynamic: license-file
|
|
29
29
|
|
|
30
|
-
# capctl — Capital.com CLI
|
|
30
|
+
# capctl — unofficial Capital.com CLI
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
An **unofficial**, fast, scriptable command-line client for the [Capital.com](https://capital.com) Open API, built with Typer and Rich. Independent project — not affiliated with or endorsed by Capital.com.
|
|
33
33
|
|
|
34
34
|
Browse markets, manage accounts and watchlists, preview and execute trades behind multiple safety guardrails, and stream real-time prices — from your terminal, in human-readable tables or raw JSON for automation.
|
|
35
35
|
|
|
@@ -38,7 +38,7 @@ Browse markets, manage accounts and watchlists, preview and execute trades behin
|
|
|
38
38
|
[](LICENSE)
|
|
39
39
|
[](https://www.python.org/downloads/)
|
|
40
40
|
[](https://github.com/SimonTarara62/capitalcom-cli/releases)
|
|
41
|
-
[](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
|
|
72
|
-
[Use as a library](#use-as-a-library
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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) —
|
|
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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "capitalcom-cli"
|
|
3
3
|
dynamic = ["version"]
|
|
4
|
-
description = "
|
|
4
|
+
description = "Unofficial command-line client for the Capital.com Open API"
|
|
5
5
|
authors = [{name = "Simon Tarara"}]
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
requires-python = ">=3.10"
|
|
@@ -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
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|