PHPackages                             fcsapi/websocket - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. fcsapi/websocket

ActiveLibrary[HTTP &amp; Networking](/categories/http)

fcsapi/websocket
================

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

4.0.0(4mo ago)11MITJavaScriptPHP &gt;=7.4

Since Dec 25Pushed 4mo agoCompare

[ Source](https://github.com/fcsapi/websocket-php)[ Packagist](https://packagist.org/packages/fcsapi/websocket)[ Docs](https://github.com/fcsapi/websocket-php)[ RSS](/packages/fcsapi-websocket/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

FCSAPI Realtime PHP
===================

[](#fcsapi-realtime-php)

**PHP** Real-time WebSocket client library for **Forex**, **Cryptocurrency**, and **Stock** market data from [FCS API](https://fcsapi.com).

This library provides PHP integration with WebSocket for live market data streaming. Uses the JavaScript client library for browser-based real-time updates.

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/6eff5053a32c9e0bcc0982c4f118ef689cad7831a3d982767aae3901bf67313c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344372e342d626c75652e737667)](https://php.net)[![Packagist](https://camo.githubusercontent.com/c1caecd93640b09faf2aa2724376b69e2378cc71ea2d325f372522f15363f2a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6663736170692f776562736f636b65742e737667)](https://packagist.org/packages/fcsapi/websocket)

Features
--------

[](#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
----

[](#demo)

Use demo API key for testing: `fcs_socket_demo`

Installation
------------

[](#installation)

### Composer (Recommended)

[](#composer-recommended)

```
composer require fcsapi/websocket
```

### Manual Installation

[](#manual-installation)

1. Download or clone this repository
2. Include the JavaScript library in your PHP views

```

    FCS-API WebSocket Example

    Loading...

        const client = new FCSClient('');

        client.onmessage = (data) => {
            if (data.type === 'price' && data.prices) {
                const p = data.prices;
                if (p.mode === 'candle' || p.mode === 'initial') {
                    document.getElementById('price').innerText =
                        `${data.symbol}: $${p.c} (O:${p.o} H:${p.h} L:${p.l})`;
                }
            }
        };

        client.connect().then(() => {
            client.join('', '');
        });

```

### Laravel Blade Example

[](#laravel-blade-example)

```
{{-- resources/views/realtime.blade.php --}}
@extends('layouts.app')

@section('scripts')

@endsection

@section('content')
Loading Forex...
Loading Crypto...

    const client = new FCSClient('{{ config("services.fcs.api_key") }}');

    client.onmessage = (data) => {
        if (data.type === 'price' && data.prices) {
            const p = data.prices;
            if (p.mode === 'candle' || p.mode === 'initial') {
                if (data.symbol.startsWith('FX:')) {
                    document.getElementById('forex-price').innerText =
                        `${data.symbol}: ${p.c}`;
                } else {
                    document.getElementById('crypto-price').innerText =
                        `${data.symbol}: $${p.c}`;
                }
            }
        }
    };

    client.connect().then(() => {
        client.join('FX:EURUSD', '1D');
        client.join('BINANCE:BTCUSDT', '1D');
    });

@endsection
```

### CodeIgniter Example

[](#codeigniter-example)

```
