Integrating financial market data into your application can often involve complex HTTP requests and parsing logic. The TraderMade Node.js SDK simplifies this process, allowing developers to interact with our Forex and CFD API using clean, native JavaScript functions.
In this tutorial, we will cover how to use the SDK to perform four essential tasks:
- Get Live Exchange Rates: Fetch real-time streaming data.
- Get Time Series Data: Retrieve daily OHLC data for charting.
- Get Available CFDs: Access a list of available instruments.
- Convert Currency: Calculate specific values between pairs (Backend Example).
Prerequisites
- Node.js: Installed on your system (version 14+ recommended).
- TraderMade Account: A valid API key (sign up for free at tradermade.com/signup).
Installation & Setup
First, install the SDK via npm:
npm install tradermade-nodejs-sdk
We also recommend using dotenv to manage your API key securely:
npm install dotenv
Create a .env file in your project root:
TRADERMADE_API_KEY=your_api_key_here
SDK Initialization
In your JavaScript file, import the library and configure it with your API key. This setup is common to all examples below.
import TraderMade from "tradermade-nodejs-sdk";
import dotenv from "dotenv";
dotenv.config();
const tm = new TraderMade();
tm.setRestApiKey(process.env.TRADERMADE_API_KEY);
1. Get Live Exchange Rates
This function allows you to fetch real-time bid/ask quotes for single or multiple currencies simultaneously.
tm.getLiveRates("EURUSD").then((data) => {
console.log("Live Rates:", data);
});
To fetch live rates for multiple currencies or cfds, pass them as a comma-separated string as shown below.
// Pass multiple currencies or instruments as a comma-separated string
tm.getLiveRates("GBPUSD,UK100,USDJPY").then((data) => {
console.log("Live Rates:", data);
});
2. Get TimeSeries Data
For detailed analysis or charting, you can retrieve historical OHLC (Open, High, Low, Close) data for a specific currency pair within a defined time range.
tm.getTimeSeriesData(
"EURUSD",
"2026-01-08",
"2026-01-10",
"daily",
"1",
"index",
).then((data) => {
console.log(data);
});
3. Get Available CFDs
This function is ideal for retrieving a list of all available CFDs (Contract for Differences) that you can query.There is also other function to get a list of all crypto and FX symbols.To get a full list of functions visit our github examples page.
tm.getCfdList().then((data) => {
console.log("CFD list:", data);
});
Use Case: Building a Backend API
You can easily wrap these SDK functions in an Express.js server to provide data to your frontend application. Here is a quick example of a Currency Conversion endpoint:
import express from "express";
import TraderMade from "tradermade-nodejs-sdk";
import dotenv from "dotenv";
dotenv.config();
const app = express();
const tm = new TraderMade();
tm.setRestApiKey(process.env.TRADERMADE_API_KEY);
app.get("/convert", async (req, res) => {
const { from, to, amount } = req.query;
try {
const data = await tm.getCurrencyConversion(from, to, amount);
res.json(data);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(3000, () => console.log("Server running on port 3000"));
Conclusion
The TraderMade Node.js SDK provides a unified interface to access a wide range of market data types. Whether you need live streaming rates for a ticker, conversion logic for a checkout page, or historical data for analytical charts, the SDK handles the heavy lifting so you can focus on building your application features.
Resources:
- NPM Package: tradermade-nodejs-sdk
- Source Code: Get full code from GitHub (Example Folder)
- API Documentation: Official SDK Documentation