Skip to content

Commit

Permalink
Merge pull request #1773 from Lukapetro/feature/add-coinmarketcap-plugin
Browse files Browse the repository at this point in the history
Feature/add coinmarketcap plugin
  • Loading branch information
wtfsayo authored Jan 8, 2025
2 parents 235c523 + aa7ff57 commit 0e74e13
Show file tree
Hide file tree
Showing 24 changed files with 728 additions and 8 deletions.
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@elizaos/plugin-0g": "workspace:*",
"@elizaos/plugin-abstract": "workspace:*",
"@elizaos/plugin-aptos": "workspace:*",
"@elizaos/plugin-coinmarketcap": "workspace:*",
"@elizaos/plugin-binance": "workspace:*",
"@elizaos/plugin-avail": "workspace:*",
"@elizaos/plugin-bootstrap": "workspace:*",
Expand Down
24 changes: 16 additions & 8 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PGLiteDatabaseAdapter } from "@elizaos/adapter-pglite";
import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
import { RedisClient } from "@elizaos/adapter-redis";
import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite";
import { PGLiteDatabaseAdapter } from "@elizaos/adapter-pglite";
import { AutoClientInterface } from "@elizaos/client-auto";
import { DiscordClientInterface } from "@elizaos/client-discord";
import { FarcasterAgentClient } from "@elizaos/client-farcaster";
Expand Down Expand Up @@ -31,14 +31,17 @@ import {
validateCharacterConfig,
} from "@elizaos/core";
import { zgPlugin } from "@elizaos/plugin-0g";

