Skip to main content

MCP Server for Shioaji

A Model Context Protocol (MCP) server that provides AI assistants with access to Shioaji trading API for the Taiwanese financial market.

Overview

This server implements the MCP protocol to expose Shioaji API functionality as tools that can be used by AI assistants. It allows AI models to:

  • Retrieve current stock prices
  • Fetch historical data
  • List available stocks
  • And more...

Installation

Prerequisites

  • Python 3.10 or higher
  • uv (fast Python package manager)

Using uv

uv sync

Configuration

Before running the server, you need to configure your Shioaji API credentials. There are two ways to do this:

Environment Variables

Set the following environment variables:

export SHIOAJI_API_KEY="your_api_key"
export SHIOAJI_SECRET_KEY="your_secret_key"

Using .env File

Create a .env file in the root directory with the following content:

SHIOAJI_API_KEY=your_api_key
SHIOAJI_SECRET_KEY=your_secret_key

Running the Server

Start the server with:

uv run mcp-server-shioaji

The server will start on http://0.0.0.0:8000 by default.

Available Tools

The server exposes the following tools via MCP:

get_stock_price

Get the current price of a stock by its symbol.

{
  "tool": "get_stock_price",
  "params": {
    "symbols": "TW.2330,TW.2317"
  }
}

Response will include price information for the requested stocks, including open, high, low, close prices, volume, and other trading data.

get_kbars

Fetch K-Bar (candlestick) data for a stock within a date range.

{
  "tool": "get_kbars",
  "params": {
    "symbol": "TW.2330",
    "start_date": "2023-12-01",
    "end_date": "2023-12-15"
  }
}

If start_date is not provided, it defaults to today. If end_date is not provided, it defaults to the same as start_date.

scan_stocks

Scan stocks based on various ranking criteria.

{
  "tool": "scan_stocks",
  "params": {
    "scanner_type": "VolumeRank",
    "ascending": false,
    "limit": 10
  }
}

Supported scanner types:

  • VolumeRank - Ranking by trading volume
  • AmountRank - Ranking by trading amount
  • TickCountRank - Ranking by number of transactions
  • ChangePercentRank - Ranking by percentage change
  • ChangePriceRank - Ranking by price change
  • DayRangeRank - Ranking by daily range

Default limit is 20, and results are sorted in descending order by default (set ascending to true for ascending order).

Development

Project Structure

mcp-server-shioaji/
├── src/
│   └── mcp_server_shioaji/
│       ├── __init__.py      # Package entry point
│       └── server.py        # MCP server implementation
├── pyproject.toml           # Project metadata and dependencies
└── README.md                # This file

Adding New Tools

To add new Shioaji functionality, modify server.py and add new tool definitions using the @mcp.tool decorator.

License

MIT

Acknowledgements

  • Shioaji - The Python wrapper for SinoPac's trading API
  • MCP - Model Context Protocol

Metadata

Release files for iflow-mcp_sinotrade_mcp-server-shioaji 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_sinotrade_mcp-server-shioaji 0.1.0
File Size Uploaded
iflow_mcp_sinotrade_mcp_server_shioaji-0.1.0.tar.gz 59.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_sinotrade_mcp-server-shioaji 0.1.0
File Interpreter ABI Platform
iflow_mcp_sinotrade_mcp_server_shioaji-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 68.1 kB

Release files / iflow_mcp_sinotrade_mcp_server_shioaji-0.1.0.tar.gz

Download URL iflow_mcp_sinotrade_mcp_server_shioaji-0.1.0.tar.gz
Size 59.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8fb7ff5d3dbbfb6b16b472228aff65e1d0c2edc98a22c4b596d6244f15cab24e
BLAKE2b-256 checksum
How to use checksums
fa3bd64713cf12e70555c8ca786aff113c6d23a930a18e2394bd3639c84f0804
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iflow_mcp_sinotrade_mcp_server_shioaji-0.1.0-py3-none-any.whl

Download URL iflow_mcp_sinotrade_mcp_server_shioaji-0.1.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9be6b83da778884894fa9c0d1f177a1d2d5c8b97af3ab85f17f5a18d34d0619
BLAKE2b-256 checksum
How to use checksums
7c28a11ff84135778b2f55d8e08501ef5fe61b270e46970aba74ef0ace1462bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page