Streaming Real-Time FX Data
Stream real-time FX quotes via WebSocket for live mid, bid, and ask prices across roughly 945 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_streamQuick 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
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. You can send the key in an x-api-key header instead, which keeps it out of URLs and logs
For the full list of supported currency pairs, see Supported FX Currency Pairs.
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:
client_id
Unique identifier for your session
subscribed
List of symbols you're currently subscribed to
Real-Time Quote
Sent continuously as prices update:
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 a ping about every 30 seconds to keep the connection alive. If you receive neither a ping nor a quote for 60 seconds, reconnect:
If you send a ping, you'll receive:
Error
Sent when something goes wrong:
A subscribe request that would take the connection over 50 symbols is rejected whole. An unknown or malformed symbol gets an error that names it.
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 roughly 945 currency pairs, the same set as the /fx spot endpoint, 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
Use Cases
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
Connections drop: networks change, proxies close idle sockets, and servers restart during deploys. For production use, reconnect automatically:
Track when you last received any message. Quotes and pings both count, so this works in quiet periods too (FX quotes stop at weekends).
If nothing arrives for 60 seconds, close the connection and open a new one.
Reconnect with exponential backoff (1s, 2s, 4s and so on, capped at 30s) plus random jitter.
Subscribe again after reconnecting. Subscriptions belong to a connection and are not carried over, and the stream restarts from the next live quote (missed quotes are not replayed).
Limits and Best Practices
Max symbols per connection
50
Max connections per API key
25
Typical update frequency
~300ms for major pairs (e.g. EURUSD, GBPUSD), ~1s for less liquid pairs
Best practices:
Implement reconnection logic: reconnect automatically with exponential backoff, and subscribe again after each reconnect
Watch for silence: the server sends a ping about every 30 seconds, so 60 seconds with no ping and no quote means the connection is dead
Subscribe dynamically — Use subscribe/unsubscribe commands rather than reconnecting to change symbols
Process messages asynchronously — Don't block the message loop with slow operations
Error Handling
Connection refused with HTTP 403
Invalid or missing API key
Check your token parameter or x-api-key header
Connection refused with HTTP 503 and a Retry-After header
25 connections already open for your key, the server is at capacity, or a deploy is in progress
Wait the Retry-After seconds, then reconnect
"Subscription limit of 50 symbols per connection would be exceeded"
The request would take the connection over 50 symbols
Subscribe to fewer symbols, or spread them across connections
Connection closed with code 1013
Your client is not reading messages fast enough
Process messages asynchronously, then reconnect
Connection closed with code 1001
The server is restarting during a deploy
Reconnect and subscribe again
No message for 60 seconds
Network issue or a dropped connection
Reconnect with exponential backoff
Related
Authentication — How to get and use your API key
Fetching FX Forward Rates — REST API for FX forward rates
Rate Limits & Best Practices — General API best practices
Create a key under API Keys in the app sidebar. See Authentication.
Last updated
Was this helpful?

