Download the PHP package fcsapi/websocket without Composer
On this page you can find all versions of the php package fcsapi/websocket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fcsapi/websocket
More information about fcsapi/websocket
Files in fcsapi/websocket
Package websocket
Short Description Real-time WebSocket client library for Forex, Cryptocurrency, and Stock market data from FCS API
License MIT
Homepage https://github.com/fcsapi/websocket-php
Informations about the package websocket
FCSAPI Realtime PHP
PHP Real-time WebSocket client library for Forex, Cryptocurrency, and Stock market data from FCS API.
This library provides PHP integration with WebSocket for live market data streaming. Uses the JavaScript client library for browser-based real-time updates.
Features
- Real-time WebSocket - Live price updates via WebSocket connection
- Multi-Market Support - Forex, Crypto, and Stock data in one library
- PHP Backend Ready - Easy integration with PHP applications
- Auto-Reconnect - Handles WebSocket connection drops automatically
- Tab Visibility - Smart disconnect when browser tab is hidden (saves bandwidth)
- Heartbeat - Built-in WebSocket keep-alive mechanism
Demo
Use demo API key for testing: fcs_socket_demo
Installation
Composer (Recommended)
Manual Installation
- Download or clone this repository
- Include the JavaScript library in your PHP views
Quick Start
Basic PHP Example
Laravel Blade Example
CodeIgniter Example
API Reference
JavaScript Client (Browser-side)
Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
apiKey |
string | required | Your FCS API key |
url |
string | wss://ws-v4.fcsapi.com/ws |
WebSocket server URL (optional) |
Methods
connect()
Connects to the WebSocket server. Returns a Promise.
disconnect()
Manually closes the connection.
join(symbol, timeframe)
Subscribe to a symbol for real-time updates.
leave(symbol, timeframe)
Unsubscribe from a symbol.
removeAll()
Unsubscribe from all symbols.
Event Callbacks
| Callback | Description |
|---|---|
onconnected |
Fired when connection is established |
onmessage |
Fired when data is received |
onclose |
Fired when connection is closed |
onerror |
Fired when an error occurs |
onreconnect |
Fired when reconnection is successful |
Configuration Options
| Property | Type | Default | Description |
|---|---|---|---|
reconnectDelay |
number | 3000 | Delay (ms) before reconnection attempt |
reconnectlimit |
number | 5 | Maximum reconnection attempts |
focusTimeout |
number | 3 | Minutes before disconnect when tab is hidden (0 = never) |
Message Data Format
The WebSocket sends different message types:
1. Join Confirmation
2. Profile Data (One-time on join)
3. Initial Candle Data (One-time on join)
4. Live Candle Updates (Continuous)
Primary update mode - contains all price data including OHLCV and Ask/Bid.
5. Ask/Bid Updates
Sent when only Ask/Bid data changes. All values in this message are updated.
Handling Different Price Modes
Symbol Format
Symbols must include an exchange prefix:
| Market | Format | Examples |
|---|---|---|
| Forex | FX:PAIR |
FX:EURUSD, FX:GBPUSD, FX:USDJPY |
| 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 |
30 |
30 minutes |
1H |
1 hour |
4H |
4 hours |
1D |
1 day |
1W |
1 week |
1M |
1 month |
Examples
Check the /examples folder for complete working demos:
- forex-example.php - Real-time Forex prices
- crypto-example.php - Real-time Cryptocurrency prices
- stock-example.php - Real-time Stock prices
PHP Framework Integration
Laravel
Add to your .env:
Add to config/services.php:
CodeIgniter 4
Add to your .env:
Symfony
Add to your .env:
Browser Tab Visibility
The library automatically handles browser tab visibility to save bandwidth:
- When tab is hidden for more than 3 minutes (configurable), connection is closed
- When tab becomes visible again, connection is automatically restored
- All subscriptions are automatically rejoined after reconnection
Set focusTimeout = 0 to disable this feature:
Error Handling
Get API Key
- Visit FCS API
- Sign up for a free account
- Get your API key from the dashboard
Documentation
For complete API documentation, visit:
Support
- Email: [email protected]
- Website: fcsapi.com
License
MIT License - see LICENSE file for details.