DEV Community

Cover image for How to Access Swiss Stock Market Data via API – Live Prices & Historical Candlesticks for SMI Top Stocks (NESN, NOVN, ROG)
San Si wu
San Si wu

Posted on

How to Access Swiss Stock Market Data via API – Live Prices & Historical Candlesticks for SMI Top Stocks (NESN, NOVN, ROG)

Recently I have been building a lightweight global asset monitoring dashboard. I quickly solved the data interfaces for US stocks, A-shares, and Hong Kong stocks, but the market data for the Swiss Exchange (SIX) was the one that kept getting stuck.

Anyone building global asset allocation or personal wealth management tools knows the Swiss market hides many heavyweight blue-chips — Nestlé, Novartis, Roche. These are classic holdings in a global portfolio. Most free data sources do not cover SIX, and paid APIs are too expensive. Before, I had to make do with static data and couldn’t support real-time monitoring or historical trend review.

After testing multiple financial data APIs, I finally used iTick’s Python SDK to successfully fetch Swiss market real-time quotes, historical K-lines, and WebSocket push data. The integration process is very simple, requires no complex configuration, and the free quota is enough for personal projects. Here I record the full implementation process so others can avoid pitfalls and get up and running quickly.

1. Why You Must Integrate Swiss Market Data

Many personal quant and asset dashboard projects tend to ignore the Swiss market, but SIX’s core names are highly valuable:

  • Nestlé (NESN): global consumer food leader, defensive asset benchmark
  • Novartis (NOVN), Roche (ROG): global pharma giants, core healthcare allocation
  • UBS Group (UBSG): major international financial institution

These low-volatility, high-stability overseas blue chips are essential for diversification. If you build global asset visualization, cross-border backtesting, or personal holdings monitoring, missing Swiss market data leaves the asset allocation picture incomplete.

I used static end-of-day data for a long time. That prevented me from seeing intraday fluctuations or automatically pulling K-lines for trend analysis. The user experience was terrible. After integrating a real-time API, I finally closed the loop for mainstream global market coverage.

2. Preparation: Account Registration and SDK Installation

The integration is very lightweight and does not require complicated approvals. Individual developers can get started quickly:

  1. Go to the iTick official website (https://itick.org) to register an account. In the personal console you can get an API Token. One token works for both REST and WebSocket APIs, so no separate application is needed.
  2. Install the official Python SDK locally in one command, compatible with mainstream Python 3 versions:
pip install itick-sdk
Enter fullscreen mode Exit fullscreen mode

New users receive free usage quota. That is enough for personal dashboards, small-scale data review, and daily market monitoring without needing to upgrade to paid service.

3. Example 1: Fetch Nestlé Real-Time Quote in Python

iTick uses a unified region coding scheme across global markets. The Swiss market is identified as CH, and stock symbols use the official SIX codes directly, so no secondary mapping is needed.

Just a few lines of code fetch Nestlé real-time market data, including current price, open, high, low, and other core fields:

from itick.sdk import Client

# Replace with the real token from your personal console
token = "your_api_token"
client = Client(token)

# Get Nestlé (NESN) real-time quote on the Swiss market
quote = client.get_stock_quote("CH", "NESN")

# Practical Guide: Accessing US Stock Quant Data — Low-Cost Real-Time Quotes and Historical K-Lines
Enter fullscreen mode Exit fullscreen mode

Environment Setup and Data Source Selection

First, install the SDK:

pip install itick-sdk
Enter fullscreen mode Exit fullscreen mode

Then register an account at https://itick.org and obtain an API token from the dashboard. You will need this token for every request.

Why choose iTick? There are many excellent financial data APIs, but iTick's free tier already covers major markets including US, HK, and A-share real-time quotes and historical K-lines. The REST API allows 5 calls per minute, and WebSocket supports 1 connection with subscriptions for 3 symbols on the free tier. This quota is sufficient for learning and prototype testing, and latency is acceptable in practice. If you need higher frequency, paid plans offer configurations such as 600 calls/minute and multiple connections.


1. Fetching Real-Time Quotes (REST)

from itick.sdk import Client

token = "your_api_token"
client = Client(token)

# Use "US" for the US market
quote = client.get_stock_quote("US", "AAPL")
print("Latest Apple quote:", quote)

tick = client.get_stock_tick("US", "TSLA")
print("Tesla tick:", tick)
Enter fullscreen mode Exit fullscreen mode

Set region to "US"; the SDK will build the full request. Returned fields include ld (latest price), o/h/l (open/high/low), ch/chp (price change and percent change), which match typical broker app fields.


2. Fetching Historical K-Lines

US stocks support multiple intervals from 1-minute to monthly. The kType values are:

kType Meaning
1 1 minute
2 5 minutes
3 15 minutes
4 30 minutes
5 1 hour
8 1 day
9 1 week
10 1 month

Pull the last 10 five-minute K-lines for Apple:

kline = client.get_stock_kline("US", "AAPL", kType=2, limit=10)
print("K-line data:", kline)
Enter fullscreen mode Exit fullscreen mode

Each K-line includes t (timestamp), o/h/l/c (open/high/low/close), v (volume), and tu (turnover). That’s sufficient for basic charting.


3. WebSocket Real-Time Push

Polling REST endpoints can hit rate limits and is inefficient for live monitoring. Use WebSocket so the server pushes updates. The iTick SDK wraps connection handling, heartbeat, and auto-reconnect.

Example subscribing to Apple and Tesla quotes and order book depth:

import time

def on_message(message):
    print(f"Received push: {message}")

def on_error(error):
    print(f"WebSocket error: {error}")

client.set_message_handler(on_message)
client.set_error_handler(on_error)

# Establish WebSocket connection
client.connect_stock_websocket()

# Subscribe to AAPL (US) and TSLA (NASDAQ on US market)
subscribe_msg = '{"ac":"subscribe","params":"AAPL$US,TSLA$NASDAQ$US","types":"quote,depth"}'
client.send_websocket_message(subscribe_msg)

# Keep the connection for a while; replace with an event loop in production
time.sleep(30)

print("WebSocket connected:", client.is_websocket_connected())
client.close_websocket()
Enter fullscreen mode Exit fullscreen mode

Subscription parameters:

  • params format: SYMBOL$REGION. If you need to disambiguate exchanges within a market, use SYMBOL$EXCHANGE$REGION.
  • types can include tick (trade-by-trade), quote (real-time quote), depth (top-10 order book), and kline (K-line push; note 1-minute kline@1 may be restricted to premium plans).

The SDK provides a default heartbeat (ping every 30s) and automatic reconnection on network blips (retry every 5s up to 10 times). Subscriptions are restored after reconnect.

FAQ

Q: Is the free tier enough for daily development?

A: For learning, prototyping, or low-frequency strategies, 5 REST calls/min and 1 WebSocket connection are usually sufficient. Upgrade when you need to monitor more symbols or higher-frequency data.

Q: How is latency?

A: iTick reports millisecond-level push latency. In my tests, delay is small and suitable for monitoring and real-time computation; actual latency depends on server location and network.

Q: How many symbols can one WebSocket connection subscribe to?

A: A single connection supports up to 500 symbols. For thousands of symbols, split across connections or request higher limits from support.

Conclusion

This article demonstrates accessing US real-time quotes and historical K-lines using the iTick Python SDK: use REST for on-demand queries and WebSocket for continuous real-time feeds. Together they support stock selection, monitoring, and backtesting workflows. From registration to receiving the first WebSocket push, you can get up and running in about 30 minutes.

For more field details, batch endpoints, and SDKs in Java/Go/Node.js, see the iTick docs: https://docs.itick.org

Top comments (0)