Skip to main content

FCS WebSocket Python

Real-time WebSocket client library for Forex, Cryptocurrency, and Stock market data from FCS API.

License: MIT Python PyPI

Features

  • Real-time WebSocket - Live price updates via WebSocket connection
  • Multi-Market Support - Forex, Crypto, and Stock data
  • Auto-Reconnect - Handles connection drops automatically
  • Simple API - Easy to use with decorators

Installation

pip install fcsapi-websocket

Examples

To download example files, clone the repository:

git clone https://github.com/fcsapi/websocket-python
cd websocket-python/examples
python simple_example.py

Demo API Key

Use demo API key for testing: fcs_socket_demo


Quick Start

from fcs_client_lib import FCSClient

client = FCSClient('YOUR_API_KEY')

@client.on_message
def handle_message(data):
    if data.get('type') == 'price':
        print(data)

client.connect()
client.join('BINANCE:BTCUSDT', '1D')
client.run_forever()

Usage Examples

Example 1: Simple Crypto Price

from fcs_client_lib import FCSClient

client = FCSClient('fcs_socket_demo')

@client.on_message
def on_message(data):
    if data.get('type') == 'price':
        symbol = data.get('symbol')
        price = data['prices'].get('c')  # Close price
        print(f'{symbol}: ${price}')

client.connect()
client.join('BINANCE:BTCUSDT', '1D')
client.run_forever()

Example 2: Multiple Forex Pairs with Spread

from fcs_client_lib import FCSClient

client = FCSClient('fcs_socket_demo')

@client.on_connected
def on_connected():
    print('Connected! Subscribing to forex pairs...')
    client.join('FX:EURUSD', '1D')
    client.join('FX:GBPUSD', '1D')
    client.join('FX:USDJPY', '1D')

@client.on_message
def on_message(data):
    if data.get('type') == 'price':
        p = data['prices']
        symbol = data.get('symbol')
        ask = p.get('a')
        bid = p.get('b')
        spread = round((float(ask) - float(bid)) * 10000, 1) if ask and bid else '--'
        print(f'{symbol}: Ask={ask} Bid={bid} Spread={spread} pips')

client.connect()
client.run_forever()

Example 3: Background Thread (Non-blocking)

from fcs_client_lib import FCSClient
import time

client = FCSClient('fcs_socket_demo')

@client.on_message
def on_message(data):
    if data.get('type') == 'price':
        print(f"Price update: {data.get('symbol')}")

# Connect and run in background thread
client.connect()
client.run_forever(blocking=False)

# Subscribe after connection
time.sleep(2)  # Wait for connection
client.join('BINANCE:ETHUSDT', '1D')

# Your other code continues here...
print('Main thread continues...')
time.sleep(60)  # Keep running for 60 seconds
client.disconnect()

API Reference

Create Client

from fcs_client_lib import FCSClient

client = FCSClient(api_key, url=None)
client.show_logs = True  # Enable console logs (default: False)

Connection

client.connect()                    # Connect to server
client.run_forever(blocking=True)   # Start receiving (blocking=False for background)
client.disconnect()                 # Disconnect from server

Subscription

client.join('BINANCE:BTCUSDT', '1D')   # Subscribe to symbol
client.leave('BINANCE:BTCUSDT', '1D')  # Unsubscribe from symbol
client.remove_all()                     # Unsubscribe from all

Event Callbacks (Decorators)

@client.on_connected
def on_connected():
    print('Connected!')

@client.on_message
def on_message(data):
    print(data)

@client.on_close
def on_close(code, msg):
    print(f'Closed: {code}')

@client.on_error
def on_error(error):
    print(f'Error: {error}')

@client.on_reconnect
def on_reconnect():
    print('Reconnected!')

Properties

client.is_connected          # Connection status (bool)
client.active_subscriptions  # Current subscriptions (dict)
client.reconnect_delay       # Reconnect delay in seconds (default: 3)
client.reconnect_limit       # Max reconnect attempts (default: 5)
client.show_logs             # Enable/disable console logs (default: False)

Symbol Format

Market Format Examples
Forex FX:PAIR FX:EURUSD, FX:GBPUSD
Crypto EXCHANGE:PAIR BINANCE:BTCUSDT, BINANCE:ETHUSDT
Stock EXCHANGE:SYMBOL NASDAQ:AAPL, NYSE:TSLA

Timeframes

Timeframe Description
1 1 minute
5 5 minutes
15 15 minutes
1H 1 hour
1D 1 day
1W 1 week

Message Data Format

# Price update
{
    "type": "price",
    "symbol": "BINANCE:BTCUSDT",
    "timeframe": "1D",
    "prices": {
        "mode": "candle",  # or "initial", "askbid"
        "t": 1766361600,   # Timestamp
        "o": 88658.87,     # Open
        "h": 90588.23,     # High
        "l": 87900,        # Low
        "c": 89962.61,     # Close
        "v": 8192.70,      # Volume
        "a": 89962.62,     # Ask
        "b": 89962.61      # Bid
    }
}

Get API Key

  1. Visit FCS API
  2. Sign up for free
  3. Get your API key

Documentation

Support

License

MIT License - see LICENSE file.

Metadata

Release files for fcsapi-websocket 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fcsapi-websocket 4.0.0
File Size Uploaded
fcsapi_websocket-4.0.0.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fcsapi-websocket 4.0.0
File Interpreter ABI Platform
fcsapi_websocket-4.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.7 kB

Release files / fcsapi_websocket-4.0.0.tar.gz

Download URL fcsapi_websocket-4.0.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
20f4bce5e73ebd9f7c781455aa156a63975e3aa51e2883f64d84e0fb6c31422f
BLAKE2b-256 checksum
How to use checksums
e9ccb05b2465de1e980379e80d280b40c588f9efedaf72d1777222037ca1be80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 25, 2025.

Transparency log

Release files / fcsapi_websocket-4.0.0-py3-none-any.whl

Download URL fcsapi_websocket-4.0.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dbfdb3b9c2d5d611a4af28cbfc75e77387395acb008dc648d0a600514827fe2b
BLAKE2b-256 checksum
How to use checksums
d8b5c346c0d5d5ba438ac9e65bdab9abce88b9238a5a30c8dde7c5fdad713640
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 25, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

4.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page