DEV Community

Cover image for Swiss Stock Market API Integration Tutorial: Get Real-Time Quotes & Historical K-Line
San Si wu
San Si wu

Posted on

Swiss Stock Market API Integration Tutorial: Get Real-Time Quotes & Historical K-Line

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")
print("Nestlé real-time market data:", quote)
Enter fullscreen mode Exit fullscreen mode

The returned data structure is very clean and the field names are intuitive. No extra parsing is required. All core quote fields are output directly, making it ideal for quickly integrating with a front-end dashboard.

4. Example 2: Pull Novartis Historical K-Line for Trend Review

Real-time quotes meet monitoring needs, while historical K-lines are essential for quant review and trend analysis. I often pull the last 90 trading days of daily data for trend judgment.

The SDK’s K-line interface is very user-friendly. The kType parameter is unified across all markets and is easy to remember:

  • 1: 1-minute K-line | 2: 5-minute K-line | 3: 15-minute K-line | 4: 30-minute K-line
  • 5: hourly | 8: daily | 9: weekly | 10: monthly

For example, to get the last 90 days of daily K-line data for Novartis (NOVN):

# Get the last 90 days of daily K-line data for Novartis
kline = client.get_stock_kline("CH", "NOVN", 8, 90)
print("Novartis historical daily data:", kline)
Enter fullscreen mode Exit fullscreen mode

The returned data includes complete fields: open (o), high (h), low (l), close (c), volume (v), turnover (tu), timestamp (t). The best part is this field standard works for US stocks, Hong Kong stocks, A-shares, and European markets. I can use the same parsing logic for all global market K-line data, saving a lot of compatibility effort.

5. Example 3: WebSocket Long Connection for Real-Time Push Data

REST APIs are good for on-demand polling, but asset dashboards need dynamic real-time updates. Polling wastes quota and is less efficient. For this use case, WebSocket long connections are the best choice.

iTick SDK includes a mature WebSocket wrapper. You don’t need to write low-level connection logic. Just configure callback functions and you can subscribe to multiple symbols in real time. The example below subscribes to Nestlé, Novartis, and Roche on the Swiss market:

import time

# Market data push callback
def on_message(message):
    print(f"Real-time market update: {message}")

# Error callback
def on_error(error):
    print(f"Connection error alert: {error}")

# Bind callback methods
client.set_message_handler(on_message)
client.set_error_handler(on_error)

# Open stock WebSocket long connection
client.connect_stock_websocket()

# Batch subscribe: format is SYMBOL$MARKET, multiple symbols separated by commas
client.send_websocket_message(
    '{"ac":"subscribe","params":"NESN$CH,NOVN$CH,ROG$CH","types":"quote"}'
)

# Listen continuously for 30 seconds, adjust duration as needed
time.sleep(30)
# Check connection status
print("WebSocket connected:", client.is_websocket_connected())
# Close connection
client.close_websocket()
Enter fullscreen mode Exit fullscreen mode

Subscriptions are flexible. The types parameter can switch between quote real-time quotes, tick trade-by-trade data, depth order book depth, and kline real-time K-line push. This covers market analysis, intraday monitoring, and real-time K-line update needs. One connection can support up to 500 subscribed symbols, which is enough for personal and small-team use.

6. Practical Experience: Stability Pitfalls Summary

For market monitoring tools, the biggest concerns are disconnects, data interruptions, and lost subscriptions after reconnect. With some smaller APIs I had to implement heartbeat keepalive, reconnection, and subscription recovery myself. That wasted time and effort.

In practice, iTick’s SDK includes a full stable mechanism and is very developer-friendly:

  • Default 30-second heartbeat keepalive to maintain connections
  • Automatic retry after unexpected disconnect, retrying every 5 seconds up to 10 times
  • Automatic recovery of subscriptions after reconnect, with no manual resubscription needed

I tested it overnight, and the connection stayed stable with no disconnects. Push latency was very low and fully met personal dashboard stability needs.

7. Key Detail: Handle Swiss Franc Pricing Correctly

This is a common beginner pitfall! All Swiss market symbols are priced in Swiss francs (CHF). If you compare them directly with USD or CNY priced assets in the same dashboard, you will get misleading results.

My solution is to pair it with an FX API to get real-time CHF/USD and CHF/CNY exchange rates, then do currency conversion at the front-end display layer and label the currency clearly. The FX calls use the same API style as stock quotes, so the learning curve is low and it solves multi-currency display consistency.

8. Summary

Overall, integrating Swiss market data with iTick offers the biggest advantages of unified standards, low learning cost, and strong stability. You don’t need to adapt to different market API rules; one codebase can cover global equities, FX, and crypto. That greatly reduces duplicated development effort.

For individual developers building global asset dashboards, small quant review tools, or cross-border asset monitoring, this solution is fully sufficient. The free quota supports normal development and use without needing expensive professional APIs.

I will continue integrating German and UK market data, and I’ll keep updating these practical notes. If you need it, you can refer to:

GitHub: https://github.com/itick-org/python-sdk
Documentation: https://docs.itick.org/sdk/python-sdk/

Top comments (0)