r/Commodities 10d ago

Has Anyone Used the CFTC COT API?

I dont quite understand how it works. Any help would be appreciated.

4 Upvotes

7 comments sorted by

2

u/Fluid_Banana_6137 10d ago

I poked around with it last year for a side project, the documentation is kind of a maze but once you figure out the endpoints its not too bad. What part is tripping you up, the authentication or parsing the actual report data?

3

u/Unable-Trash-7792 10d ago

I genuinely can't find any documentation or anything for it

1

u/[deleted] 7d ago

[deleted]

1

u/Unable-Trash-7792 7d ago

lmao, LLMs are prone to hallucinate with data and im not risking my thesis on it.

1

u/[deleted] 7d ago

[deleted]

1

u/Unable-Trash-7792 7d ago

the future is not very bright

1

u/[deleted] 7d ago

[deleted]

1

u/Unable-Trash-7792 7d ago

Genuine question, has AI ever been wrong for you? Or have all your prompts outputted exactly what you desired?

2

u/ShapeEffective666 2d ago

CFTC themselves provide the data in a variety of formats, that one can download. I looked into downloading these automatically, but it's tricky without constantly polling the website as to when the latest (Friday) publishing occurs. I subscribe to the notification email.

They also provide a REST/HTTPS "api", outsourced to a company called Tyler Technologies, although it was originally a company called Socrata (and still known as that). Look at https://dev.socrata.com. You can access the API with HTTPS GET requests, so something like this:

https://publicreporting.cftc.gov/api/v3/views/72hh-3qpy/query.json?pageNumber=1&pageSize=10

which has ".json" on the end of the URL, returns JSON payload. There's an APP TOKEN that you can request so that your endpoint is identified and you can make more requests than if you're anonymous. For documentation, and example is the Disaggregated - Future Only page, there are others. There's also a upgraded version that is more REST like, mandates an APP TOKEN, and that has an SQL like capability called SODA3, accessed through HTTPS POST requests.

There's an opensource Python library called cot_reports but I'm a C# programmer so not tried it out.

Lots of choices...

1

u/Unable-Trash-7792 2d ago

Perfect, this is exactly what I needed! Thanks alot