Skip to main content

CFTC COT SDK

PyPI License: MIT

A robust, verified Python SDK for accessing, querying, and analyzing CFTC Commitments of Traders (COT) data.

Overview

The cftc-cot SDK provides a fluent, production-ready interface for the CFTC's SODA2 API. It simplifies the complexity of querying 6 different CFTC datasets, handles API-specific naming quirks, and provides powerful post-fetch analysis tools.

Key Features

  • Fluent API: Chainable query building for intuitive data retrieval.
  • Production-Tested: Verified field mappings and API interactions against live CFTC data.
  • Advanced Analysis: Net Positions, Z-Scores, the classic 0–100 COT Index, extreme positioning detection, long/short ratios, percentile ranks, and week-over-week change.
  • Caching: Optional in-memory or persistent disk caching of API responses (COT data updates weekly, so a 24h TTL eliminates redundant requests).
  • Resilient Networking: Automatic retry with exponential backoff on transient API failures (429/5xx).
  • Command-Line Interface: A cftc-cot CLI for quick lookups without writing Python.
  • Robust Field Handling: Preserves official API quirks (typos, naming inconsistencies) using structured field constants.
  • Production Ready: Full type hinting, comprehensive exception hierarchy, and rate-limiting support via app tokens.

Installation

pip install cftc-cot-soda

# With disk caching support:
pip install cftc-cot-soda[cache]

Quick Start

from cftc_cot import COTClient, COTAnalysis

# Initialize client
client = COTClient()

# Query: 52-week history of Crude Oil positioning
df = client.legacy().market("Crude Oil").last_n_weeks(52).execute()

# Analyze: Compute net positions and the COT Index
analysis = COTAnalysis(df, classification="legacy")
df_analyzed = analysis.cot_index(window=52)

print(df_analyzed[['report_date_as_yyyy_mm_dd', 'noncomm_net', 'noncomm_net_cot_index']].tail())

Caching

# In-memory cache (per-process) or persistent disk cache.
client = COTClient(cache="memory")
client = COTClient(cache="disk", cache_dir="./cot_cache", cache_ttl=86400)

Command-Line Interface

cftc-cot latest  --dataset legacy --market "Crude Oil"
cftc-cot history --dataset legacy --market "Crude Oil" --weeks 52
cftc-cot markets --dataset legacy
cftc-cot index   --dataset legacy --market "Crude Oil" --window 156

# Choose output format and enable caching:
cftc-cot --format json --cache memory latest --dataset legacy --market "Gold"

Documentation

For a complete API reference, guides, and dataset specifications, please visit our GitHub Wiki.

License

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

Metadata

Release files for cftc-cot-soda 0.2.0

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

Source distribution (sdist)

Source distribution for cftc-cot-soda 0.2.0
File Size Uploaded
cftc_cot_soda-0.2.0.tar.gz 18.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cftc-cot-soda 0.2.0
File Interpreter ABI Platform
cftc_cot_soda-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.5 kB

Release files / cftc_cot_soda-0.2.0.tar.gz

Download URL cftc_cot_soda-0.2.0.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f1f04763b9ebb36278bdee1c693ff84b0b96bd67309e56906195f8ede0ab9e76
BLAKE2b-256 checksum
How to use checksums
a48e93d18d416ddac00f9056eb6d92478cae38b90edbc12e2a0270e39510110e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / cftc_cot_soda-0.2.0-py3-none-any.whl

Download URL cftc_cot_soda-0.2.0-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a73f85e785d78040eee6f7c5157708ac95edb5278ca930d4768411bf0631513
BLAKE2b-256 checksum
How to use checksums
90c0882fe0603592e85e55a77c6ede6d90a2f1c545e72600e0c01d4addd6b031
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.1

2 release files

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