Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 184 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import { AxiosResponse } from 'axios';

// Base response structure for all API endpoints
interface BaseResponse {
success: boolean;
error?: {
code: number;
info: string;
};
}

// Symbols response
interface SymbolsResponse extends BaseResponse {
symbols: {
[currencyCode: string]: string;
};
}

// Live rates response
interface LiveRatesResponse extends BaseResponse {
base: string;
timestamp: number;
rates: {
[currencyCode: string]: number;
};
}

// Historical rates response (same structure as live rates)
interface HistoricalRatesResponse extends BaseResponse {
base: string;
timestamp: number;
rates: {
[currencyCode: string]: number;
};
}

// OHLC response
interface OHLCResponse extends BaseResponse {
base: string;
currency: string;
timestamp: number;
ohlc: {
open: number;
high: number;
low: number;
close: number;
};
}

// Convert response
interface ConvertResponse extends BaseResponse {
base: string;
query: {
from: string;
to: string;
amount: number;
};
info: {
quote: number;
timestamp: number
}
result: number;
}

// Timeframe response
interface TimeframeResponse extends BaseResponse {
base: string;
start_date: string;
end_date: string;
rates: {
[date: string]: {
[currencyCode: string]: number;
};
};
}

// Change response
interface ChangeResponse extends BaseResponse {
base: string;
start_date: string;
end_date: string;
change: {
[currencyCode: string]: {
start_rate: number;
end_rate: number;
change: number;
change_pct: number;
};
};
}

// Usage response
interface UsageResponse extends BaseResponse {
result: {
plan: string;
used: number;
total: number;
remaining: number;
}
}

// Date type options for OHLC endpoint
type DateType = 'recent' | 'yesterday' | 'week' | 'month' | 'year';

// Main module interface
interface ForexRateAPI {
/**
* Set the API key for authentication
* @param apiKey Your ForexRateAPI.com API key
*/
setAPIKey(apiKey: string): void;

/**
* Fetch all supported currency symbols
* @returns Promise resolving to axios response with symbols data
*/
fetchSymbols(): Promise<AxiosResponse<SymbolsResponse>>;

/**
* Fetch live exchange rates
* @param base Optional base currency (defaults to USD)
* @param currencies Optional array of currencies to return rates for
* @returns Promise resolving to axios response with live rates data
*/
fetchLive(base?: string, currencies?: string[]): Promise<AxiosResponse<LiveRatesResponse>>;

/**
* Fetch historical exchange rates for a specific date
* @param date Date in YYYY-MM-DD format
* @param base Optional base currency (defaults to USD)
* @param currencies Optional array of currencies to return rates for
* @returns Promise resolving to axios response with historical rates data
*/
fetchHistorical(date: string, base?: string, currencies?: string[]): Promise<AxiosResponse<HistoricalRatesResponse>>;

/**
* Fetch Open, High, Low, Close (OHLC) data for a currency pair
* @param base Base currency (defaults to USD)
* @param currency Target currency for OHLC data
* @param date Date in YYYY-MM-DD format
* @param dateType Optional date type that overrides the date parameter
* @returns Promise resolving to axios response with OHLC data
*/
ohlc(base?: string, currency?: string, date?: string, dateType?: DateType): Promise<AxiosResponse<OHLCResponse>>;

/**
* Convert amount from one currency to another
* @param from Source currency (defaults to USD)
* @param to Target currency
* @param amount Amount to convert
* @param date Optional date for historical conversion (YYYY-MM-DD format)
* @returns Promise resolving to axios response with conversion data
*/
convert(from?: string, to?: string, amount?: number, date?: string): Promise<AxiosResponse<ConvertResponse>>;

/**
* Get exchange rates for a specific time period
* @param startDate Start date in YYYY-MM-DD format
* @param endDate End date in YYYY-MM-DD format
* @param base Optional base currency (defaults to USD)
* @param currencies Optional array of currencies to return rates for
* @returns Promise resolving to axios response with timeframe data
*/
timeframe(startDate: string, endDate: string, base?: string, currencies?: string[]): Promise<AxiosResponse<TimeframeResponse>>;

/**
* Get exchange rate changes between two dates
* @param startDate Start date in YYYY-MM-DD format
* @param endDate End date in YYYY-MM-DD format
* @param base Optional base currency (defaults to USD)
* @param currencies Optional array of currencies to return changes for
* @returns Promise resolving to axios response with change data
*/
change(startDate: string, endDate: string, base?: string, currencies?: string[]): Promise<AxiosResponse<ChangeResponse>>;

/**
* Get current API usage statistics
* @returns Promise resolving to axios response with usage data
*/
usage(): Promise<AxiosResponse<UsageResponse>>;
}

declare const api: ForexRateAPI;
export = api;
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"name": "forexrateapi",
"version": "1.1.2",
"name": "@mileszim/forexrateapi",
"version": "1.1.3",
"description": "Official Node.js Library for ForexRateAPI",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "ForexRateAPI",
"license": "MIT",
"dependencies": {
"axios": "^1.6.7"
"axios": "^1.11.0"
},
"homepage": "https://forexrateapi.com",
"repository": {
"type": "git",
"url": "https://github.com/forexrateapi/forexrateapi-nodejs.git"
"url": "https://github.com/mileszim/forexrateapi-nodejs.git"
},
"keywords": [
"foreign exchange rates",
Expand Down