Streaming Real-Time FX Data

Stream real-time FX quotes via WebSocket for live mid, bid, and ask prices across approximately 1000 currency pairs.

The BlueGamma FX streaming API provides real-time foreign exchange quotes via WebSocket. Use this to power live dashboards, monitor currency exposure, or feed real-time FX rates into pricing engines.


WebSocket Endpoint

wss://streaming.bluegamma.io/fx_stream

Quick Start

Connect to the stream with your API token and receive real-time quotes:

import asyncio
import json
import websockets

async def stream_fx():
    url = 'wss://streaming.bluegamma.io/fx_stream?s=EURUSD&s=GBPUSD&token=YOUR_API_KEY'
    
    async with websockets.connect(url) as ws:
        async for msg in ws:
            data = json.loads(msg)
            if data.get("type") == "quote":
                print(f"{data['symbol']}: mid={data['mid']}, bid={data['bid']}, ask={data['ask']}")

asyncio.run(stream_fx())

Sample output:


Query Parameters

Parameter
Required
Description

s

No

Symbol(s) to subscribe to. Repeat for multiple symbols (e.g., ?s=EURUSD&s=GBPUSD)

token

Yes

Your BlueGamma API key. See Authentication


Server Messages

The server sends JSON messages to your client. Each message has a type field indicating its purpose.

Connection Confirmation

Sent immediately after connecting:

Field
Description

client_id

Unique identifier for your session

subscribed

List of symbols you're currently subscribed to

Real-Time Quote

Sent continuously as prices update:

Field
Description

symbol

Currency pair

mid

Mid-market rate (average of bid and ask)

bid

Best bid price

ask

Best ask price

timestamp

ISO 8601 timestamp in UTC

Subscription Confirmation

Sent when you subscribe to new symbols:

Unsubscription Confirmation

Sent when you unsubscribe from symbols:

Heartbeat

The server sends periodic pings to keep the connection alive:

If you send a ping, you'll receive:

Error

Sent when something goes wrong:


Client Commands

Send JSON messages to the server to manage your subscriptions.

Subscribe to Additional Symbols

Response:

Unsubscribe from Symbols

Response:

Ping

Response:


Supported Currency Pairs

The stream supports approximately 1000 currency pairs, including:

  • Major pairs: EURUSD, GBPUSD, USDJPY, USDCHF, AUDUSD, USDCAD, NZDUSD

  • Euro crosses: EURGBP, EURJPY, EURCHF, EURAUD, EURCAD, and more

  • Other crosses: GBPJPY, CHFJPY, AUDJPY, CADJPY, and more

  • Emerging markets: USDMXN, USDBRL, USDZAR, USDTRY, USDCNY, and many more

circle-info

For a complete list of available pairs or to verify availability of specific currencies, contact us at support@bluegamma.ioenvelope.


Use Cases

Use Case
Description

Real-time dashboards

Power live FX rate displays and monitoring screens

Risk monitoring

Track currency exposure in real-time

Pricing engines

Real-time FX component for multi-asset pricing

Cash flow forecasting

Monitor FX rates affecting foreign currency positions


Complete Example with Reconnection

For production use, implement reconnection logic to handle network interruptions:


Limits and Best Practices

Limit
Value

Max symbols per connection

1000

Best practices:

  1. Implement reconnection logic — Network interruptions happen; always reconnect automatically

  2. Handle heartbeats — The server sends periodic pings to keep connections alive

  3. Subscribe dynamically — Use subscribe/unsubscribe commands rather than reconnecting to change symbols

  4. Process messages asynchronously — Don't block the message loop with slow operations


Error Handling

Error
Cause
Solution

Connection closed with code 1008

Invalid or missing API token

Check your token parameter

"Subscription limit exceeded"

Requested more than 1000 symbols

Reduce the number of symbols

Connection timeout

Network issue or server unavailable

Implement retry with exponential backoff



Need help? 📩 support@bluegamma.ioenvelope | 📅 Book a callarrow-up-right

Last updated

Was this helpful?