More and more friends are doing Asia-market quant work these days, and Japan is one you can't ignore — the TSE Prime (formerly the First Section) has over 2,000 listed companies and ranks in the global top three for average daily turnover. Compared with the US and Hong Kong markets, Japan's code system and trading rules are quite different, and it's easy to trip up when connecting to the data.

This post documents the full process of connecting to Japanese stock market data, focusing on Japan's code system and how it differs from other markets.

Basics of the Japanese Market

Japan's main exchange is the Tokyo Stock Exchange (TSE), which now has three segments: Prime (main board), Standard, and Growth. The Nikkei 225 index and the TOPIX (Tokyo Stock Price Index) you commonly hear about are both selected from the Prime segment.

Compared with other markets, the Japanese market has a few characteristics:

First, codes are 4-digit numbers. Unlike the US market's alphabetic codes (AAPL) or Hong Kong's 5-digit numeric codes (00700), Japanese stock codes are 4 digits. For example, 7203 is Toyota, 9984 is SoftBank, and 6758 is Sony.

Second, trading hours follow Japan Standard Time (JST). JST is 1 hour ahead of Beijing time. The exchange opens at Tokyo time 9:00-11:30 (before noon) and 12:30-15:00 (after noon). Watch out for timezone conversion when doing real-time monitoring.

Third, the region code is JP. It's not like US or HK — for the Japanese market you pass JP.

Quick Reference: Japanese Stock Codes

Here are the codes of common Japanese large-cap stocks, ready to use when connecting to data:

Code Company Industry
7203 Toyota Motor Automobile
9984 SoftBank Group Conglomerate
6758 Sony Group Electronics
8306 Mitsubishi UFJ Financial Group Banking
6861 Keyence Industrial automation
6098 Recruit Holdings Human resources
7974 Nintendo Gaming
4063 Shin-Etsu Chemical Chemicals

These are all Nikkei 225 constituents — highly liquid with stable data.

Fetching Japanese Stock Quotes via REST

Let's start with REST to confirm the data format.

import requests API_BASE = "https://api.itick.org" TOKEN = "your_token_here" headers = {"accept": "application/json", "token": TOKEN} # Fetch real-time quotes for Japanese stocks def get_jp_stock_quote(code): resp = requests.get( f"{API_BASE}/stock/quote", headers=headers, params={ "region": "JP", "code": code } ) return resp.json()["data"] # Fetch a few Japanese large-cap stocks stocks = ["7203", "9984", "6758"] for code in stocks: q = get_jp_stock_quote(code) sign = "+" if q["chp"] >= 0 else "" print(f"{code}: {q['ld']} ({sign}{q['chp']}%)") 

The returned fields are basically the same as other markets: ld latest price, chp change percentage, o/h/l open/high/low, v volume. These are enough for building a market dashboard.

Note: Japanese stock codes are 4-digit numbers, so pass them as strings ("7203"), not as numbers.

Subscribing to Japanese Stocks via WebSocket

The WebSocket subscription format is the same as the US market: two parameters, code$market.

import json import threading import time import websocket WS_URL = "wss://api.itick.org/stock" TOKEN = "your_token_here" authenticated = False def on_message(ws, message): global authenticated payload = json.loads(message) # First wait for authentication to succeed  if payload.get("resAc") == "auth" and payload.get("code") == 1 and not authenticated: authenticated = True # Japanese stock subscription format: code$market  ws.send(json.dumps({ "ac": "subscribe", "params": "7203$JP,9984$JP", "types": "quote" })) return if payload.get("resAc") == "pong": return data = payload.get("data") or {} if data.get("type") == "quote": sign = "+" if data["chp"] >= 0 else "" print(f"{data['s']}: {data['ld']} ({sign}{data['chp']}%)") 

Unlike the Indian market — Japan uses two parameters (7203$JP), not three. Because Japan's primary exchange is just the TSE, there's no need to specify NSE/BSE like in India.

Fetching K-Line Data

The K-line endpoint is the same as other markets, except you pass JP as the region.

