eliza icon indicating copy to clipboard operation
eliza copied to clipboard

feat: Add CoinGecko plugin

Open 0xCardiE opened this issue 1 year ago • 23 comments

Adding a new plugin, where with free API from coingecko we can get price of a currency and its marketcap. There are 2 actions, so we can fetch by name/ticker but also with address of token.

Added, Readme, .env config and integration to default agent if key is set.

Image attached for example how it makes output. image

0xCardiE avatar Dec 22 '24 21:12 0xCardiE

Seems unnecessary to change the character files (provider switched for whatever reason), also the entire package.json instead of just adding the plugin. I know that's just a formatting thing but makes it more tedious to review.

proteanx avatar Dec 22 '24 22:12 proteanx

Seems unnecessary to change the character files (provider switched for whatever reason), also the entire package.json instead of just adding the plugin. I know that's just a formatting thing but makes it more tedious to review.

Ahh nm I see you added those characters originally. Just seemed unrelated to the PR.

proteanx avatar Dec 22 '24 23:12 proteanx

Seems unnecessary to change the character files (provider switched for whatever reason), also the entire package.json instead of just adding the plugin. I know that's just a formatting thing but makes it more tedious to review.

Ahh nm I see you added those characters originally. Just seemed unrelated to the PR.

had some problems on DEV branch with antropic so I did change model to openai, but reverted now on this PR, as this is unrelated.

0xCardiE avatar Dec 22 '24 23:12 0xCardiE

Seems unnecessary to change the character files (provider switched for whatever reason), also the entire package.json instead of just adding the plugin. I know that's just a formatting thing but makes it more tedious to review.

about formating, isnt the setting for prettier set to 4 in all places, so seems to me this should be right formating of .json file?

0xCardiE avatar Dec 22 '24 23:12 0xCardiE

