DEV Community

Cover image for Real-Time Equity Data Across the Americas with iTick API
San Si wu
San Si wu

Posted on

Real-Time Equity Data Across the Americas with iTick API

iTick provides unified, low-latency market data coverage for global equities, forex, futures, and more. Its consistent API design simplifies access to real-time and historical feeds from key North and Latin American exchanges, including the NYSE & NASDAQ (United States), Toronto Stock Exchange (Canada), Bolsa Mexicana de Valores (Mexico), and Bolsa de Valores de Lima (Peru).

The platform uses a single region parameter to abstract away exchange-specific differences, allowing developers to retrieve Level 1 quotes, trades, depth, and historical bars using the same endpoint patterns across markets.

Americas Market Coverage at a Glance

  • United States (region: US) — NYSE and NASDAQ; prices in USD; sub-50 ms latency on WebSocket; ideal for high-frequency and algorithmic trading.
  • Canada (region: CA) — TSX and TSXV; prices in CAD; strong coverage of financials, energy, and mining sectors.
  • Mexico (region: MX) — BMV; prices in MXN; important for Latin American telecom, consumer, and materials exposure.
  • Peru (region: PE) — BVL; prices in PEN; emerging-market opportunities in mining and financials.

Two primary interfaces are available:

  • REST API — best for on-demand snapshots, batch lookups, portfolio monitoring, and historical data retrieval
  • WebSocket — preferred for real-time quote, trade, and depth streaming with millisecond-level updates

All endpoints require a valid API token from https://itick.org.

Fetching Real-Time US Equity Quotes (REST Example)

import requests

API_TOKEN = "your_itick_token_here"
BASE_URL = "https://api.itick.org"

def fetch_us_quote(symbol: str) -> dict | None:
    """Retrieve current Level 1 quote for a US-listed security."""
    headers = {"accept": "application/json", "token": API_TOKEN}
    url = f"{BASE_URL}/stock/quote?region=US&code={symbol}"

    try:
        resp = requests.get(url, headers=headers, timeout=8)
        resp.raise_for_status()
        return resp.json().get("data", {})
    except Exception as e:
        print(f"US quote failed: {e}")
        return None


# Usage example: Apple Inc.
if __name__ == "__main__":
    quote = fetch_us_quote("AAPL")
    if quote:
        print("NASDAQ — Real-Time Quote".center(60, "="))
        print(f"Symbol     : {quote.get('c', 'N/A')}")
        print(f"Last       : {quote.get('ld', 'N/A')} USD")
        print(f"Change %   : {quote.get('chp', 'N/A')}%")
        print(f"Volume     : {quote.get('v', 'N/A'):,}")
        print(f"Open / High / Low : {quote.get('o')} / {quote.get('h')} / {quote.get('l')}")
        print(f"Timestamp  : {quote.get('t', 'N/A')}")
Enter fullscreen mode Exit fullscreen mode

Streaming Canadian Equities via WebSocket (TSX Example)

For latency-sensitive applications, WebSocket delivers continuous quote and trade updates.

import websocket
import json
import threading
import time

WS_URL = "wss://api.itick.org/stock"
API_TOKEN = "your_itick_token_here"


class TSXMonitor:
    def on_message(self, ws, message):
        try:
            msg = json.loads(message)
            if "data" not in msg:
                return
            d = msg["data"]
            sym = d.get("s")
            typ = d.get("type")

            if typ == "quote":
                print(f"[QUOTE] {sym:6}  Last: {d.get('ld')} CAD   Vol: {d.get('v'):,}")
            elif typ == "tick":
                print(f"[TRADE] {sym:6}  Price: {d.get('p')}   Size: {d.get('v')}")
        except Exception as e:
            print(f"Parse error: {e}")

    def on_open(self, ws):
        print("WebSocket connected → subscribing to TSX symbols")
        sub = {
            "ac": "subscribe",
            "params": "RY$CA,ENB$CA,ABX$CA",  # Royal Bank, Enbridge, Barrick
            "types": "quote,tick"
        }
        ws.send(json.dumps(sub))

    def on_error(self, ws, error):
        print(f"WS error: {error}")

    def on_close(self, ws, code, msg):
        print(f"WS closed (code {code}): {msg}")

    def run(self):
        headers = {"token": API_TOKEN}
        self.ws = websocket.WebSocketApp(
            WS_URL, header=headers,
            on_open=self.on_open, on_message=self.on_message,
            on_error=self.on_error, on_close=self.on_close
        )

        # Required heartbeat (iTick specification)
        def ping():
            while True:
                time.sleep(30)
                if self.ws.sock and self.ws.sock.connected:
                    self.ws.send(json.dumps({"ac": "ping", "params": str(int(time.time() * 1000))}))

        threading.Thread(target=ping, daemon=True).start()
        self.ws.run_forever()


if __name__ == "__main__":
    TSXMonitor().run()
Enter fullscreen mode Exit fullscreen mode

Important WebSocket details
Symbol format is always TICKER$REGION (e.g. RY$CA, AAPL$US).
Supported subscription types include quote, tick, and depth (comma-separated).
Send a ping message approximately every 30 seconds to maintain the connection.

Mexico (BMV) and Peru (BVL) — Quick REST Examples

Prices are returned in local currency (MXN for Mexico, PEN for Peru).

Mexico example — América Móvil

def fetch_mx_quote(symbol: str):
    url = f"{BASE_URL}/stock/quote?region=MX&code={symbol}"
    headers = {"accept": "application/json", "token": API_TOKEN}
    resp = requests.get(url, headers=headers)
    if resp.status_code == 200:
        data = resp.json().get("data", {})
        print(f"BMV — {symbol}: {data.get('ld')} MXN")
        return data
    else:
        print(f"Mexico request failed: {resp.text}")
Enter fullscreen mode Exit fullscreen mode

Peru example (validate exact ticker format first)

def fetch_pe_quote(symbol: str):
    url = f"{BASE_URL}/stock/quote?region=PE&code={symbol}"
    # implementation follows the same pattern
Enter fullscreen mode Exit fullscreen mode

Recommendations for Latin American markets
Always confirm supported symbols and region codes via the /symbol/list or symbol-search endpoint before production use.
Consider integrating a real-time FX feed (also available on iTick) when displaying prices in USD or other base currencies.

Choosing Between REST and WebSocket

REST is ideal when you need periodic snapshots, portfolio valuation, intraday scanners with moderate frequency, or historical bar / tick data for research and backtesting.

WebSocket is the right choice for live trading desks, algorithmic execution systems, real-time monitoring panels, and any application where millisecond-level updates and minimal polling overhead matter.

iTick’s region-based, unified interface greatly reduces complexity when building strategies that span US mega-caps, Canadian resource names, and Latin American growth opportunities.

Further Reading
Documentation: https://docs.itick.org
Account & Pricing: https://itick.org
Code Examples: https://github.com/itick-org

Top comments (0)