import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
import createGoatPlugin from "@elizaos/plugin-goat";
// import { intifacePlugin } from "@elizaos/plugin-intiface";
import { DirectClient } from "@elizaos/client-direct";
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
import { abstractPlugin } from "@elizaos/plugin-abstract";
import { aptosPlugin } from "@elizaos/plugin-aptos";
import { alloraPlugin } from "@elizaos/plugin-allora";
import { aptosPlugin } from "@elizaos/plugin-aptos";
import { artheraPlugin } from "@elizaos/plugin-arthera";
import { availPlugin } from "@elizaos/plugin-avail";
import { avalanchePlugin } from "@elizaos/plugin-avalanche";
import { binancePlugin } from "@elizaos/plugin-binance";
import {
Expand All @@ -49,12 +52,13 @@ import {
tradePlugin,
webhookPlugin,
} from "@elizaos/plugin-coinbase";
import { coinmarketcapPlugin } from "@elizaos/plugin-coinmarketcap";
import { coinPricePlugin } from "@elizaos/plugin-coinprice";
import { confluxPlugin } from "@elizaos/plugin-conflux";
import { createCosmosPlugin } from "@elizaos/plugin-cosmos";
import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
import { echoChambersPlugin } from "@elizaos/plugin-echochambers";
import { evmPlugin } from "@elizaos/plugin-evm";
import { createCosmosPlugin } from "@elizaos/plugin-cosmos";
import { flowPlugin } from "@elizaos/plugin-flow";
import { fuelPlugin } from "@elizaos/plugin-fuel";
import { genLayerPlugin } from "@elizaos/plugin-genlayer";
Expand All @@ -63,24 +67,25 @@ import { multiversxPlugin } from "@elizaos/plugin-multiversx";
import { nearPlugin } from "@elizaos/plugin-near";
import { nftGenerationPlugin } from "@elizaos/plugin-nft-generation";
import { createNodePlugin } from "@elizaos/plugin-node";
import { obsidianPlugin } from "@elizaos/plugin-obsidian";
import { openWeatherPlugin } from "@elizaos/plugin-open-weather";
import { solanaPlugin } from "@elizaos/plugin-solana";
import { solanaAgentkitPlguin } from "@elizaos/plugin-solana-agentkit";
import { stargazePlugin } from "@elizaos/plugin-stargaze";
import { storyPlugin } from "@elizaos/plugin-story";
import { suiPlugin } from "@elizaos/plugin-sui";
import { TEEMode, teePlugin } from "@elizaos/plugin-tee";
import { teeMarlinPlugin } from "@elizaos/plugin-tee-marlin";
import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";
import { tonPlugin } from "@elizaos/plugin-ton";
import { webSearchPlugin } from "@elizaos/plugin-web-search";

import { giphyPlugin } from "@elizaos/plugin-giphy";
import { echoChamberPlugin } from "@elizaos/plugin-echochambers";
import { letzAIPlugin } from "@elizaos/plugin-letzai";
import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";

import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
import { availPlugin } from "@elizaos/plugin-avail";
import { openWeatherPlugin } from "@elizaos/plugin-open-weather";
import { artheraPlugin } from "@elizaos/plugin-arthera";
import { stargazePlugin } from "@elizaos/plugin-stargaze";
import { obsidianPlugin } from "@elizaos/plugin-obsidian";
import Database from "better-sqlite3";
import fs from "fs";
import net from "net";
Expand Down Expand Up @@ -631,6 +636,9 @@ export async function createAgent(
? nftGenerationPlugin
: null,
getSecret(character, "ZEROG_PRIVATE_KEY") ? zgPlugin : null,
getSecret(character, "COINMARKETCAP_API_KEY")
? coinmarketcapPlugin
: null,
getSecret(character, "COINBASE_COMMERCE_KEY")
? coinbaseCommercePlugin
: null,
Expand Down
127 changes: 127 additions & 0 deletions packages/plugin-coinmarketcap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# @elizaos/plugin-coinmarketcap

A plugin for Eliza that enables cryptocurrency price checking using the CoinMarketCap API.

## Features

- Real-time cryptocurrency price checking
- Support for multiple cryptocurrencies (BTC, ETH, SOL, etc.)
- Currency conversion (USD, EUR, etc.)
- Detailed price and market data
- Natural language processing for price queries

## Installation

```bash
npm install @elizaos/plugin-coinmarketcap
```

## Configuration

1. Get your API key from [CoinMarketCap](https://pro.coinmarketcap.com)

2. Set up your environment variables:

```bash
COINMARKETCAP_API_KEY=your_api_key
```

3. Register the plugin in your Eliza configuration:

```typescript
import { CoinMarketCapPlugin } from "@elizaos/plugin-coinmarketcap";

// In your Eliza configuration
plugins: [
new CoinMarketCapPlugin(),
// ... other plugins
];
```

## Usage

The plugin responds to natural language queries about cryptocurrency prices. Here are some examples:

```plaintext
"What's the current price of Bitcoin?"
"Show me ETH price in USD"
"Get the price of SOL"
```

### Supported Cryptocurrencies

The plugin supports major cryptocurrencies including:

- Bitcoin (BTC)
- Ethereum (ETH)
- Solana (SOL)
- USD Coin (USDC)
- And many more...

### Available Actions

#### GET_PRICE

Fetches the current price of a cryptocurrency.

```typescript
// Example response format
{
symbol: "BTC",
price: 50000.00,
currency: "USD",
marketCap: 1000000000000,
volume24h: 50000000000,
percentChange24h: 2.5
}
```

## API Reference

### Environment Variables

| Variable | Description | Required |
| --------------------- | -------------------------- | -------- |
| COINMARKETCAP_API_KEY | Your CoinMarketCap API key | Yes |

### Types

```typescript
interface PriceData {
price: number;
marketCap: number;
volume24h: number;
percentChange24h: number;
}

interface GetPriceContent {
symbol: string;
currency: string;
}
```

## Error Handling

The plugin includes comprehensive error handling for:

- Invalid API keys
- Rate limiting
- Network timeouts
- Invalid cryptocurrency symbols
- Unsupported currencies

## Rate Limits

CoinMarketCap API has different rate limits based on your subscription plan. Please refer to [CoinMarketCap's pricing page](https://coinmarketcap.com/api/pricing/) for detailed information.

## Support

For support, please open an issue in the repository or reach out to the maintainers:

- Discord: 0xspit

## Links

- [CoinMarketCap API Documentation](https://coinmarketcap.com/api/documentation/v1/)

- [GitHub Repository](https://github.com/elizaOS/eliza/tree/main/packages/plugin-coinmarketcap)
19 changes: 19 additions & 0 deletions packages/plugin-coinmarketcap/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@elizaos/plugin-coinmarketcap",
"version": "0.1.7-alpha.2",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@elizaos/core": "workspace:*",
"axios": "^1.6.7",
"zod": "^3.22.4"
},
"devDependencies": {
"tsup": "^8.3.5"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch"
}
}
46 changes: 46 additions & 0 deletions packages/plugin-coinmarketcap/src/actions/getPrice/examples.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ActionExample } from "@elizaos/core";

export const priceExamples: ActionExample[][] = [
[
{
user: "{{user1}}",
content: {
text: "What's the current price of Bitcoin?",
},
},
{
user: "{{agent}}",
content: {
text: "Let me check the current Bitcoin price for you.",
action: "GET_PRICE",
},
},
{
user: "{{agent}}",
content: {
text: "The current price of BTC is 65,432.21 USD",
},
},
],
[
{
user: "{{user1}}",
content: {
text: "Check ETH price in EUR",
},
},
{
user: "{{agent}}",
content: {
text: "I'll check the current Ethereum price in EUR.",
action: "GET_PRICE",
},
},
{
user: "{{agent}}",
content: {
text: "The current price of ETH is 2,345.67 EUR",
},
},
],
];
Loading

0 comments on commit 0e74e13

Please sign in to comment.