Skip to content

feat: add cg token-price command for contract address lookups#18

Open
gosuto-inzasheru wants to merge 1 commit intocoingecko:mainfrom
gosuto-inzasheru:feat/token-price-by-contract
Open

feat: add cg token-price command for contract address lookups#18
gosuto-inzasheru wants to merge 1 commit intocoingecko:mainfrom
gosuto-inzasheru:feat/token-price-by-contract

Conversation

@gosuto-inzasheru
Copy link

Summary

Adds a new token-price command that fetches current prices by token contract addresses via the /simple/token_price/{platform} endpoint.

cg token-price --address 0x1f9840a85d5af5bf1d1762f925bdaddc4201f984 --platform ethereum
cg token-price --address 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,0xdAC17F958D2ee523a2206206994597C13D831ec7 --platform ethereum
cg token-price --address 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 --platform base --vs eur
cg token-price --address 0x912CE59144191C1204E64559FE8253a0e49E6548 --platform arbitrum-one -o json

Motivation

The existing cg price command supports coin IDs and ticker symbols, but many web3 workflows start with a contract address. Currently there's no way to look up a token's price by address without first resolving it to a CoinGecko ID. This command fills that gap using the existing /simple/token_price/{platform} API endpoint.

Implemented as a standalone command rather than flags on cg price because:

  • Different API endpoint (/simple/token_price/{platform} vs /simple/price)
  • Different input type (contract addresses vs coin IDs/symbols)
  • Response keys are contract addresses, not coin IDs
  • Avoids flag interdependency (--platform required with --contract but invalid with --ids)

Changes

  • cmd/token_price.go — new command with --address, --platform, --vs flags
  • cmd/token_price_test.go — 7 tests (missing flags, dry-run, JSON output, multiple addresses, no results, partial miss warning)
  • internal/api/coins.go — new SimpleTokenPrice client method
  • internal/api/coins_test.go — 3 API client tests (basic, multiple addresses, platform escaping)
  • cmd/commands.go — command metadata for agent catalog

Features

  • Multiple comma-separated addresses in one call
  • --vs currency support (default: usd)
  • --dry-run mode
  • -o json output
  • Partial miss warnings on stderr
  • Registered in cg commands catalog for agent discovery

Add a new `token-price` command that fetches current prices by token
contract addresses via the `/simple/token_price/{platform}` endpoint.

Usage:
  cg token-price --address 0x1f98...f984 --platform ethereum
  cg token-price --address 0xUSDC,0xUNI --platform base --vs eur -o json

Supports multiple addresses, --vs currency, --dry-run, -o json, and
warns on stderr for addresses that return no data.
@gosuto-inzasheru gosuto-inzasheru requested a review from a team March 19, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant