-
Notifications
You must be signed in to change notification settings - Fork 0
Development Guide
Victor Kaiuki edited this page Jun 16, 2026
·
1 revision
- Project Goal: Python SDK for the CFTC Commitments of Traders (COT) SODA2 API.
- Core Principle: Strict preservation of API-verified field names (including quirks) is paramount.
-
Architecture:
-
COTClient: Main entry point (Factory). -
COTQuery: Fluent builder for SODA2 queries (delegates tosodapy). -
COTAnalysis: Post-fetch DataFrame metrics (Net, Z-Scores). -
fields.py: Source of truth for API field constants.
-
-
Critical Constraints:
-
selectarg insodapy.getMUST be a comma-separated string (", ".join(list)). - Market filtering MUST use
upper()for case-insensitivity against ALL CAPS API data. - All field constants MUST match the API exact string (no fixing typos/quirks).
-
Primary interface. Manages connection configuration and acts as a factory for specific dataset query objects. Convenience methods (latest, history) wrap query building and execution.
Fluent API for building SODA2 queries.
- Accumulates state (
_where_clauses,_select_fields, etc.). -
execute()handles:- SODA2 parameter formatting.
- Conversion of response to
pandas.DataFrame. - Automated date and numeric type conversion.
-
_check_classification(): Enforces dataset-specific constraints (e.g., Legacy-only helper methods cannot be called on TFF queries).
Provides post-fetch computed metrics.
- Operates on a copied
pd.DataFrame. - Maps fields via
fields.pyconstants to ensure robust mapping of (long, short) columns.
Authoritative constants module. Do not modify field strings unless the CFTC API itself changes.
- Naming: Follow PEP 8 (snake_case functions/vars, PascalCase classes).
- Docstrings: Required for all public methods (Google Style).
-
Type Hints: Mandatory for all parameters and return types (
from __future__ import annotations). -
Logging: Use
loggingmodule, notprint. -
Error Handling: Use custom exceptions defined in
exceptions.py.
- Verify the exact field name from the live API (including typos).
- Add to the appropriate class (
LegacyFields,DisaggregatedFields, orTFFFields) insrc/cftc_cot/fields.py. - Add a comment noting any quirks (typos, missing suffixes).
- Define the mapping of fields (e.g., long_col, short_col) in
COTAnalysis.__init__for the relevant classification. - Implement the calculation method in
COTAnalysis.
This project uses Git-Flow.
-
master: Production-ready code. -
develop: Integration branch. - Feature/Bugfix branches: Created from
develop, merged back viagit flow finish.
Getting Started
API Reference
Field Reference
Guides
Reference