Skip to content

Real-time (WebSockets) ​

Live prices, order books, trades, balances and P2P chat reach the browser over a WebSocket. The platform sends each update to Soketi, a self-hosted server that speaks the Pusher protocol, and Soketi passes it to every open page.

10 minutesServer administrationDevOpsVerified against the platform code

How it fits together ​

  1. Something changes: a trade, a new order, a deposit.
  2. The platform puts a broadcast event on a queue (market, orderbook or events).
  3. A Horizon worker sends it to Soketi using PUSHER_APP_ID, PUSHER_APP_KEY and PUSHER_APP_SECRET.
  4. Soketi pushes it to browsers connected at wss://socket.yourdomain.com.
  5. For private updates (your balance, your orders), the browser first proves who it is at /api/broadcasting/auth.

So live updates need Soketi, Horizon and Redis all running.

Install and run Soketi ​

bash
sudo npm install -g @soketi/soketi

The PM2 process soket (soketi start --config=socket-config.json) is one of the background services in config/pm.php: the scheduler's pm:watcher starts it and keeps it running. To start it right away:

bash
cd /var/www/exchange
php artisan pm:ecosystem
pm2w start storage/app/pm2/ecosystem.json --only soket
pm2w save

Admin → Market services shows it as WebSocket Server, with a health check on Soketi's /ready address (the port from socket-config.json). A Soketi that stops answering is restarted; one started some other way (for example the older pm2w start socket.json) is never started a second time.

socket-config.json ​

This file in the project root configures Soketi:

json
{
    "debug": false,
    "port": 6001,
    "appManager.array.apps": [
        { "id": "my-app-id", "key": "my-app-key", "secret": "my-app-secret" }
    ]
}

Replace the example credentials

The repository's socket-config.json contains sample id, key and secret values. Choose your own long random strings before going live. Anyone who knows the secret can send fake price updates to your users.

The matching .env values ​

The same three values go in .env, and the browser needs to know where to connect:

ini
PUSHER_APP_ID=my-app-id
PUSHER_APP_KEY=my-app-key
PUSHER_APP_SECRET=my-app-secret
PUSHER_HOST="socket.yourdomain.com"
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

BROADCAST_DRIVER=pusher
VariableUsed byMust match
PUSHER_APP_IDThe platformid in socket-config.json
PUSHER_APP_KEYThe platform and the browserkey
PUSHER_APP_SECRETThe platform onlysecret
PUSHER_HOST, PUSHER_PORT, PUSHER_SCHEMEWhere the platform and browser connectYour socket subdomain, 443, https
BROADCAST_DRIVERThe platformMust be pusher. .env.example has log, which sends nothing.

The browser gets its copy from the MIX_PUSHER_* lines (MIX_PUSHER_APP_KEY, MIX_PUSHER_HOST, MIX_PUSHER_PORT, MIX_PUSHER_SCHEME, MIX_PUSHER_APP_CLUSTER), which repeat the values above:

ini
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_HOST="${PUSHER_HOST}"

MIX_ values are built into the front-end

MIX_* values are copied into the JavaScript when you build the front-end, not when the page loads. After changing any PUSHER_* value, rebuild both bundles. Otherwise browsers keep connecting with the old values.

MIX_SOCKET_PORT in .env.example isn't used by the current front-end. You can leave it.

The socket subdomain ​

Browsers connect to wss://socket.yourdomain.com on port 443. Nginx passes that to Soketi on port 6001:

nginx
server {
    listen 80;
    server_name socket.yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1:6001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_read_timeout 120s;
    }
}

You need:

  • a DNS A record for socket.yourdomain.com pointing at the server
  • a certificate for it: sudo certbot --nginx -d socket.yourdomain.com

Check it from your computer. A working Soketi answers with OK:

bash
curl https://socket.yourdomain.com

The connection indicator ​

The status bar at the bottom of the trade page shows the live connection:

IndicatorMeaning
🟢 Stable connectionConnected to Soketi. Prices are live.
🟡 Connecting…Connecting, or reconnecting after a short drop
🔴 Connection lostCan't reach Soketi, or the visitor's internet is down. Live prices pause and it retries automatically.

The site footer shows Stable connection or Server Maintenance. That one follows maintenance mode, not the WebSocket.

Fixing "Connection lost" ​

Open the browser's developer tools (F12) → Console or Network → WS to see the error, then check:

CauseFix
Soketi isn't runningpm2w status → soket online? pm2w logs soket for errors
DNS for the socket subdomain is missingdig socket.yourdomain.com should show your server's IP
No certificate on the subdomainThe browser shows a certificate error. Run certbot for socket.yourdomain.com.
Nginx block missing or not reloadedsudo nginx -t && sudo systemctl reload nginx
Key mismatchPUSHER_APP_KEY, MIX_PUSHER_APP_KEY and the key in socket-config.json must be identical. Rebuild the front-end after fixing.
Firewall blocks 443Open it: sudo ufw allow 443/tcp
Connected, but prices never moveHorizon isn't running, or BROADCAST_DRIVER isn't pusher. Check pm2w status and .env.
Public data works, balances don't updatePrivate channel sign-in fails. Check PUSHER_APP_SECRET matches secret, and look for errors on /api/broadcasting/auth in the Network tab.

Port 6001 only needs to be reachable from the server itself, because Nginx connects to it locally. You can block it from outside with sudo ufw deny 6001/tcp.

Owner documentation for the CryptoTech exchange platform.