Using the 1Forge API with JavaScript

The 1Forge API provides real-time forex and cryptocurrency market data. In this article, we will explore how to use the 1Forge API with JavaScript.

Getting Started

First, you will need to sign up for a free API key on the 1Forge website. Once you have your API key, you can start making requests to the API using JavaScript.

Making a Request

To make a request, you will need to use the fetch function, which is a part of the JavaScript window object. The fetch function allows you to send a request to a URL and receive a response in return.

Here's an example of how to use the fetch function to get the current price of a currency pair:

const apiKey = 'your-api-key-here';
const symbol = 'EURUSD';
const url = `https://api.1forge.com/quotes?pairs=${symbol}&api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data));

In this example code, we are using the fetch function to send a request to the 1Forge API with our API key and the desired currency pair, and then we are using the json method to convert the response to a JavaScript object.

Available Endpoints

The 1Forge API provides several endpoints that you can use to retrieve different types of market data. Here are some examples:

Currency Pair Quotes

This endpoint returns the current price of one or more currency pairs.

const apiKey = 'your-api-key-here';
const symbols = 'EURUSD,GBPUSD';

const url = `https://api.1forge.com/quotes?pairs=${symbols}&api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data));

Market Status

This endpoint returns the status of the forex market.

const apiKey = 'your-api-key-here';
const url = `https://api.1forge.com/market_status?api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data));

Currency Symbols

This endpoint returns a list of all available currency symbols.

const apiKey = 'your-api-key-here';
const url = `https://api.1forge.com/symbols?api_key=${apiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data));

Conclusion

In this article, we have explored how to use the 1Forge API with JavaScript. We have covered how to make requests to the API using the fetch function, and we have provided examples for some of the available endpoints. Now that you have a better understanding of how to use the 1Forge API, you can start building your own applications that rely on real-time forex and cryptocurrency market data.

Related APIs in Currency Exchange