This project implements a multi-threaded data integration pipeline for interacting with the Swissquote API, retrieving financial data for managed clients and injecting the data into a Microsoft SQL Server database. It is designed for financial analysts, advisors, and platform engineers looking to automate portfolio and transaction monitoring at scale.
This application automates the following tasks:
- Authenticates with the Swissquote REST API using a bearer token.
- Retrieves data across several dimensions (clients, positions, transactions, static lists).
- Parallelizes API calls across data types using Python threading.
- Transforms the nested API responses into structured tabular formats.
- Inserts the transformed data into a SQL Server database.
The solution is intended to enable seamless integration of Swissquote data into a financial platform or analytics pipeline.
Data is collected from the Swissquote Asset Management API, specifically:
- Managed clients and associated metadata.
- Current holdings (positions) by client.
- Historical transactions paginated per client.
- Static lists (securities metadata and taxonomy).
Base URL:
https://bankingapi.swissquote.ch/am-interface-v2/api/v1/
A valid API token is required for access.
The orchestration begins in main.py, executing the following sequence:
-
Initialization:
- The
Appclass initializes an internalSwissQuoteclient instance. - Configurations like retry/backoff are applied to ensure robust API interaction.
- The
-
Data Fetching:
- A list of client accounts is fetched first.
- Threads are launched to pull positions, transactions, and static lists concurrently.
- Transactions are paginated client-by-client for completeness.
-
Transformation:
- The raw nested responses are passed to a
transformer.Agentmodule. - Data is flattened and filtered to retain relevant fields only.
- The raw nested responses are passed to a
-
Storage:
- Final cleaned data is inserted into respective SQL Server tables.
- The
insert_data()utility handles upsert/append logic.
swissquote-client-main/
├── swissquote/ # API interaction logic and app orchestration
│ ├── client.py # Raw endpoint wrappers
│ └── app.py # Threaded data fetch logic
├── config/ # Environment setup and logging
├── database/ # MSSQL connectivity and helpers
├── transformer/ # Data cleaning and shaping
├── main.py # Pipeline entry point
├── .env.sample # Example environment configuration
├── Dockerfile # Containerization for deployment
Create a .env file based on .env.sample. Required variables include:
| Variable | Description |
|---|---|
LOG_LEVEL |
Logging verbosity |
TOKEN |
Swissquote API bearer token |
STATICLISTS_OUTPUT_TABLE, TRANSACTIONS_OUTPUT_TABLE, ... |
Output MSSQL table names |
MSSQL_* |
SQL Server authentication parameters |
INSERTER_MAX_RETRIES, REQUEST_MAX_RETRIES, REQUEST_BACKOFF_FACTOR |
Retry behavior and exponential backoff settings |
This project supports containerized deployment using Docker.
docker build -t swissquote-client .docker run --env-file .env swissquote-clientInstall Python dependencies using pip:
pip install -r requirements.txtKey libraries include:
requests: API communicationpandas: Data transformationSQLAlchemy: Database interactionfast-to-sql: High-speed SQL insertion
Ensure .env is correctly set with all required variables, then:
python main.pyLogs will reflect API calls, data transformations, and database writes.
This project is licensed under the MIT License. Access and use of Swissquote APIs must comply with their official data licensing and privacy terms.