Skip to main content

MCP server for interacting with Shioaji trading API

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mseep_mcp_server_shioaji-0.1.0.tar.gz (55.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mseep_mcp_server_shioaji-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file mseep_mcp_server_shioaji-0.1.0.tar.gz.

File metadata

  • Download URL: mseep_mcp_server_shioaji-0.1.0.tar.gz
  • Upload date:
  • Size: 55.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for mseep_mcp_server_shioaji-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d8557c0991e489a9bca595b9f01b2b67ecd6661f0583a3e35139909544b42831
MD5 47f706ff2de0b9d15cb1a5730e07ba54
BLAKE2b-256 23d61838a8fca2b319c40aa083621c1b2eb5b8f86d6ee46f8d6e39943fbbda75

See more details on using hashes here.

File details

Details for the file mseep_mcp_server_shioaji-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mseep_mcp_server_shioaji-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f921cfa868d5c0d83206e0ef984de2a7e673d222422f3f1b8530037a2e25fa66
MD5 23118f2a8458c5feead06a8f665448fc
BLAKE2b-256 2ea39ee0d86abcc07161e1851e9fac3ac59b8edf89e327da221e9efb40302683

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page