Going to test this but there are merge conflicts that need to be fixed. Might need to rebase this onto current develop branch to fix. I'm seeing some stuff that doesn't exist in current develop i.e. agent/src/index.ts everything but the addition of the import and getSecret(character, "COINGECKO_API_KEY") ? coingeckoPlugin : null, should be reverted/removed (it's correct already in current develop so this is probably the merge conflict).

proteanx avatar Dec 23 '24 01:12 proteanx

Going to test this but there are merge conflicts that need to be fixed. Might need to rebase this onto current develop branch to fix. I'm seeing some stuff that doesn't exist in current develop i.e. agent/src/index.ts everything but the addition of the import and getSecret(character, "COINGECKO_API_KEY") ? coingeckoPlugin : null, should be reverted/removed (it's correct already in current develop so this is probably the merge conflict).

thanx for review, develop moves fast so I didn't update it for 2 days and lots has changed, I merged current develop into mine so now there shouldn't be any conflict.

0xCardiE avatar Dec 23 '24 14:12 0xCardiE

Going to test this but there are merge conflicts that need to be fixed. Might need to rebase this onto current develop branch to fix. I'm seeing some stuff that doesn't exist in current develop i.e. agent/src/index.ts everything but the addition of the import and getSecret(character, "COINGECKO_API_KEY") ? coingeckoPlugin : null, should be reverted/removed (it's correct already in current develop so this is probably the merge conflict).

thanx for review, develop moves fast so I didn't update it for 2 days and lots has changed, I merged current develop into mine so now there shouldn't be any conflict.

This looks really clean now. Unfortunately I encountered an error attempting to test price retrieval -

 ["✓ Normalized action: getcoin_price"] 

 ["ℹ Executing handler for action: GET_COIN_PRICE"] 

 ["◎ Starting GET_COIN_PRICE handler..."] 

 ◎ LOGS
   Fetched coin list, total coins: 
   16269 

Error in generateObject: Error: Unknown model
    at getEncodingNameForModel (file:///media/bsc/eliza/node_modules/js-tiktoken/dist/chunk-YVJR5WRT.js:242:13)
    at encodingForModel (file:///media/bsc/eliza/node_modules/js-tiktoken/dist/index.js:43:22)
    at trimTokens (file:///media/bsc/eliza/packages/core/dist/index.js:2191:22)
    at generateObject (file:///media/bsc/eliza/packages/core/dist/index.js:2607:19)
    at Object.handler (file:///media/bsc/eliza/packages/plugin-gecko/dist/index.js:4114:40)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async AgentRuntime.processActions (file:///media/bsc/eliza/packages/core/dist/index.js:3577:17)
    at async MessageManager.handleMessage (file:///media/bsc/eliza/packages/client-discord/dist/index.js:2132:17)
 ⛔ ERRORS
   Error during price lookup: 
   {} 

proteanx avatar Dec 23 '24 23:12 proteanx

Going to test this but there are merge conflicts that need to be fixed. Might need to rebase this onto current develop branch to fix. I'm seeing some stuff that doesn't exist in current develop i.e. agent/src/index.ts everything but the addition of the import and getSecret(character, "COINGECKO_API_KEY") ? coingeckoPlugin : null, should be reverted/removed (it's correct already in current develop so this is probably the merge conflict).

thanx for review, develop moves fast so I didn't update it for 2 days and lots has changed, I merged current develop into mine so now there shouldn't be any conflict.

This looks really clean now. Unfortunately I encountered an error attempting to test price retrieval -

 ["✓ Normalized action: getcoin_price"] 

 ["ℹ Executing handler for action: GET_COIN_PRICE"] 

 ["◎ Starting GET_COIN_PRICE handler..."] 

 ◎ LOGS
   Fetched coin list, total coins: 
   16269 

Error in generateObject: Error: Unknown model
    at getEncodingNameForModel (file:///media/bsc/eliza/node_modules/js-tiktoken/dist/chunk-YVJR5WRT.js:242:13)
    at encodingForModel (file:///media/bsc/eliza/node_modules/js-tiktoken/dist/index.js:43:22)
    at trimTokens (file:///media/bsc/eliza/packages/core/dist/index.js:2191:22)
    at generateObject (file:///media/bsc/eliza/packages/core/dist/index.js:2607:19)
    at Object.handler (file:///media/bsc/eliza/packages/plugin-gecko/dist/index.js:4114:40)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async AgentRuntime.processActions (file:///media/bsc/eliza/packages/core/dist/index.js:3577:17)
    at async MessageManager.handleMessage (file:///media/bsc/eliza/packages/client-discord/dist/index.js:2132:17)
 ⛔ ERRORS
   Error during price lookup: 
   {} 

try with openai as modelProvider, IDK why when using anthropic it gets this error, doesnt seem like problem with this plugin as it just sets "ModelClass.SMALL" and then in tiktoken module

function getEncodingNameForModel(model) {
  switch (model) {

this part gets some model that is not in the list, but seems more like general codebase problem, as I dont set the actual model in plugin. Please trace it out yourself and let me know what you think?

0xCardiE avatar Dec 24 '24 00:12 0xCardiE

image was having problems with using "generateObject" somehow it got into tiktoken even when using anthropic, didn't really need to use it, just switched to "generateMessageResponse" and all is fine now and should work as expected, please try it out

0xCardiE avatar Dec 25 '24 00:12 0xCardiE


proteanx avatar Dec 26 '24 21:12 proteanx

Scratch what I said before, this is working now you just need to add the plugin to the pnpm-lock file. This is a lot of commits for a single PR but the eliza devs don't seem to mind so this should be good to go.

Tested with Venice

image

proteanx avatar Dec 26 '24 21:12 proteanx

Scratch what I said before, this is working now you just need to add the plugin to the pnpm-lock file. This is a lot of commits for a single PR but the eliza devs don't seem to mind so this should be good to go.

Tested with Venice

image

Added lock file.

yeah, sorry for too many fixes, was mostly because of the model issue and that the whole plugin namespace changed, so tracking this and updating to dev branch that is constantly moving was hard to catch, but in the end it all resulted in better code and better of understanding of the whole system.

0xCardiE avatar Dec 27 '24 00:12 0xCardiE

hey @0xCardinalError @odilitime , thanks for working on this!

I work on CoinGecko product, I can supply pro api key to ease your testing, and as token of appreciation for your contributions. Feel free to ping TG @soonegg91

There's more can be done here for eliza with the CG demo and pro api, happy to bounce ideas.

sachiew avatar Dec 27 '24 18:12 sachiew

hey @0xCardinalError @odilitime , thanks for working on this!

I work on CoinGecko product, I can supply pro api key to ease your testing, and as token of appreciation for your contributions. Feel free to ping TG @soonegg91

There's more can be done here for eliza with the CG demo and pro api, happy to bounce ideas.

hey, thnx. will contact him in pvt and see where we can take this to

0xCardiE avatar Dec 27 '24 20:12 0xCardiE

@odilitime @proteanx is testing done, Is anything else needed for this PR? (updated to latest dev branch)

0xCardiE avatar Dec 30 '24 10:12 0xCardiE

It correctly fetched the price but the first message was probably not meant to be printed? image

tripluca avatar Jan 02 '25 21:01 tripluca

I installed and tested the plugin. Here's some feedback:

Current Features

  1. Get current price and market cap for known coins (BTC, ETH). Question: I tested with ordinals tokens (BRC20 but it doesn't fetch them.
  2. Get price and market cap for tokens by address on specific chains
  3. Basic error handling for unknown tokens

Limitations Found Through Testing

  1. Cannot remember or reference previously mentioned prices
  2. No access to historical data or 24h changes
  3. No price comparison functionality
  4. No volume data
  5. No price alerts or threshold notifications
  6. No trend analysis
  7. Action indicators ((GET_COIN_PRICE), (GET_TOKEN_PRICE_BY_ADDRESS)) visible in responses

Questions

Is this the whole scope? Getting the price when explicitly requested? Or is there a way to extract more from the API?` thanks!

tripluca avatar Jan 04 '25 16:01 tripluca

No access to historical data or 24h changes No volume data

Thanks for testing it out. The current commits include these 2 endpoints that support 24hr price change and 24hr trading volume data, but don't think it's included in the code:

  • https://docs.coingecko.com/reference/simple-price
  • https://docs.coingecko.com/reference/simple-token-price Currently, only include_market_cap is included for both endpoints above. Suggestion: to add the optional params: include_24hr_vol , include_24hr_change

Question: I tested with ordinals tokens (BRC20 but it doesn't fetch them.

Able to replicate this issue. It works for 'bitcoin', but not the following (refer image below):

  • 64550b91e058ef71501f1f46d446f6dae16fa446321f9e02e3c89490220ef400i0 on ordinals (CG page)
  • price for Bitcoin Wizards (same token as above)
  • 0x1185cb5122edad199bdbc0cbd7a0457e448f23c7 on base (CG page) Screenshot 2025-01-05 at 1 26 35 AM

In case this helps - for 'chainId', this is how CoinGecko API maps with 'asset_platform_id'

  • https://docs.coingecko.com/reference/asset-platforms-list (list of ids here)
  • https://docs.coingecko.com/reference/simple-token-price

--

There's definitely a lot more data and functionalities can be added given the API has more than 70 endpoints. Perhaps, can let 0xCardinalError focus on shipping the initial scopes, and can continue to expand to support more use cases. Hoping to see more contributors collab too :)

sachiew avatar Jan 04 '25 17:01 sachiew

this works but not good all the time!

wtfsayo avatar Jan 07 '25 11:01 wtfsayo

2. No access to historical data or 24h changes

What kind of print out do you use, when using default browser I don't get extra messages.

image

0xCardiE avatar Jan 08 '25 22:01 0xCardiE

I installed and tested the plugin. Here's some feedback:

Current Features

  1. Get current price and market cap for known coins (BTC, ETH). Question: I tested with ordinals tokens (BRC20 but it doesn't fetch them.
  2. Get price and market cap for tokens by address on specific chains
  3. Basic error handling for unknown tokens

Limitations Found Through Testing

  1. Cannot remember or reference previously mentioned prices
  2. No access to historical data or 24h changes
  3. No price comparison functionality
  4. No volume data
  5. No price alerts or threshold notificationsh
  6. No trend analysis
  7. Action indicators ((GET_COIN_PRICE), (GET_TOKEN_PRICE_BY_ADDRESS)) visible in responses

Questions

Is this the whole scope? Getting the price when explicitly requested? Or is there a way to extract more from the API?` thanks!

as written in readme it was just 2 endpoints for fetching price as some V1 of this to have access to price. this made most sense to have for a BOT. should add it to memory/state for reuse. will add others over time, which ones makes most sense. I am thinking mostly in a way that AI would buy something or inform others about specific info about price/market situations. Please state some scenarios you think would be good to have?

0xCardiE avatar Jan 08 '25 22:01 0xCardiE

No access to historical data or 24h changes No volume data

Thanks for testing it out. The current commits include these 2 endpoints that support 24hr price change and 24hr trading volume data, but don't think it's included in the code:

  • https://docs.coingecko.com/reference/simple-price
  • https://docs.coingecko.com/reference/simple-token-price Currently, only include_market_cap is included for both endpoints above. Suggestion: to add the optional params: include_24hr_vol , include_24hr_change

Question: I tested with ordinals tokens (BRC20 but it doesn't fetch them.

Able to replicate this issue. It works for 'bitcoin', but not the following (refer image below):

  • 64550b91e058ef71501f1f46d446f6dae16fa446321f9e02e3c89490220ef400i0 on ordinals (CG page)
  • price for Bitcoin Wizards (same token as above)
  • 0x1185cb5122edad199bdbc0cbd7a0457e448f23c7 on base (CG page)
Screenshot 2025-01-05 at 1 26 35 AM In case this helps - for 'chainId', this is how CoinGecko API maps with 'asset_platform_id'
  • https://docs.coingecko.com/reference/asset-platforms-list (list of ids here)
  • https://docs.coingecko.com/reference/simple-token-price

--

There's definitely a lot more data and functionalities can be added given the API has more than 70 endpoints. Perhaps, can let 0xCardinalError focus on shipping the initial scopes, and can continue to expand to support more use cases. Hoping to see more contributors collab too :)

yes, there are a lot of endpoints, started from the most logical one :)

about the base problem, hmm it could also be down to quirkiness of actual LLM/char you are using. I tried exact same many times and it does output correctly as seen below.

about ordinals, yeah, that is a problem, optimizing template for it and other to use ordinals word as platform/chain _id

image

0xCardiE avatar Jan 08 '25 22:01 0xCardiE

this works but not good all the time!

please provide if you have different problems then the ones stated by others?

0xCardiE avatar Jan 08 '25 22:01 0xCardiE

Ordinals should be fetched now, also added memory part so agent can recall what he just found

image

0xCardiE avatar Jan 09 '25 21:01 0xCardiE

Added trending coins.

image

0xCardiE avatar Jan 09 '25 22:01 0xCardiE

was solved and merged in other PRs, so will close this one

0xCardiE avatar Jan 20 '25 17:01 0xCardiE