# Cftc Cot Reports (`khnaami/cftc-cot-reports`) Actor

Production-ready serverless Apify Actor providing automated COT scraping, pandas data normalization, and weekly institutional orderflow rankings.

- **URL**: https://apify.com/khnaami/cftc-cot-reports.md
- **Developed by:** [khalid naami](https://apify.com/khnaami) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## CFTC Commitment of Traders (COT) Reports & Orderflow Analytics 📈

An automated, serverless **Apify Actor** that scrapes, cleans, and analyzes weekly **Commitment of Traders (COT)** reports from the official [U.S. Commodity Futures Trading Commission (CFTC)](https://www.cftc.gov/).

Designed for Forex traders, Commodity analysts, Crypto investors, and Algorithmic trading systems looking for **Smart Money Orderflow** data.

***

### 🚀 Features

- **Multi-Asset Coverage (20+ Assets):**
  - **Forex:** EUR, JPY, GBP, AUD, NZD, CAD, CHF, USD, MXN, BRL, ZAR.
  - **Cryptocurrencies:** Bitcoin (BTC), Ethereum (ETH).
  - **Metals & Energy:** Gold (GOLD), Silver (SILVER), Copper (COPPER), Crude Oil (OIL), Natural Gas (GAS).
  - **Indices:** S\&P 500, NASDAQ-100, Dow Jones.
- **Smart Money Metrics:**
  - `long_positions` & `short_positions` (Non-Commercial positions).
  - `change_long` & `change_short` (Weekly position injection/unwinding).
  - `net_position` ($Long - Short$).
- **Smart Money Orderflow Rankings:** Automatically computes the weekly institutional buying and selling pressure ranking against historical data.
- **AI & MCP Ready:** Fully compatible with Claude, Cursor, and AI agents via the **Model Context Protocol (MCP)**.
- **Export Formats:** JSON, CSV, Excel, XML.

***

### 📥 Input Configuration

```json
{
  "assets": ["GOLD", "EUR", "BTC", "OIL"],
  "categories": ["ALL"],
  "years": [2025, 2026],
  "includeRankings": true,
  "outputFormat": "flat_records"
}
```

#### Input Parameters:

| Field | Type | Default | Description |
|---|---|---|---|
| `assets` | Array | `["ALL"]` | List of assets to scrape or `["ALL"]`. |
| `categories` | Array | `["ALL"]` | Filter by `forex`, `crypto`, `metals`, `index`, `other`. |
| `years` | Array | `[2025, 2026]` | Years of historical reports to fetch from CFTC. |
| `includeRankings` | Boolean | `true` | Computes Smart Money Orderflow injection rankings. |
| `outputFormat` | String | `flat_records` | `flat_records` or `aggregated_by_asset`. |

***

### 📤 Output Example (Dataset)

```json
{
  "date": "24/09/25",
  "iso_date": "2025-09-24",
  "asset": "GOLD",
  "category": "metals",
  "contract_code": "088691",
  "long_positions": 284520,
  "short_positions": 41200,
  "change_long": 14200,
  "change_short": -3100,
  "net_position": 243320,
  "report_id": "deacmxsf"
}
```

***

### 🤖 Using with Apify Client in Python (e.g. Streamlit)

```python
from apify_client import ApifyClient
import pandas as pd

client = ApifyClient("YOUR_APIFY_TOKEN")

## Run the actor
run = client.actor("your-username/cftc-cot-reports-analytics").call(
    run_input={"assets": ["GOLD", "EUR", "BTC"], "years": [2025, 2026]}
)

## Fetch results as DataFrame
items = client.dataset(run["defaultDatasetId"]).list_items().items
df = pd.DataFrame(items)
print(df.head())
```

***

### 🛠️ Local Development & Testing

```bash
## 1. Install dependencies
pip install -r requirements.txt

## 2. Run with Apify CLI
apify run

## Or run directly with Python
python -m src.main
```

# Actor input Schema

## `assets` (type: `array`):

Select the financial assets to fetch. Choose 'ALL' or specific assets (e.g. GOLD, BTC, EUR, OIL).

## `categories` (type: `array`):

Filter assets by their market category.

## `years` (type: `array`):

List of report years to download from CFTC. Default is current years \[2025, 2026].

## `includeRankings` (type: `boolean`):

When enabled, computes weekly orderflow injection rankings (Long & Short rankings).

## `outputFormat` (type: `string`):

Choose between flat records (ideal for tabular/CSV exports) or aggregated by asset.

## Actor input object example

```json
{
  "assets": [
    "ALL"
  ],
  "categories": [
    "ALL"
  ],
  "years": [
    2025,
    2026
  ],
  "includeRankings": true,
  "outputFormat": "flat_records"
}
```

# Actor output Schema

## `results` (type: `string`):

Dataset items and records produced by the Actor

## `overview` (type: `string`):

Summary report stored in Key-Value store

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("khnaami/cftc-cot-reports").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("khnaami/cftc-cot-reports").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call khnaami/cftc-cot-reports --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,khnaami/cftc-cot-reports"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/OYqldB6ShEKywAVfM/builds/cdFBwvolRnsyT63Nd/openapi.json
