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

Features
- Real-time WebSocket - Live price updates via WebSocket connection
- Multi-Market Support - Forex, Crypto, and Stock data
- Frontend & Backend - Use in browser or pure Python
- Auto-Reconnect - Handles connection drops automatically
- No Dependencies - Frontend uses Python built-in modules
Installation
pip install fcsapi-websocket-python
For backend usage, also install:
pip install websocket-client
Demo
Use demo API key for testing: fcs_socket_demo
Frontend (Browser-based)
For web applications that display real-time prices in the browser.
Structure
frontend/
├── fcs-client-lib.js # JavaScript WebSocket client
└── examples/
├── crypto_example.py # Crypto prices in browser
├── forex_example.py # Forex prices in browser
└── stock_example.py # Stock prices in browser
Quick Start
cd frontend/examples
python crypto_example.py
How it works
- Python serves HTML page with embedded JavaScript
- JavaScript (
fcs-client-lib.js) connects to WebSocket
- Real-time updates displayed in browser
Backend (Pure Python)
For server-side applications, bots, or scripts that need real-time data without a browser.
Structure
backend/
├── fcs_client_lib.py # Python WebSocket client
└── examples/
├── crypto_example.py # Terminal crypto prices
├── forex_example.py # Terminal forex prices
└── stock_example.py # Terminal stock prices
Quick Start
pip install websocket-client
cd backend/examples
python crypto_example.py
Usage
from backend 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()
Backend API
from backend import FCSClient
client = FCSClient(api_key, url=None)
client.connect()
client.run_forever(blocking=True)
client.join('BINANCE:BTCUSDT', '1D')
client.leave('BINANCE:BTCUSDT', '1D')
client.remove_all()
client.disconnect()
@client.on_connected
@client.on_message
@client.on_close
@client.on_error
@client.on_reconnect
Symbol Format
| Forex | FX:PAIR | FX:EURUSD, FX:GBPUSD |
| Crypto | EXCHANGE:PAIR | BINANCE:BTCUSDT, BINANCE:ETHUSDT |
| Stock | EXCHANGE:SYMBOL | NASDAQ:AAPL, NYSE:TSLA |
Timeframes
1 | 1 minute |
5 | 5 minutes |
15 | 15 minutes |
1H | 1 hour |
1D | 1 day |
1W | 1 week |
Message Data Format
{
"type": "price",
"symbol": "BINANCE:BTCUSDT",
"timeframe": "1D",
"prices": {
"mode": "candle",
"t": 1766361600,
"o": 88658.87,
"h": 90588.23,
"l": 87900,
"c": 89962.61,
"v": 8192.70,
"a": 89962.62,
"b": 89962.61
}
}
Get API Key
- Visit FCS API
- Sign up for free
- Get your API key
Documentation
Support
License
MIT License - see LICENSE file.