Skip to main content

A robust stock, crypto, and forex classifier with async support.

Project description

ticker-classifier


GitHub Actions Workflow Status License Code style: black

Introduction

ticker-classifier is a small Python library for classifying ticker-like symbols (for example AAPL, BTC, EUR, GOLD) into a simple market/category representation. It uses Yahoo Finance for equities, CoinGecko for cryptocurrencies and a few heuristics for currencies/commodities. The output indicates the most likely category, a display name, market cap when available, and a yahoo_lookup value to fetch further data if desired.

Table of Contents 🗂

Key Features 🔑

  • Classify symbols as Equity, Crypto, Forex, Commodity, Index or Unknown.
  • Adds sector and industry metadata for many equity tickers (for example AAPL, NVDA).
  • Adds a compact company_profile payload for equity/ETF symbols (exchange, country, currency, industry group, website, market-cap category).
  • Uses multiple public APIs and simple heuristics to make robust decisions.
  • Provides both synchronous and asynchronous APIs.
  • Lightweight disk cache to avoid repeated lookups (TickerCache).

Installation ⚙️

Install from pypi using this command:

pip install ticker-classifier

Usage ⌨️

Basic synchronous usage:

from ticker_classifier.classifier import TickerClassifier

classifier = TickerClassifier()
symbols = ["AAPL", "BTC", "EUR", "GOLD", "UNKNOWN123"]
results = classifier.classify(symbols)
for r in results:
    print(r)

Example asynchronous usage:

import asyncio
from ticker_classifier.classifier import TickerClassifier

async def main():
    classifier = TickerClassifier()
    symbols = ["AAPL", "BTC", "ETH", "JPY"]
    results = await classifier.classify_async(symbols)
    for r in results:
        print(r)

asyncio.run(main())

The output for each symbol is a dictionary like:

{'category': 'EQUITY', 'ticker': 'AAPL', 'name': 'Apple Inc.', 'market_cap': 4029017227264, 'sector': 'Information Technology', 'industry': 'Electronic Equipment, Instruments & Components', 'company_profile': {'industry_group': 'Technology Hardware & Equipment', 'country': 'United States', 'exchange': 'NASDAQ Global Select', 'currency': 'USD', 'website': 'http://www.apple.com', 'market_cap_category': 'Mega Cap'}, 'yahoo_lookup': 'AAPL', 'alternatives': ['crypto'], 'source': 'api'}
{'category': 'crypto', 'ticker': 'BTC', 'name': 'Bitcoin', 'market_cap': 1736590593460.9607, 'yahoo_lookup': 'BTC-USD', 'alternatives': ['stock'], 'source': 'api'}
{'category': 'crypto', 'ticker': 'ETH', 'name': 'Ethereum', 'market_cap': 338145915081.1455, 'yahoo_lookup': 'ETH-USD', 'alternatives': ['stock'], 'source': 'cache'}
{'category': 'forex', 'ticker': 'JPY', 'name': 'JPY Currency', 'market_cap': None, 'yahoo_lookup': 'JPYUSD=X', 'alternatives': ['stock'], 'source': 'cache'}

Notes

  • The classifier caches positive classifications (non-Unknown) in an SQLite database (default ticker_cache.db) for 24 hours by default.
  • You can customize the cache filename and expiry by passing db_name and hours_to_expire to TickerClassifier.

API

  • ticker_classifier.classifier.TickerClassifier
  • classify(symbols: List[str]) -> List[dict] – synchronous classification.
  • classify_async(symbols: List[str]) -> List[dict] – async classification.
  • ticker_classifier.apis.yahoo.YahooClient – low-level Yahoo quote fetcher (sync + async helpers).
  • ticker_classifier.apis.coingecko.CoinGeckoClient – crypto lookup + market cap helpers (sync + async).
  • ticker_classifier.db.cache.TickerCache – tiny SQLite-backed cache used by TickerClassifier.

Development

Run formatting and linting tools you prefer (project uses black code style).

Run a quick smoke check by running the classifier.py module directly:

& .venv\Scripts\python.exe ticker_classifier\classifier.py

If you add tests, run them with your chosen test runner (e.g. pytest).

Release and Versioning

This package is published to PyPI through GitHub Actions:

  • Workflow: .github/workflows/publish.yml
  • Trigger: GitHub Release published
  • Publisher: pypa/gh-action-pypi-publish using trusted publishing (OIDC)

Release flow:

  1. Update version in pyproject.toml.
  2. Update ticker_classifier/__init__.py __version__ to match.
  3. Commit and push.
  4. Create a GitHub release with tag vX.Y.Z (or X.Y.Z).

The publish workflow validates that the release tag version matches pyproject.toml before uploading to PyPI.

Citation ✍️

If you use this project in your research, please cite as follows (adjust metadata accordingly):

@misc{ticker-classifier,
author  = {Stephan Akkerman},
title   = {ticker-classifier},
year    = {2025},
publisher = {GitHub},
howpublished = {\url{https://github.com/StephanAkkerman/ticker-classifier}}
}

Contributing 🛠

Contributions are welcome. Suggested workflow:

  1. Fork the repository and create a feature branch.
  2. Run tests and format your changes with black.
  3. Open a pull request with a clear description of the change.

Please open issues for feature requests or bugs and include a small reproducible example when possible.

https://github.com/StephanAkkerman/ticker-classifier/graphs/contributors

License 📜

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

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

ticker_classifier-0.1.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

ticker_classifier-0.1.2-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file ticker_classifier-0.1.2.tar.gz.

File metadata

  • Download URL: ticker_classifier-0.1.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ticker_classifier-0.1.2.tar.gz
Algorithm Hash digest
SHA256 eccd64e076d39e5f3d62cce61406c390be88c574158f1b92c09f4d5a9c903e02
MD5 f8328c6d92f2641dc8b9a7b1923fea8a
BLAKE2b-256 f2c47686fb7387ccf8e773050249f3f330223a61c748bc91c691700a3eb66378

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticker_classifier-0.1.2.tar.gz:

Publisher: publish.yml on StephanAkkerman/ticker-classifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ticker_classifier-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ticker_classifier-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b32d740b150241ff6ed21ae097c40ffb6992ddbf6b021095c2f7c5a6c04c6dba
MD5 9cc48bd0bd5ae5d7fcc9d15a2c139ba7
BLAKE2b-256 83d9b623149bc9ae872cfb952e142c42a3cb3f4c523353fadfae00d398590fb4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticker_classifier-0.1.2-py3-none-any.whl:

Publisher: publish.yml on StephanAkkerman/ticker-classifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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