Getting Started

API Documentation

Welcome to the currapi documentation. Learn how to integrate with our API to access historical currency exchange rates.

Installation

Install the @appaka/currapi package using npm, yarn, or pnpm:

npm install @appaka/currapi

Usage

The @appaka/currapi package provides a simple and intuitive API for accessing currency exchange rates.

Initialization

First, initialize the client with your API key:

import { CurrAPIClient } from '@appaka/currapi'

// Initialize the client with your API key
const currapi = new CurrAPIClient(process.env.CURRAPI_API_KEY!)

Caching

Optionally, implement caching functions to reduce the number of requests to currapi.com:

import Redis from 'ioredis'
import { CurrAPIClient } from '@appaka/currapi'

const redis = new Redis(process.env.REDIS_URL!)

const currapi = new CurrAPIClient(process.env.CURRAPI_API_KEY!, {
  verboseMode: true,
  cacheGet: (base, target, date) => redis.get(`${date}:${base}${target}`),
  cacheSet: (base, target, date, rate) =>
    redis.set(`${date}:${base}${target}`, rate),
})

Getting Exchange Rates

Fetch the exchange rate between two currencies for a specific date:

// Get exchange rate
const rate = await currapi.getRate('USD', 'EUR', '2023-01-15')
console.log(rate) // 0.92385671

Converting Currency

Convert an amount from one currency to another:

// Convert currency
const result = await currapi.convert(100, 'USD', 'EUR', '2023-01-15')
// Date is optional, defaults to current date
console.log(result) // 92.39 EUR

Supported Currencies

You can find the list of supported currencies and their codes in the CURRENCIES constant:

import { CURRENCIES } from '@appaka/currapi'