Real-Time Forex Data API by Infoway

Published: (June 17, 2026 at 10:12 PM EDT)
10 min read
Source: Dev.to

Source: Dev.to

Infoway API aggregates Forex price data from major market makers and delivers it through a unified REST and WebSocket interface. For forex, this means genuine real-time rates with latency consistently under 100ms and an SLA of 99.6% uptime.

The forex feed covers 42 currency pairs across all major and several exotic pairs:

Symbol Pair

EURUSD Euro / US Dollar

GBPUSD British Pound / US Dollar

USDJPY US Dollar / Japanese Yen

USDCHF US Dollar / Swiss Franc

AUDUSD Australian Dollar / US Dollar

NZDUSD New Zealand Dollar / US Dollar

USDCAD US Dollar / Canadian Dollar

USDCNY US Dollar / Chinese Yuan

USDCNH US Dollar / Offshore Chinese Yuan

USDHKD US Dollar / Hong Kong Dollar

USDSGD US Dollar / Singapore Dollar

USDTHB US Dollar / Thai Baht

USDTWD US Dollar / Taiwan Dollar

USDRUB US Dollar / Russian Ruble

EURJPY Euro / Japanese Yen

EURGBP Euro / British Pound

EURCHF Euro / Swiss Franc

EURAUD Euro / Australian Dollar

EURCAD Euro / Canadian Dollar

EURNZD Euro / New Zealand Dollar

GBPJPY British Pound / Japanese Yen

GBPCHF British Pound / Swiss Franc

GBPAUD British Pound / Australian Dollar

GBPCAD British Pound / Canadian Dollar

GBPNZD British Pound / New Zealand Dollar

AUDJPY Australian Dollar / Japanese Yen

AUDCHF Australian Dollar / Swiss Franc

AUDCAD Australian Dollar / Canadian Dollar

AUDNZD Australian Dollar / New Zealand Dollar

AUDDKK Australian Dollar / Danish Krone

CADJPY Canadian Dollar / Japanese Yen

CADCHF Canadian Dollar / Swiss Franc

CADUSD Canadian Dollar / US Dollar

CHFJPY Swiss Franc / Japanese Yen

CHFUSD Swiss Franc / US Dollar

NZDJPY New Zealand Dollar / Japanese Yen

NZDCAD New Zealand Dollar / Canadian Dollar

SGDUSD Singapore Dollar / US Dollar

CNYUSD Chinese Yuan / US Dollar

JPYUSD Japanese Yen / US Dollar

USDEUR US Dollar / Euro

USDGBP US Dollar / British Pound

Beyond forex, the same API key gives you access to equities (US, HK, China A-shares, Japan, India), crypto, commodities, precious metals, and CFDs — all through the same interface. If your application eventually grows to cover more than just currencies, you won’t need to stitch together multiple providers.

Getting Started

Sign up at the Infoway website to get your API key. New accounts automatically receive a 7-day trial — no credit card required. Your key shows up in the dashboard immediately, and you can start making requests within minutes.

Every request needs the API key passed as a request header:

apiKey: YOUR_API_KEY_HERE
Enter fullscreen mode


Exit fullscreen mode

REST API Examples

The forex endpoints use the /common/ path prefix. Here’s how to pull data for the most common use cases.

Latest Trade Price

The trade endpoint returns the most recent transaction for one or more currency pairs.

import requests

url = "https://data.infoway.io/common/batch_trade/EURUSD,GBPUSD,USDJPY"

headers = {
    "User-Agent": "Mozilla/5.0",
    "Accept": "application/json",
    "apiKey": "YOUR_API_KEY_HERE"
}

response = requests.get(url, headers=headers)
print(response.json())
Enter fullscreen mode


Exit fullscreen mode

Response:

{
  "ret": 200,
  "msg": "success",
  "traceId": "a1b2c3d4-1234-5678-abcd-ef0123456789",
  "data": [
    {
      "s": "EURUSD",
      "t": 1781672609412,
      "p": "1.08423",
      "v": "1.0",
      "vw": "1.08423",
      "td": 1
    },
    {
      "s": "GBPUSD",
      "t": 1781672609318,
      "p": "1.27185",
      "v": "1.0",
      "vw": "1.27185",
      "td": 2
    },
    {
      "s": "USDJPY",
      "t": 1781672609501,
      "p": "149.832",
      "v": "1.0",
      "vw": "149.832",
      "td": 0
    }
  ]
}
Enter fullscreen mode


Exit fullscreen mode

Field Description

s Symbol

t Timestamp (milliseconds)

p Trade price

v Volume

vw Trade value

td Direction: 0 = default, 1 = buy, 2 = sell

You can query up to 100 symbols in a single request by comma-separating them in the URL path.

Candlestick / OHLCV Data

The candle endpoint supports 12 timeframes from 1-minute to yearly. It uses a POST request with a JSON body.

import requests
import json

url = "https://data.infoway.io/common/v2/batch_kline"

