Integrating Nigerian (NG) Stock Market Data via iTick API – Real-time Quotes & Historical K-Line

Published: (February 9, 2026 at 11:20 AM EST)
4 min read
Source: Dev.to

Source: Dev.to

1. Preparation: API Setup Basics

1.1 Registration & API Token

iTick is currently one of the more reliable local financial data providers for the Nigerian market, offering both real‑time and historical data.

  1. Go to the official website and register a developer account.
  2. Complete email verification.
  3. You’ll receive your API_TOKEN (sometimes still called API_KEY in older docs). This token is the core credential for all subsequent API calls — keep it secure.

1.2 Environment Setup

I’m using Python 3.8+. You only need two main libraries for basic usage:

pip install requests pandas mplfinance
  • requests – for HTTP calls
  • pandas – for data structuring
  • mplfinance – optional, for candlestick charting

2. 实战1 – Fetching Real‑time Quotes

Current endpoint (2026)

GET /stock/quote?region=NG&code=xxxx

Important: The market code for Nigeria is now NG (not NSENG anymore).

Clean & Reusable Implementation

import requests
import time
from typing import Dict, Optional
import pandas as pd

class ITickNGAPI:
    """
    iTick API wrapper for Nigerian (NG) stock market data – 2026 version
    """
    def __init__(self, token: str):
        self.base_url = "https://api.itick.org"
        self.token = token
        self.headers = {
            "accept": "application/json",
            "token": self.token
        }

    def get_realtime_quote(self, stock_code: str) -> Optional[Dict]:
        """
        Get real‑time quote for a single stock
        :param stock_code: e.g. "DANGCEM"
        :return: quote dictionary or None if failed
        """
        for retry in range(3):
            try:
                url = f"{self.base_url}/stock/quote"
                params = {
                    "region": "NG",
                    "code": stock_code.upper()      # must be uppercase
                }

                response = requests.get(
                    url,
                    headers=self.headers,
                    params=params,
                    timeout=10
                )

                if response.status_code == 200:
                    result = response.json()
                    if result.get("code") == 0 and "data" in result:
                        quote = result["data"]
                        return {
                            "Symbol": quote["s"],
                            "Last Price": quote["ld"],
                            "Open": quote["o"],
                            "High": quote["h"],
                            "Low": quote["l"],
                            "Volume": quote["v"],
                            "Change": quote["ch"],
                            "Change %": quote["chp"],
                            "Timestamp": quote["t"],
                            "Trading Status": quote["ts"]   # 0=normal, 1=suspended, etc.
                        }
                    else:
                        print(f"No real‑time data found for {stock_code} or API error")
                        return None
                else:
                    print(f"Request failed – status {response.status_code} – retry {retry+1}")
                    time.sleep(1.5)

            except requests.exceptions.Timeout:
                print(f"Timeout – retry {retry+1}")
                time.sleep(1.5)
            except Exception as e:
                print(f"Exception: {str(e)}")
                return None

        return None

# ────────────────────────────────────────────────
if __name__ == "__main__":
    MY_TOKEN = "your_itick_token_here"
    api = ITickNGAPI(MY_TOKEN)

    quote = api.get_realtime_quote("DANGCEM")
    if quote:
        print("=== Nigerian (NG) Real‑time Quote ===")
        for k, v in quote.items():
            print(f"{k}: {v}")

3. Fetching Historical K‑line Data

    def get_historical_klines(
        self,
        stock_code: str,
        k_type: int = 8,
        limit: int = 30,
        end_timestamp: Optional[int] = None
    ) -> Optional[pd.DataFrame]:
        """
        Fetch historical k‑line data
        """
        try:
            url = f"{self.base_url}/stock/kline"
            params = {
                "region": "NG",
                "code": stock_code.upper(),
                "kType": k_type,
                "limit": limit
            }
            if end_timestamp:
                params["et"] = end_timestamp

            response = requests.get(
                url, headers=self.headers, params=params, timeout=12
            )

            if response.status_code == 200:
                result = response.json()
                if result.get("code") == 0 and "data" in result:
                    # Convert list of dicts to DataFrame
                    df = pd.DataFrame(result["data"])
                    # Rename columns for readability
                    df.rename(columns={
                        "t": "Timestamp",
                        "o": "Open",
                        "h": "High",
                        "l": "Low",
                        "c": "Close",
                        "v": "Volume"
                    }, inplace=True)
                    # Convert timestamp from ms to datetime (UTC)
                    df["Timestamp"] = pd.to_datetime(df["Timestamp"], unit="ms", utc=True)
                    return df
                else:
                    print(f"API returned error for {stock_code}: {result.get('msg')}")
                    return None
            else:
                print(f"HTTP error {response.status_code} when fetching k‑lines")
                return None
        except Exception as e:
            print(f"Exception while fetching k‑lines: {e}")
            return None

Usage Example

if __name__ == "__main__":
    api = ITickNGAPI(MY_TOKEN)

    # Daily K‑lines (last 30 days)
    df_daily = api.get_historical_klines("DANGCEM", k_type=8, limit=30)
    if df_daily is not None:
        print(df_daily.head())

        # Optional: candlestick chart with mplfinance
        import mplfinance as mpf
        plot_df = df_daily.copy()
        plot_df.set_index("Timestamp", inplace=True)

        mpf.plot(
            plot_df,
            type='candle',
            volume=True,
            title='DANGCEM (NG) Daily',
            ylabel='Price (NGN)',
            figratio=(16, 9),
            style='yahoo'
        )

4. Important Notes (2026 Edition)

  • Market code is NGnot NSENG anymore.
  • Authentication now uses a plain token header (no more Bearer api_key:secret).
  • All timestamps are millisecond Unix timestamps in UTC.
  • Free tier has rate limits — add sleep or upgrade plan for production use.
  • Prices are in Nigerian Naira (NGN).

5. Summary & Recommendations

Integrating Nigerian stock data is definitely less plug‑and‑play than U.S. or Chinese markets, but once you understand the quirks (market code change, timestamp handling, rate limits), it becomes manageable.

Key takeaways

  • Always implement timeout + retry logic.
  • Convert timestamps properly (UTC → your target timezone).
  • Use pandas early — it makes data cleaning and visualization much easier.

Disclaimer: This article is for technical reference only. It does not constitute investment advice. Investing involves risks.

Official Documentation

  • (link placeholder)

GitHub Organization

  • (link placeholder)

Hope this helps someone trying to access NGX data in 2026! Feel free to leave questions or share your own experience in the comments.

Good luck with your project!

0 views
Back to Blog

Related posts

Read more »