// Import libraries
const axios = require('axios');
// Define Myfxbook API URL and your credentials
const MYFXBOOK_API_URL = "https://api.myfxbook.com/api/";
const API_KEY = "YOUR_API_KEY";
// Get today's date and previous day's date
const today = new Date().toISOString().slice(0, 10);
const yesterday = new Date(new Date().getTime() - 24 * 60 * 60 * 1000).toISOString().slice(0, 10);
// Build the API request URL
const url = `${MYFXBOOK_API_URL}/gain?account=${10577213}&from=${yesterday}&to=${today}`;
// Set headers with your API key
const headers = {
Authorization: `Bearer ${API_KEY}`,
};
// Send the API request
axios.get(url, { headers })
.then(response => {
if (response.status === 200) {
// Extract daily gain
const { daily_gain } = response.data;
// Display daily gain on your website
console.log(`Daily gain: ${daily_gain}`);
} else {
console.error(response.statusText);
}
})
.catch(error => {
console.error(error);
});