feat: add cg token-price command for contract address lookups#18
Open
gosuto-inzasheru wants to merge 1 commit intocoingecko:mainfrom
Open
feat: add cg token-price command for contract address lookups#18gosuto-inzasheru wants to merge 1 commit intocoingecko:mainfrom
cg token-price command for contract address lookups#18gosuto-inzasheru wants to merge 1 commit intocoingecko:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
token-pricecommand that fetches current prices by token contract addresses via the/simple/token_price/{platform}endpoint.Motivation
The existing
cg pricecommand 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 pricebecause:/simple/token_price/{platform}vs/simple/price)--platformrequired with--contractbut invalid with--ids)Changes
cmd/token_price.go— new command with--address,--platform,--vsflagscmd/token_price_test.go— 7 tests (missing flags, dry-run, JSON output, multiple addresses, no results, partial miss warning)internal/api/coins.go— newSimpleTokenPriceclient methodinternal/api/coins_test.go— 3 API client tests (basic, multiple addresses, platform escaping)cmd/commands.go— command metadata for agent catalogFeatures
--vscurrency support (default: usd)--dry-runmode-o jsonoutputcg commandscatalog for agent discovery