Getting Started¶
Welcome to cotbias, the official Python client and Model Context Protocol (MCP) server for the COT Bias Terminal Quant API.
This guide walks you through account requirements, installation options, API key configuration, and your first request.
๐ Prerequisites¶
- Python 3.10 or higher: Check your version with
python --version. - Quant Tier API Key: Access to the programmatic API and MCP endpoints requires an active Quant Tier subscription from COT Bias Terminal.
๐ฆ Installation¶
Choose the installation option that best fits your workflow:
Installs the Model Context Protocol server for Claude Desktop, Cursor IDE, or Cline:
๐ Authentication¶
The client authenticates every request using the X-API-Key HTTP header.
1. Environment Variable (Recommended)¶
Set the COT_API_KEY environment variable in your terminal session or shell profile (~/.zshrc, ~/.bashrc):
If you use .env files in your project, load it using python-dotenv:
from dotenv import load_dotenv
from cotbias import CotClient
load_dotenv()
# CotClient automatically reads COT_API_KEY from os.environ
client = CotClient()
2. Explicit Key Argument¶
Alternatively, pass the key directly when instantiating the client:
Security Best Practice
Never commit hardcoded API keys into version control. Use environment variables or secret managers (such as AWS Secrets Manager or GCP Secret Manager).
๐ Client Lifecycle¶
Using Context Managers (Recommended)¶
Both CotClient (synchronous) and AsyncCotClient (asynchronous) implement context managers. This ensures HTTP/2 connection pools and sockets are cleanly closed when done:
Manual Connection Cleanup¶
If you maintain a long-running client instance (e.g. inside a Flask or FastAPI dependency container):
๐งช Verifying Your Connection¶
Run this quick verification script to ensure your key and network connection are working properly:
import os
from cotbias import CotClient
from cotbias.exceptions import AuthenticationError, PermissionDeniedError
try:
with CotClient() as client:
markets = client.markets.list(sector="Equity")
print(f"โ
Success! Connected to COT Bias API. Found {len(markets)} equity contracts.")
for m in markets[:3]:
print(f" - {m.symbol} ({m.name}): CFTC #{m.cftc_code}")
except AuthenticationError:
print("โ Authentication failed: Please verify your COT_API_KEY.")
except PermissionDeniedError:
print("โ Access denied: Your account requires an active Quant Tier subscription.")
except Exception as e:
print(f"โ Connection error: {e}")
๐งญ Next Steps¶
- Timeseries Guide: Query up to 156 weeks of historical positioning across Legacy, Disaggregated, and TFF reports.
- AI Inference Guide: Interpret institutional market regimes, directional scores, and macro commentary.
- Multi-Market Screener: Filter contracts by crowdedness risk, smart money accumulation, and momentum.
- MCP Server Setup: Connect COT positioning directly into Claude Desktop or Cursor IDE.