DEV Community

Cover image for Demystifying the iTick Global Forex, Stocks, Futures, and Funds Real-Time API: A Comprehensive Guide
San Si wu
San Si wu

Posted on

Demystifying the iTick Global Forex, Stocks, Futures, and Funds Real-Time API: A Comprehensive Guide

In today's fast-paced financial world, having access to accurate and timely market data is a game-changer. Financial data providers offer APIs that deliver real-time quotes, historical data, and more for assets like stocks, forex, futures, and funds. These typically include REST APIs for on-demand queries and WebSocket for live streaming. In this blog post, I'll walk you through the iTick API, which covers global markets including forex (GB market), stocks (HK, SZ, SH, US, etc.), futures (US, HK, CN), and funds (US). We'll focus on practical integration using Python examples to make it easy for you to get started.

iTick API
Before diving in, sign up on the official website to grab your API token. The APIs are split into RESTful HTTP GET requests for batch or historical data, and WebSocket for low-latency real-time feeds. Base URL for REST is https://api.itick.org, and all requests need headers like accept: application/json and token: your_token.

Breaking Down the REST API

REST APIs are straightforward—perfect for one-off queries or pulling historical data. Let's explore each asset type.

1. Forex API

The Forex API handles major pairs like EUR/USD and GBP/USD, offering real-time quotes, order books, trades, and historical candlesticks. Use GB as the market code.

  • Real-Time Quote: GET /forex/quote?region={region}&code={code}

    • Params: region (required, e.g., GB), code (required, e.g., EURUSD)
    • Response: Includes last price (ld), open (o), etc.
  • Real-Time Order Book: GET /forex/depth?region={region}&code={code}

    • Params: Same as above.
    • Response: Bids (b) and asks (a) with price (p) and volume (v).
  • Real-Time Trades: GET /forex/tick?region={region}&code={code}

    • Params: Same as above.
    • Response: Last price (ld), volume (v), timestamp (t).
  • Historical Candlesticks: GET /forex/kline?region={region}&code={code}&kType={kType}&limit={limit}&et={et}

    • Params: region (GB), code (EURUSD), kType (1-10 for minute to monthly), limit (required, number of bars), et (optional end timestamp).
    • Response: Array of bars with open (o), high (h), low (l), close (c), etc.

Python Example for Real-Time Quote:

import requests

url = "https://api.itick.org/forex/quote?region=GB&code=EURUSD"
headers = {
    "accept": "application/json",
    "token": "your_token"
}

response = requests.get(url, headers=headers)
if response.status_code == 200:
    data = response.json()
    print("Last Price:", data.get('data', {}).get('ld'))
else:
    print("Request Failed:", response.text)
Enter fullscreen mode Exit fullscreen mode

This snippet fetches the latest EUR/USD price—super handy for quick checks.

2. Stocks API

Stocks API supports exchanges like HK (Hong Kong) and US (United States), with real-time quotes, order books, trades, and candlesticks.

  • Real-Time Quote: GET /stock/quote?region={region}&code={code}

    • Params: region (e.g., HK), code (e.g., 700 for Tencent Holdings).
    • Response: Includes change percentage (chp), etc.
  • Real-Time Order Book: GET /stock/depth?region={region}&code={code}

    • Params: Same as above.
    • Response: Multi-level bids and asks.
  • Real-Time Trades: GET /stock/tick?region={region}&code={code}

    • Params: Same as above.
  • Historical Candlesticks: GET /stock/kline?region={region}&code={code}&kType={kType}&limit={limit}&et={et}

    • Params: Similar to forex; regions include HK, US, etc.

Python Example for Historical Candlesticks:

import requests

url = "https://api.itick.org/stock/kline?region=HK&code=700&kType=2&limit=10"
headers = {
    "accept": "application/json",
    "token": "your_token"
}

response = requests.get(url, headers=headers)
if response.status_code == 200:
    kline_data = response.json().get('data', [])
    for bar in kline_data:
        print(f"Time: {bar['t']}, Open: {bar['o']}, Close: {bar['c']}")
else:
    print("Request Failed")
Enter fullscreen mode Exit fullscreen mode

Here, we're pulling the last 10 five-minute bars for Tencent—great for charting or backtesting.

3. Futures API

Futures API covers commodities and financials across US, HK, and CN markets, like NQ for Nasdaq futures.

  • Real-Time Quote: GET /future/quote?region={region}&code={code}

    • Params: region (e.g., US), code (e.g., NQ).
  • Real-Time Order Book: GET /future/depth?region={region}&code={code}

  • Real-Time Trades: GET /future/tick?region={region}&code={code}

  • Historical Candlesticks: GET /future/kline?region={region}&code={code}&kType={kType}&limit={limit}&et={et}

Responses mirror stocks, ideal for algorithmic trading.

4. Funds API

Funds API focuses on ETFs/LOFs, mainly US like QQQ (Nasdaq ETF).

  • Real-Time Quote: GET /fund/quote?region={region}&code={code}

    • Params: region (e.g., US), code (e.g., QQQ).
  • Real-Time Order Book: GET /fund/depth?region={region}&code={code}

  • Real-Time Trades: GET /fund/tick?region={region}&code={code}

  • Historical Candlesticks: GET /fund/kline?region={region}&code={code}&kType={kType}&limit={limit}&et={et}

Includes fund-specific data like IOPV (indicative net asset value).

Mastering the WebSocket API

For real-time streaming, WebSocket is your go-to. Connect to endpoints like wss://api.itick.org/stock (swap for forex/future/fund). Include your token in headers.

Connection Flow:

  1. Connect and get "Connected Successfully."
  2. Auto-authenticate to receive "authenticated."
  3. Send subscription: {"ac": "subscribe", "params": "AAPL$US", "types": "quote,tick,depth"}

    • params: Symbols like "AAPL$US" (comma-separated for multiples).
    • types: quote (quotes), tick (trades), depth (order book).
  4. Receive JSON data with a 'type' field to identify.

Python Example (using websocket library):

import websocket
import json

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

def on_message(ws, message):
    data = json.loads(message)
    print("Received Data:", data)

def on_open(ws):
    print("Connection Successful")
    subscribe_msg = {
        "ac": "subscribe",
        "params": "AAPL$US",
        "types": "quote,tick"
    }
    ws.send(json.dumps(subscribe_msg))

ws = websocket.WebSocketApp(WS_URL, header={"token": API_TOKEN},
                            on_open=on_open, on_message=on_message)
ws.run_forever()
Enter fullscreen mode Exit fullscreen mode

This subscribes to Apple stock quotes and trades. Send pings every 30 seconds to keep the connection alive.

Wrapping It Up

Whether you're building a trading bot, analyzing markets, or powering a financial app, the iTick API delivers comprehensive real-time and historical data for forex, stocks, futures, and funds. REST for bulk pulls, WebSocket for live updates—all with a clean JSON format and secure auth. Dive in with the Python snippets above, and you'll be up and running in no time.

Disclaimer: This is for informational purposes only and not investment advice. Markets are volatile—trade wisely.

For more details, check the official docs or GitHub repo.

Top comments (0)