headers = {
    "User-Agent": "Mozilla/5.0",
    "Accept": "application/json",
    "Content-Type": "application/json",
    "apiKey": "YOUR_API_KEY_HERE"
}

payload = {
    "klineType": 1,      # 1 = 1-min, 2 = 5-min, 5 = 1-hour, 8 = daily
    "klineNum": 20,      # Number of candles to return (max 500 per symbol)
    "codes": "EURUSD,GBPUSD"
}

response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.json())
Enter fullscreen mode


Exit fullscreen mode

Response:

{
  "ret": 200,
  "msg": "success",
  "traceId": "b2c3d4e5-2345-6789-bcde-f01234567890",
  "data": [
    {
      "s": "EURUSD",
      "respList": [
        {
          "t": "1781671920",
          "o": "1.08401",
          "h": "1.08435",
          "l": "1.08398",
          "c": "1.08423",
          "v": "142.0",
          "vw": "154.08",
          "pc": "0.02%",
          "pca": "0.00022"
        }
      ]
    }
  ]
}
Enter fullscreen mode


Exit fullscreen mode

Field Description

t Candle open time (Unix seconds)

o Open

h High

l Low

c Close

v Volume

vw Trade value

pc Change %

pca Change (absolute)

To pull historical candles, add a timestamp field to the request body. The API will return candles going back from that Unix timestamp:

payload = {
    "klineType": 8,           # Daily candles
    "klineNum": 500,
    "codes": "EURUSD",
    "timestamp": 1770000000   # Pull up to 500 daily candles ending at this time
}
Enter fullscreen mode


Exit fullscreen mode

Minute-level history goes back 3 years. Daily and above have no lookback restriction.

Order Book (Bid/Ask)

The depth endpoint returns the current best bid and ask for one or more pairs.

import requests

url = "https://data.infoway.io/common/batch_depth/EURUSD,USDJPY"

headers = {
    "User-Agent": "Mozilla/5.0",
    "Accept": "application/json",
    "apiKey": "YOUR_API_KEY_HERE"
}

response = requests.get(url, headers=headers)
print(response.json())
Enter fullscreen mode


Exit fullscreen mode

Response:

{
  "ret": 200,
  "msg": "success",
  "traceId": "c3d4e5f6-3456-7890-cdef-012345678901",
  "data": [
    {
      "s": "EURUSD",
      "t": 1781672693007,
      "a": [
        ["1.08431"],
        ["0.0"]
      ],
      "b": [
        ["1.08415"],
        ["0.0"]
      ]
    }
  ]
}
Enter fullscreen mode


Exit fullscreen mode

a is the ask (sell side), b is the bid (buy side). Each contains a price array and a volume array, matched by index position.

WebSocket for Real-Time Streaming

REST polling works well for dashboards that refresh every few seconds, but if you’re building something that needs to react to price moves in real time — an alert system, an automated strategy, a trading terminal — you want a persistent WebSocket connection instead.

The WebSocket endpoint for forex (and all common-type products like commodities and precious metals) is:

wss://data.infoway.io/ws?business=common&apikey=YOUR_API_KEY_HERE
Enter fullscreen mode


Exit fullscreen mode

Once connected, the server pushes updates to you as they happen. No polling, no repeated round trips.

Here’s a production-ready Python client that subscribes to live trades, order book updates, and 1-minute candles for a set of forex pairs, with automatic reconnection on disconnect:

import asyncio
import json
import uuid
import logging
from typing import Optional
import websockets
from websockets.exceptions import ConnectionClosed

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(message)s"
)
logger = logging.getLogger("forex-ws")

PAIRS = "EURUSD,GBPUSD,USDJPY,AUDUSD,USDCAD"

