Skip to main content

cotbias

PyPI version Python versions License: MIT

Official Python SDK and Model Context Protocol (MCP) Server for the CFTC Commitment of Traders (COT) Bias Terminal Quant API.

Access institutional positioning metrics, 156-week historical timeseries across multiple CFTC report families, cross-market positioning screeners, and AI-driven market regime & attribution analysis directly in Python and in AI assistants (Claude Desktop, Cursor, Cline).


Installation

Python SDK (Batteries-included with Pandas)

pip install cotbias

With Model Context Protocol (MCP) Server

For connecting into Claude Desktop, Cursor, or Cline:

pip install "cotbias[mcp]"

🤖 Model Context Protocol (MCP) Server

Connect your Quant API key directly into Claude Desktop or Cursor IDE:

{
  "mcpServers": {
    "cotbias": {
      "command": "uvx",
      "args": ["cotbias[mcp]", "cotbias-mcp"],
      "env": {
        "COT_API_KEY": "cot_live_YOUR_ACTUAL_API_KEY"
      }
    }
  }
}

See docs/mcp.md for full configuration details, available tools (get_market_snapshot, get_ai_inference, get_timeseries, scan_markets, list_markets), and quota preservation caching.


Quickstart

Get your API key at cot-bias-terminal.com. Set it as an environment variable:

export COT_API_KEY="cot_live_..."

1. Fetch Positioning Timeseries into Pandas

from cotbias import CotClient

with CotClient() as cot:
    # Pull 156 weeks of combined futures & options data for Gold (GC) as a Pandas DataFrame
    df = cot.timeseries.get("GC", contract_type="futopt", lookback_weeks=156, as_dataframe=True)
    print(df[["commercial_net", "cot_52w_commercial", "z_score_156w_commercial"]].tail())

2. AI Market Regime & Qualitative Attribution

from cotbias import CotClient

with CotClient() as cot:
    inf = cot.inference.get("GC")
    print(f"Asset: {inf.symbol}")
    print(f"Bias: {inf.ai_bias_score} | Regime: {inf.regime_status}")
    print(f"Primary Driver: {inf.primary_driver} ({inf.momentum})")
    print(f"Macro Rationale: {inf.qualitative_attribution.macro_rationale}")

3. Cross-Market Positioning Screener

from cotbias import CotClient

with CotClient() as cot:
    # Find all markets where AI bias is Bullish and smart money is entering new longs
    res = cot.screener.scan(ai_bias_score="Bullish", momentum="New Longs (OI Expanding)")
    for item in res.results:
        print(f"{item.symbol}: {item.ai_bias_score} ({item.regime_status})")

4. Automatic Retries & Network Resilience

The SDK automatically retries transient 5xx errors, network timeouts, and transient rate limits with exponential backoff and jitter:

from cotbias import CotClient

# Default max_retries=3. Set to 0 to disable or adjust for custom pipelines
with CotClient(max_retries=5, timeout=20.0) as cot:
    markets = cot.markets.list()

5. Asynchronous Client (FastAPI / Bots)

import asyncio
from cotbias import AsyncCotClient


async def main():
    async with AsyncCotClient() as cot:
        # Fetch multiple markets concurrently
        gold_task = cot.timeseries.get("GC")
        sp500_task = cot.timeseries.get("ES")
        gold_ts, sp500_ts = await asyncio.gather(gold_task, sp500_task)
        print("Gold rows:", gold_ts.count, "| S&P 500 rows:", sp500_ts.count)


asyncio.run(main())

Error Handling

All API errors inherit from CotApiError:

from cotbias import CotClient
from cotbias.exceptions import (
    AuthenticationError,
    NotFoundError,
    PermissionDeniedError,
    RateLimitExceededError,
)

try:
    with CotClient() as cot:
        cot.timeseries.get("INVALID_TICKER")
except NotFoundError as e:
    print(f"Asset not found: {e.message}")
except RateLimitExceededError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds.")
except AuthenticationError as e:
    print("Invalid or missing API key.")

License

MIT License. Developed for quantitative traders, portfolio managers, and market researchers.

Metadata

Release files for cotbias 0.2.1

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

Source distribution (sdist)

Source distribution for cotbias 0.2.1
File Size Uploaded Provenance Actions
cotbias-0.2.1.tar.gz 164.1 kB With provenance Details for cotbias-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 184.1 kB

Release files / cotbias-0.2.1.tar.gz

Download URL cotbias-0.2.1.tar.gz
Size 164.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8f17cf1c8ea87cf463b5044a163f49a292951b7de170214e002b088b0ee1fe97
BLAKE2b-256 checksum
How to use checksums
3055b710581f1774cfcc5467ffa3959d67701226e6396215eb60a8915805b7f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Release files / cotbias-0.2.1-py3-none-any.whl

Download URL cotbias-0.2.1-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
647e7f087c1829d590db16b5c72f88ba26787e394a41315d58c0bd9596a65731
BLAKE2b-256 checksum
How to use checksums
ed9478a74c8cf49af85ee7ef2f5fe0bf02ba318b59f2e4502cc141d38ee5fb5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

Security for cotbias 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cotbias-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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