def get_jp_kline(code, k_type=8, limit=100): """ k_type: 1=1min 2=5min 5=1hour 8=daily 9=weekly 10=monthly """ resp = requests.get( f"{API_BASE}/stock/kline", headers=headers, params={ "region": "JP", "code": code, "kType": k_type, "limit": limit } ) return resp.json()["data"] # Fetch the last 100 daily K-lines for Toyota daily = get_jp_kline("7203", k_type=8, limit=100) closes = [bar["c"] for bar in daily] # Calculate the 20-day moving average ma20 = sum(closes[-20:]) / 20 print(f"7203 latest close: {closes[-1]}, 20-day MA: {ma20:.2f}") 

The K-line returns standard OHLCV: t timestamp, o/h/l/c open/high/low/close, v volume. You can use these fields directly for technical analysis.

Notes on Japanese Market Integration

Codes are 4-digit numbers. Japanese stock codes are 4 digits (7203, 9984), which differs from both Hong Kong's 5-digit codes (00700) and the US's alphabetic codes (AAPL). At first I passed "07203" (with a leading zero) and got back empty data.

Trading hours are 1 hour ahead of China. Japan Standard Time (JST) is 1 hour ahead of Beijing time. The TSE opens at Tokyo time 9:00-11:30 and 12:30-15:00, which corresponds to Beijing time 8:00-10:30 and 11:30-14:00. Watch the timezone when doing real-time monitoring.

There's a midday break. The Japanese market has a 1-hour lunch break (Tokyo time 11:30-12:30) with no trade data during that period. Be careful when backtesting strategies — don't mistake the lunch break for a liquidity drought.

The subscription format uses two parameters. Japan, like the US, uses two parameters (7203$JP), not India's three-parameter format. Because Japan's primary exchange is just the TSE.

Timestamps are in milliseconds. All returned timestamps are in milliseconds. Treating them as seconds will give you a far-future time, so remember to divide by 1000.

Complete Script: Japanese Stock Market Monitor

Putting the earlier sections together, here's the final complete script:

import json, time, threading, requests, websocket API_BASE = "https://api.itick.org" WS_URL = "wss://api.itick.org/stock" TOKEN = "your_token_here" headers = {"accept": "application/json", "token": TOKEN} # Japanese stock watchlist watchlist = ["7203", "9984", "6758"] # Fetch snapshot on startup print("=== Japanese Stock Snapshot ===") for code in watchlist: r = requests.get(f"{API_BASE}/stock/quote", headers=headers, params={"region": "JP", "code": code}).json()["data"] sign = "+" if r["chp"] >= 0 else "" print(f" {code}: {r['ld']} ({sign}{r['chp']}%)") # Real-time WebSocket push authenticated = False def on_message(ws, message): global authenticated payload = json.loads(message) if payload.get("resAc") == "auth" and payload.get("code") == 1 and not authenticated: authenticated = True params = ",".join(f"{c}$JP" for c in watchlist) ws.send(json.dumps({ "ac": "subscribe", "params": params, "types": "quote" })) threading.Thread(target=heartbeat, args=(ws,), daemon=True).start() return if payload.get("resAc") == "pong": return data = payload.get("data") or {} if data.get("type") == "quote": sign = "+" if data["chp"] >= 0 else "" print(f"[LIVE] {data['s']}: {data['ld']} ({sign}{data['chp']}%)") def heartbeat(ws): while True: time.sleep(30) ws.send(json.dumps({"ac": "ping", "params": str(int(time.time() * 1000))})) ws = websocket.WebSocketApp(WS_URL, header=[f"token: {TOKEN}"], on_message=on_message) ws.run_forever() 

Once this script runs, you'll first see a snapshot of Japanese stocks before the market opens, then real-time price and change updates throughout the session.

Summary

The technical framework for connecting to Japanese stock data is similar to the US market — REST for snapshots and historical data, WebSocket for real-time push. The main differences are the code system (4-digit numbers), trading hours (1 hour ahead of China), and the midday break. These details are easy to overlook unless you actually step on each pitfall.

Reference docs: https://docs.itick.org/websocket/stocks
WebSite:https://itick.org
GitHub: https://github.com/itick-org/