Skip to main content

twse

A Python package for querying real-time stock information from Taiwan Stock Exchange (TWSE).

Features

  • Real-time stock data querying from TWSE
  • Support for single or multiple stock symbols
  • Comprehensive stock information including:
    • Current price, volume, and price changes
    • Open, high, low prices
    • Best bid/ask prices
    • Company information
  • Formatted output suitable for display (including Telegram MarkdownV2 format)

Installation

Requires Python 3.11 or higher.

pip install twse

Usage

Basic Usage

from twse import get_stock_info_sync

# Query single stock (TSMC - 2330)
response = get_stock_info_sync("2330")
print(response.pretty_repr())

# Query multiple stocks (TSMC - 2330 and Hon Hai - 2317)
response = get_stock_info_sync(["2330", "2317"])
print(response.pretty_repr())

Async Usage

import asyncio

from twse import get_stock_info


async def main() -> None:
    # Query single stock (TSMC - 2330)
    response = await get_stock_info("2330")
    print(response.pretty_repr())


if __name__ == "__main__":
    asyncio.run(main())

Example Output

The pretty_repr() method formats the output in Telegram MarkdownV2 format:

⏰ 2024-03-21 14:30:00

📊 台積電 (2330)
Open: 735.00
High: 738.00
Low: 732.00
Last: 735.00
Change: 🔺 +0.68%
Volume: 15,234,567

Stock Information Fields

The StockInfo class provides access to various fields:

  • symbol: Stock symbol
  • name: Stock name
  • full_name: Full company name
  • last_price: Current trading price
  • open_price: Opening price
  • high_price: High price
  • low_price: Low price
  • accumulated_volume: Trading volume
  • best_ask_price: Best ask price
  • best_bid_price: Best bid price
  • And more...

Development

Setup

  1. Clone the repository
  2. Install dependencies using uv:
    uv pip install -r requirements.txt
    

Commands

  • Run tests:
    make test
    
  • Run linter:
    make lint
    

Pre-commit Hooks

The project uses pre-commit hooks for code quality. Install them with:

pre-commit install

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for twse 0.5.1

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

Built distribution (wheel)

Table of built distributions (wheels) for twse 0.5.1
File Interpreter ABI Platform
twse-0.5.1-py3-none-any.whl Python 3 none any Details

Release files / twse-0.5.1-py3-none-any.whl

Download URL twse-0.5.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b560c3ebd6da38b5e45a53d4583625b7d9beaed37f98e7938ef072532091f5d2
BLAKE2b-256 checksum
How to use checksums
3b69a9a16cd564d0137db3a4b83dca3653df3b124561c2efaaac514409da8bb4
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":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.5.1 This release

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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