CapitalCom

A lightweight Python wrapper for the Capital.com REST API. Supports demo and live accounts. Designed for algorithmic trading, market data exploration, and automated execution.
Features
- Open and close market positions
- Lot-based forex trading with SL/TP (in pips)
- Automatic session token renewal
- View and manage demo account balance
- List and search tradable instruments
- Colored CLI feedback (green/red/blue)
Installation
pip install capitalcom
Example usage
from capitalcom_client import CapitalClient
client = CapitalClient(
api_key="your_api_key",
login="your_email",
password="your_api_password",
demo=True # Set to False for live account
)
# List your accounts
client.list_accounts()
# Check balance
balance = client.get_balance()
print("Current balance:", balance)
# Open and close a test trade
client.test_trade()
# Add demo funds
client.top_up_demo(5000)
)
# Open and close a test trade
client.test_trade()
Available Methods
| Method | Description |
|---|---|
open_forex_position(epic, size, direction, stop_dist=None, profit_dist=None) |
Open forex trade (lot-based) |
open_raw_position(epic, size, direction, ...) |
Open position with raw size |
close_position_by_id(deal_id, size=None) |
Close full or partial position |
get_open_positions() |
List all open positions |
search_instrument(term) |
Search instruments via market navigation |
search_markets(term) |
Search instruments via /markets endpoint |
list_all_instruments() |
Recursively list all tradable instruments |
get_session_info() |
View session, accountId, clientId |
get_balance(account_id=None, raw=False) |
Fetch current account balance |
list_accounts() |
List all your accounts and IDs |
top_up_demo(amount) |
Add funds to demo account (up to 100K) |
test_trade() |
Execute a small test trade (0.001 lot EUR/USD) |
License
This project is licensed under the CC BY-NC 4.0 License.
Notes
- Works with REST API only (not streaming).
requestsis the only dependency.
Metadata
Release files for capitalcom 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| capitalcom-1.0.4.tar.gz | 5.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| capitalcom-1.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.9 kB
Release files / capitalcom-1.0.4.tar.gz
| Download URL | capitalcom-1.0.4.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4d9815381fb8bdb0d2b4cfccefc5bb827e5a036905950db6a66436b4ed39d53
|
|
BLAKE2b-256 checksum How to use checksums |
766c5974ab7690447780bf7838c4dbefa979689d1e14638df2f919d60396ef92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / capitalcom-1.0.4-py3-none-any.whl
| Download URL | capitalcom-1.0.4-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
512e3e950f22b828f3b8a453dd2bf83c0623e77594603914bd7c192f72a0bbe4
|
|
BLAKE2b-256 checksum How to use checksums |
2287845a88afec841a3d997973290e52407f862fc77a1fc876e7ead3c1c7f1ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for capitalcom 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.