fxdatapi-js-sdk
v1.0.9
Published
An SDK for interacting with the Currency API by Hori Systems Limited.
Downloads
10
Maintainers
Readme
Currency API SDK
Develop and deploy applications, mobile and web, with popular JavaScript Frameworks using Currency API SDK.
Install
yarn add fxdatapi-js-sdk
# or
npm i fxdatapi-js-sdk
Example of Usage
import {
login,
convertCurrency,
convertAllCurrencies,
getAllCurrencies,
getCurrencyById,
getAllHistoricalRates,
getHistoricalRateById,
getDailyAverage,
getWeeklyAverage,
getMonthlyAverage,
getAllMarginsSpreads,
getMarginsSpreadsById,
getAllPerformances,
getPerformancesById,
getAllSignals,
getSignalsById,
} from 'fxdatapi-js-sdk';
async function retrieveFxdatapi() {
try {
const credentials = {
username: 'your_username',
password: 'your_password',
};
const response = await login(credentials);
console.log('Login successful:', response);
// Test the convertCurrency function
const conversionRequest = {
username: credentials.username,
date: '2023_04_02',
base_currency: 'GBP',
target_currency: 'CAD',
amount: '500',
};
const conversionResponse = await convertCurrency(response.token, conversionRequest);
console.log('Conversion successful:', conversionResponse);
// Test the convertAllCurrencies function
const convertAllRequest = {
username: credentials.username,
base_currency: 'GBP',
amount: 120,
date: '2023_04_02',
};
const convertAllResponse = await convertAllCurrencies(response.token, convertAllRequest);
console.log('Convert all currencies successful:', convertAllResponse);
// Test the getAllCurrencies function
const getAllCurrenciesRequest = {
username: credentials.username,
day: 2,
month: 4,
year: 2023,
};
const getAllCurrenciesResponse = await getAllCurrencies(response.token, getAllCurrenciesRequest);
console.log('Get all currencies successful:', getAllCurrenciesResponse);
// Test the getCurrencyById function
const uuid = 'some-uuid'; // Replace with a valid UUID for a currency
const getCurrencyByIdRequest = {
uuid,
username: credentials.username,
day: 2,
month: 4,
year: 2023,
};
const currencyByIdResponse = await getCurrencyById(response.token, getCurrencyByIdRequest);
console.log('Get currency by ID successful:', currencyByIdResponse);
// Test the getAllHistoricalRates function
const getAllHistoricalRatesRequest = {
username: credentials.username,
date: '2023_04_02',
day: 2,
month: 4,
year: 2023,
};
const getAllHistoricalRatesResponse = await getAllHistoricalRates(response.token, getAllHistoricalRatesRequest);
console.log('Get all historical rates successful:', getAllHistoricalRatesResponse);
// Test the getHistoricalRateById function
const historicalUuid = 'some-uuid'; // Replace with a valid UUID for a historical rate
const getHistoricalRateByIdRequest = {
uuid: historicalUuid,
username: credentials.username,
day: 2,
month: 4,
year: 2023,
date_string: '2023_04_02',
};
const historicalRateByIdResponse = await getHistoricalRateById(response.token, getHistoricalRateByIdRequest);
console.log('Get historical rate by ID successful:', historicalRateByIdResponse);
// Test the getDailyAverage function
const dailyAverageRequest = {
date: '2023_04_10',
};
const dailyAverageResponse = await getDailyAverage(dailyAverageRequest);
console.log('Get daily average successful:', dailyAverageResponse);
// Test the getWeeklyAverage function
const weeklyAverageRequest = {
from_date: '2023_04_03',
to_date: '2023_04_07',
};
const weeklyAverageResponse = await getWeeklyAverage(weeklyAverageRequest);
console.log('Get weekly average successful:', weeklyAverageResponse);
// Test the getMonthlyAverage function
const monthlyAverageRequest = {
year: '2023',
month: '04',
};
const monthlyAverageResponse = await getMonthlyAverage(monthlyAverageRequest);
console.log('Get monthly average successful:', monthlyAverageResponse);
// Test the getAllMarginsSpreads function
const getAllMarginsSpreadsRequest = {
username: credentials.username,
day: 19,
month: 4,
year: 2023,
};
const getAllMarginsSpreadsResponse = await getAllMarginsSpreads(response.token, getAllMarginsSpreadsRequest);
console.log('Get all margins spreads successful:', getAllMarginsSpreadsResponse);
// Test the getMarginsSpreadsById function
const marginsSpreadsUuid = 'margins_spreads_uuid'; // Replace with a valid UUID for a margins spread
const getMarginsSpreadsByIdRequest = {
username: credentials.username,
day: 19,
month: 4,
year: 2023,
};
const marginsSpreadsByIdResponse = await getMarginsSpreadsById(response.token, marginsSpreadsUuid, getMarginsSpreadsByIdRequest);
console.log('Get margins spreads by ID successful:', marginsSpreadsByIdResponse);
// Test the getAllPerformances function
const getAllPerformancesRequest = {
username: credentials.username,
};
const getAllPerformancesResponse = await getAllPerformances(response.token, getAllPerformancesRequest);
console.log('Get all performances successful:', getAllPerformancesResponse);
// Test the getPerformancesById function
const performancesUuid = 'performances_uuid'; // Replace with a valid UUID for a performance
const getPerformancesByIdRequest = {
username: credentials.username,
};
const performancesByIdResponse = await getPerformancesById(response.token, performancesUuid, getPerformancesByIdRequest);
console.log('Get performances by ID successful:', performancesByIdResponse);
// Test the getAllSignals function
const getAllSignalsRequest = {
username: credentials.username,
};
const getAllSignalsResponse = await getAllSignals(response.token, getAllSignalsRequest);
console.log('Get all signals successful:', getAllSignalsResponse);
// Test the getSignalsById function
const signalsUuid = 'signals_uuid'; // Replace with a valid UUID for a signal
const getSignalsByIdRequest = {
username: credentials.username,
};
const signalsByIdResponse = await getSignalsById(response.token, signalsUuid, getSignalsByIdRequest);
console.log('Get signals by ID successful:', signalsByIdResponse);
} catch (error) {
if (error instanceof Error) {
console.error('Error:', error.message);
} else {
console.error('An unknown error occurred:', error);
}
}
}
retrieveFxdatapi();
The Currency API documentation is available here. If you need further assistance, don't hesitate to contact us.
License
This project is licensed under the BSD 3-Clause License.
Copyright
(c) 2023 Hori Systems Limited.