Skip to main content

Client for Capital.com REST API (demo and real)

Project description

CapitalCom PyPI Publish PyPI Python License PyPI Downloads

Discord

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).
  • requests is the only dependency.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

capitalcom-1.0.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

capitalcom-1.0.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file capitalcom-1.0.2.tar.gz.

File metadata

  • Download URL: capitalcom-1.0.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for capitalcom-1.0.2.tar.gz
Algorithm Hash digest
SHA256 fefa83a0b76b75d879f5b3b8567bc20eb412ef77c069877cd45d85c9e93a2921
MD5 d6ec7016ef6f4725f74b715f4cf606d0
BLAKE2b-256 c394d5d216b68fbbe92ac0cf35631a87783df3a0066a9a927adc3e44a982d880

See more details on using hashes here.

File details

Details for the file capitalcom-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: capitalcom-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for capitalcom-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 30ef5be853497c84f5e7b66268c1f056b19bbf0a4015c50252224924e192d125
MD5 9d90231f2cc55432267a87e682c2ae58
BLAKE2b-256 7a3cf5f3d6e2ceb4f8d9480b483c23f7cff029891e4ade2aae11fcf117922a94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page