Skip to content

fix(pyth): match price feeds on the symbol when Hermes omits attributes.base - #1676

Open
burrows99 wants to merge 1 commit into
coinbase:mainfrom
burrows99:fix/pyth-feed-without-base
Open

burrows99 wants to merge 1 commit into
coinbase:mainfrom
burrows99:fix/pyth-feed-without-base

Conversation

@burrows99

Copy link
Copy Markdown

Description

The Pyth fetch_price_feed action fails for every symbol on main, in both packages. Hermes /v2/price_feeds no longer returns attributes.base (I checked crypto, equity, fx and metal queries: none of the returned feeds has it), and the filter reads it unguarded:

  • TypeScript throws TypeError: Cannot read properties of undefined (reading 'toLowerCase')
  • Python returns {"success": false, "error": "Error fetching price feed: 'base'"}

A current Hermes item looks like this:

{ "id": "e62d...5b43", "attributes": { "asset_type": "Crypto", "display_symbol": "BTCUSD", "quote_currency": "USD", "symbol": "Crypto.BTC/USD" } }

The fix keeps attributes.base when present and otherwise takes the base from attributes.symbol (the part before /, after the last ., e.g. Crypto.BTC/USD and Equity.US.AAPL/USD.PRE give BTC and AAPL). The equity regular-market selection and everything after the filter are unchanged.

flowchart TD
    A[Agent asks for the BTC price feed] --> B{Hermes item without base}
    B -->|Before| C[TypeError or KeyError and no feed]
    B -->|After| D[Base read from symbol and BTC USD feed returned]
Loading

Narrated recording, before then after (sound on):

evidence.mp4

Separate from this PR: the follow-up fetch_price action now gets HTTP error! status: 401 from https://hermes.pyth.network/v2/updates/price/latest without an API key. That needs a decision on how keys are configured, so I left it out.

Tests

Shown in the recording, against the live public Hermes metadata endpoint (no keys, no wallet).

TypeScript (Node REPL with the workspace @coinbase/agentkit build):

const { pythActionProvider } = require("@coinbase/agentkit")
const pyth = pythActionProvider()
await pyth.fetchPriceFeed({ tokenSymbol: "BTC", quoteCurrency: "USD", assetType: "crypto" })
main:   Uncaught TypeError: Cannot read properties of undefined (reading 'toLowerCase')
branch: '{"success":true,"priceFeedID":"e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43","tokenSymbol":"BTC","quoteCurrency":"USD","feedType":"BTCUSD"}'

Python (python/coinbase-agentkit venv):

from coinbase_agentkit import pyth_action_provider
pyth = pyth_action_provider()
print(pyth.fetch_price_feed({"token_symbol": "BTC", "quote_currency": "USD", "asset_type": "crypto"}))
main:   {"success": false, "error": "Error fetching price feed: 'base'"}
branch: {"success": true, "priceFeedID": "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43", "tokenSymbol": "BTC", "quoteCurrency": "USD", "feedType": "BTCUSD"}

Edge cases and unchanged behaviour checked (TypeScript, live Hermes, in the recording):

  • lowercase eth / crypto returns the ETHUSD feed
  • AAPL / equity returns the regular-market AAPL feed
  • XAU / metal returns the XAUUSD feed
  • unchanged: NOTATOKEN still returns No price feed found for NOTATOKEN
  • unchanged: the existing mocks that still carry base (crypto, metals, commodities, equities, FX, pre/post market preference) pass as before

Unit tests (a new test in each package mocks the current Hermes shape, without base; both fail on main):

$ cd typescript/agentkit && npx jest --testMatch='**/pyth/*.test.ts'
Tests:       15 passed, 15 total

$ cd python/coinbase-agentkit && uv run pytest tests/action_providers/pyth -q
7 passed

eslint, prettier --check, tsc --noEmit, ruff check and ruff format --check pass on the touched files. I did not run the full suites or a chatbot.

Checklist

  • Added documentation to all relevant README.md files (no README change needed)
  • Added a changelog entry (changeset for @coinbase/agentkit, changelog.d/pyth-feed-without-base.bugfix.md for Python)

AI assistance (Claude Code) was used to find and fix this and to prepare the PR.

🤖 Generated with Claude Code

…es.base

Hermes /v2/price_feeds no longer returns attributes.base, so fetch_price_feed
threw "Cannot read properties of undefined (reading 'toLowerCase')" in
TypeScript and returned "Error fetching price feed: 'base'" in Python for
every symbol. Fall back to the base in attributes.symbol
("Crypto.BTC/USD", "Equity.US.AAPL/USD.PRE") when base is missing.
@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
1 if authored by an app that is not allowlisted and lacks verified human attribution 0
Sum 1

@github-actions github-actions Bot added documentation Improvements or additions to documentation action provider New action provider python typescript labels Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider documentation Improvements or additions to documentation python typescript

Development

Successfully merging this pull request may close these issues.

2 participants