class ForexWebSocketClient:
    """Real-time forex streaming client with auto-reconnect."""

    def __init__(self, api_key: str):
        self.url = f"wss://data.infoway.io/ws?business=common&apikey={api_key}"
        self.ws: Optional[websockets.WebSocketClientProtocol] = None
        self.running = True
        self.reconnect_base = 5
        self.reconnect_max = 60
        self.heartbeat_interval = 30
        self._heartbeat_task: Optional[asyncio.Task] = None

    def _trace(self) -> str:
        return str(uuid.uuid4())

    async def _send(self, msg: dict) -> None:
        if self.ws:
            await self.ws.send(json.dumps(msg))

    async def _subscribe(self) -> None:
        # Subscribe to live trades
        await self._send({
            "code": 10000,
            "trace": self._trace(),
            "data": {"codes": PAIRS}
        })
        await asyncio.sleep(5)

        # Subscribe to order book
        await self._send({
            "code": 10003,
            "trace": self._trace(),
            "data": {"codes": PAIRS}
        })
        await asyncio.sleep(5)

        # Subscribe to 1-minute candles
        await self._send({
            "code": 10006,
            "trace": self._trace(),
            "data": {
                "arr": [{"type": 1, "codes": PAIRS}]
            }
        })
        logger.info("Subscribed to %s", PAIRS)

    def _start_heartbeat(self) -> None:
        if self._heartbeat_task and not self._heartbeat_task.done():
            self._heartbeat_task.cancel()

        async def beat():
            while True:
                await asyncio.sleep(self.heartbeat_interval)
                if not self.ws or self.ws.close_code is not None:
                    break
                try:
                    await self._send({"code": 10010, "trace": self._trace()})
                    logger.debug("Heartbeat sent")
                except Exception:
                    break

        self._heartbeat_task = asyncio.create_task(beat())

    def _handle(self, raw: str) -> None:
        try:
            msg = json.loads(raw)
        except json.JSONDecodeError:
            logger.error("Bad message: %s", raw)
            return

        code = msg.get("code")
        data = msg.get("data", {})

        if code == 10002:       # Trade push
            logger.info("Trade  %s @ %s", data.get("s"), data.get("p"))
        elif code == 10005:     # Depth push
            logger.info("Depth  %s bid=%s ask=%s",
                        data.get("s"),
                        data.get("b", [[None]])[0][0],
                        data.get("a", [[None]])[0][0])
        elif code == 10008:     # Candle push
            logger.info("Candle %s o=%s h=%s l=%s c=%s",
                        data.get("s"), data.get("o"),
                        data.get("h"), data.get("l"), data.get("c"))
        elif code == 10010:
            logger.debug("Heartbeat ack")
        elif code in (10001, 10004, 10007):
            logger.info("Subscription confirmed (code=%s)", code)
        else:
            logger.debug("Message: %s", raw)

    async def _connect_once(self) -> None:
        async with websockets.connect(self.url) as ws:
            self.ws = ws
            logger.info("Connected to %s", self.url)
            await self._subscribe()
            self._start_heartbeat()
            try:
                async for message in ws:
                    self._handle(message)
            finally:
                if self._heartbeat_task:
                    self._heartbeat_task.cancel()
                self.ws = None

    async def start(self) -> None:
        backoff = self.reconnect_base
        while self.running:
            try:
                await self._connect_once()
                backoff = self.reconnect_base
            except ConnectionClosed as e:
                logger.warning("Connection closed: %s", e)
                backoff = self.reconnect_base
            except Exception as e:
                logger.error("Connection error: %s", e)

            if not self.running:
                break
            logger.info("Reconnecting in %ss...", backoff)
            await asyncio.sleep(backoff)
            backoff = min(backoff * 2, self.reconnect_max)

    def stop(self) -> None:
        self.running = False

async def main():
    client = ForexWebSocketClient(api_key="YOUR_API_KEY_HERE")
    await client.start()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        logger.info("Stopped")
Enter fullscreen mode


Exit fullscreen mode

WebSocket Protocol Reference

Code Direction Description

10000 Client → Server Subscribe to trades

10001 Server → Client Trade subscription confirmed

10002 Server → Client Trade data push

10003 Client → Server Subscribe to order book

10004 Server → Client Order book subscription confirmed

10005 Server → Client Order book push

10006 Client → Server Subscribe to candles

10007 Server → Client Candle subscription confirmed

10008 Server → Client Candle push

10010 Both Heartbeat

One connection supports subscribing to up to 600 symbols simultaneously. The server will drop the connection if no heartbeat is received within 60 seconds, so make sure your client sends one every 30 seconds.

Frequently Asked Questions

When is the forex market open?

The forex market trades 24 hours a day, five days a week. It opens Sunday evening (New York time) with the Sydney session, and the major liquidity windows are the London session (roughly 3am–12pm ET) and the New York session (8am–5pm ET). The overlap between London and New York (8am–12pm ET) is typically when spreads are tightest and volume is highest.

How do I query multiple currency pairs at once?

Comma-separate the symbols in the REST endpoint path or in the codes field of your WebSocket subscription message. REST supports up to 100 symbols per request. WebSocket supports up to 600 per connection.

What is the latency on the price feed?

Under normal market conditions, the measured latency between a market event and data availability via WebSocket is under 100ms. REST requests add a round-trip on top of that, so WebSocket is the right choice for latency-sensitive applications.

Does Infoway API provide historical forex data?

Yes. You can pull minute-level historical data going back 3 years by passing a timestamp parameter in the candle request body. Daily and weekly candles have no lookback limit.

What’s the difference between USDCNY and USDCNH?

CNY is the onshore Chinese yuan (traded on the mainland, subject to PBOC controls). CNH is the offshore yuan traded in Hong Kong and other international markets — it moves more freely based on global supply and demand. The two rates often diverge slightly, and that spread itself can be a useful signal.

Is there a free trial?

Yes — register on the Infoway website and you’ll get a 7-day trial automatically. No credit card, no identity verification required. The trial lets you query all markets and data types, with a rate limit of 60 REST requests per minute and up to 10 WebSocket subscriptions. Feel free to reach out to our support team on Telegram if you have any questions during the trial.

0 views
Back to Blog

Related posts

Read more »

Pointers and Tuning and Loops! Oh My!

Introduction While all code should be efficient, code for library-like components, especially involving loops, should be as efficient as possible since such cod...