Skip to content

Conversation

@HermanKoii
Copy link
Owner

@HermanKoii HermanKoii commented May 30, 2025

Implement CoinGecko API Client with Comprehensive Data Fetching

Description

Task

create a coin gekko api

Acceptance Criteria

  • Can fetch individual coin data
  • Can list top cryptocurrencies
  • Provides structured, typed responses
  • Handles potential API errors gracefully

Summary of Work

CoinGecko API Client Implementation

Overview

This pull request implements a robust CoinGecko API client with two primary methods for fetching cryptocurrency data:

  • Retrieve detailed information for a specific coin
  • List top cryptocurrencies by market capitalization

Key Features

  • Flexible API initialization with optional base URL and API key
  • Error handling for API requests
  • Typed responses with success/error metadata
  • Support for fetching individual coin data
  • Support for listing top cryptocurrencies

Implementation Details

  1. CoinGekkoApi Class

    • Utilizes axios for HTTP requests
    • Configurable base URL (defaults to CoinGecko v3 API)
    • Optional API key support for future extensions
  2. Methods

    • fetchCoinData(coinId: string):
      • Retrieves detailed information for a specific cryptocurrency
      • Returns structured CoinData with price, market cap, and volume
    • listCoins(limit: number = 100):
      • Fetches top cryptocurrencies
      • Supports configurable limit (default 100)
      • Sorted by market capitalization
  3. Error Handling

    • Comprehensive error management
    • Returns consistent FetchResult interface for both successful and failed requests

Potential Future Improvements

  • Add more granular coin data retrieval
  • Implement caching mechanism
  • Add more comprehensive error types

Changes Made

  • Implemented CoinGekkoApi class in src/index.ts
  • Created TypeScript interfaces in src/types.ts
  • Added axios as a dependency for HTTP requests
  • Implemented fetchCoinData method to retrieve individual coin information
  • Implemented listCoins method to fetch top cryptocurrencies
  • Added comprehensive error handling
  • Created typed response structure

Tests

  • Verify fetchCoinData returns correct coin information
  • Verify listCoins returns top cryptocurrencies
  • Ensure error handling works for invalid coin IDs
  • Check default and custom base URL configuration
  • Validate response type consistency

Signatures

Staking Key

0x1234567890123456789012345678901234567890: 0x1234567890123456789012345678901234567890

Public Key

0x1234567890123456789012345678901234567890: 0x1234567890123456789012345678901234567890

@HermanKoii HermanKoii changed the title [WIP] Implement Coin Gekko API Integration Implement CoinGecko API Client with Comprehensive Data Fetching May 30, 2025
@HermanKoii HermanKoii marked this pull request as ready for review May 30, 2025 15:06
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.

2 participants