How to trade with Codex (OpenAI)
Short answer: Codex reads MCP servers from
~/.codex/config.toml. Add an[mcp_servers.openfinance]block withurl = "https://api.openfinance.tech/agent/mcp"and your key as a header, restart Codex, and it can query markets and place trades in crypto, onchain stocks, forex, memecoins and Polymarket while it codes your bots.
MCP URL: https://api.openfinance.tech/agent/mcp · HTTP streamable · works with any MCP client · one URL, no SDK · no KYC · fund with a debit card.
Setup in 60 seconds: get your OpenFinance key and start trading all markets with the cheapest fees.
How Codex connects to tools
Codex (CLI and IDE extension) supports Streamable HTTP MCP servers in config.toml with url, a static http_headers map, env_http_headers (header value read from an env var), or bearer_token_env_var. OpenFinance uses an x-api-key header, so env_http_headers keeps the key out of the file.
Set up Codex in under 60 seconds
- Export your key:
export OPENFINANCE_API_KEY=open_xxxxx. - Open
~/.codex/config.toml. - Paste the block below and save.
- Restart Codex and run
/mcpto see OpenFinance tools. - Ask Codex for a quote to confirm it works.
[mcp_servers.openfinance]
url = "https://api.openfinance.tech/agent/mcp"
env_http_headers = { "x-api-key" = "OPENFINANCE_API_KEY" }
Get your OpenFinance key at openfinance.tech (sidebar → External AI), then fund it with a debit card or crypto.
What Codex can trade through OpenFinance
Codex can trade crypto spot and leveraged perps on Hyperliquid, onchain stocks such as TSLA and NVDA, forex, Solana and Base memecoins, and Polymarket prediction markets, all with one OpenFinance key. The full market list is on the hub page.
Prompts to try in Codex
- “Write a script that checks BTC funding every hour and goes long 5x when it flips negative; run it once now with $50.”
- “Fetch NVDA and AAPL token prices and buy $50 of whichever is down more today.”
- “Chart TSLA from the OpenFinance candles into a PNG, then buy with 3x margin.”
- “Build a memecoin sniper that apes $20 into the top trending Solana token and sells at 2x; dry-run the logic first.”
- “List my Polymarket positions and write them to positions.csv.”
FAQ
Is Codex good for trading bots?
Codex is a coding agent, so it's best for building and running strategy scripts that call OpenFinance tools, with you approving each live order.
Where is the Codex MCP config?
~/.codex/config.toml (or a project .codex/config.toml). Each server is a [mcp_servers.<name>] table.
How do I pass the API key?
Use env_http_headers so the header value comes from an environment variable, or http_headers for a literal (not recommended in shared repos).
Does Codex in ChatGPT use the same setup?
Codex CLI and IDE use config.toml. ChatGPT itself adds MCP servers in its own settings.
Will Codex trade without asking?
Codex asks for approval for tool calls depending on your approval mode. Keep it on a mode that asks before order tools.
Can I limit Codex to market data only?
Yes: use the server's tool filter (enabled_tools / disabled_tools) to hide order tools.
Related
- Make any AI agent trading-compatible: every agent and market in one place
- Hyperliquid MCP server
- Polymarket MCP server
- OpenFinance vs Alpaca vs CCXT: how OpenFinance compares with a broker API
Sources: https://learn.chatgpt.com/docs/config-file/config-reference, https://github.com/openai/codex/pull/5241/files
Trading involves risk, especially with leverage and memecoins. Start small.