Skip to main content

LangChain tools for the TradeOdds REST API — drop-in agent integrations for quantitative pattern analysis.

Project description

tradeodds-langchain

LangChain tools for the TradeOdds REST API. Drop the four tools below into any LangChain agent and it can reason about quantitative pattern analysis on ~3,200 symbols.

pip install tradeodds-langchain

Quickstart

import os
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from tradeodds_langchain import all_tools

os.environ.setdefault("TRADEODDS_API_KEY", "sk-to-...")

tools = all_tools()
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a quantitative trading research assistant. Ground every claim in TradeOdds base rates."),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])

agent = create_tool_calling_agent(llm, tools, prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
executor.invoke({"input": "What usually happens in SPY 5 days after a high-VIX bull-regime day?"})

Tools

Tool What it does Auth Cost
TradeOddsListSymbolsTool List every available symbol (~3,200) none free
TradeOddsPriceHistoryTool Daily OHLCV bars for a symbol none free
TradeOddsAnalyzeTool Historical pattern analysis on one symbol API key $0.05
TradeOddsFactorMatchTool Scan all symbols for current matches API key $0.15

Each tool subclasses langchain_core.tools.BaseTool with a Pydantic v2 args_schema. Tool descriptions are written for the LLM — they explain what the tool does, when to use it, and what shape it returns, so most agents pick the right tool with no extra prompting.

Configuration

Set TRADEODDS_API_KEY in your environment (or pass client=TradeOddsClient(api_key=...) per tool). Get a key at https://tradeodds.io/account.

Sharing a client

By default each tool builds its own TradeOddsClient. To share an HTTP session (e.g. with retries) across all four tools:

from tradeodds import TradeOddsClient
from tradeodds_langchain import all_tools

client = TradeOddsClient(api_key="sk-to-...", timeout=120.0)
tools = all_tools(client=client)

Manual tool wiring

If you only need one tool, import it directly:

from tradeodds_langchain import TradeOddsFactorMatchTool

tool = TradeOddsFactorMatchTool()
result = tool.invoke({
    "conditions": {"vix_level": True, "regime": True, "rsi_zone": True},
    "filters": {"is_etf": False, "price_min": 10},
    "perf_filter": {"metric": "win_5d", "operator": "gt", "threshold": 0.6},
    "min_instances": 20,
})

Error handling

API errors are returned as a structured dict so the agent can read them:

{"ok": False, "error": {"code": "rate_limit_exceeded", "message": "...", "hint": "...", "request_id": "...", "status_code": 429}}

That way one bad call doesn't break an agent loop — the LLM sees the error envelope and can retry, narrow the query, or surface the issue to the user.

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tradeodds_langchain-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tradeodds_langchain-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file tradeodds_langchain-0.1.0.tar.gz.

File metadata

  • Download URL: tradeodds_langchain-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tradeodds_langchain-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1becff566f2d7c4967f5b215c845652993835fdd0ea5013e35e933e9d76b1bb4
MD5 c2482e467ecf748e05437771a2cc5303
BLAKE2b-256 a0b5767878bc2f38e3af727ae6b0c3aae4f89b9eef8e00f1cb4efd2b76e31be4

See more details on using hashes here.

File details

Details for the file tradeodds_langchain-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tradeodds_langchain-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50082c0e691094fbc8bf38d256b2cb05c37f0d20e9e67d3ec76d018c290d1d34
MD5 185dbbae9dd1c41b2ef049f461e11dcc
BLAKE2b-256 c387a1d0c7a1ffa6c1bd8afffb3dcd4672111737a1fb6929d1cf4669deedec0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page