From c171590c5d995165aa8eb1c09c4dac1e4219f633 Mon Sep 17 00:00:00 2001 From: CodeGhost28 Date: Tue, 8 Oct 2024 16:08:01 +0200 Subject: [PATCH] Create api.tsx --- lib/api.tsx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/api.tsx diff --git a/lib/api.tsx b/lib/api.tsx new file mode 100644 index 0000000000..eb11380feb --- /dev/null +++ b/lib/api.tsx @@ -0,0 +1,28 @@ +// api.tsx (Next.js API for fetching trading data) + +import type { NextApiRequest, NextApiResponse } from 'next'; + +const ALPHA_MARKETS_API_KEY = 'YOUR_ALPHA_MARKETS_API_KEY'; // Replace with your actual API key +const BASE_URL = 'https://api.alphamarkets.com/v1/markets'; // Replace with the actual Alpha Markets base URL + +export default async function handler(req: NextApiRequest, res: NextApiResponse) { + const { symbol } = req.query; // Example: EURUSD, BTCUSD, XAUUSD + if (!symbol) { + res.status(400).json({ error: 'Symbol is required' }); + return; + } + + try { + // Fetch trading data from Alpha Markets API + const response = await fetch(`${BASE_URL}/quotes?symbol=${symbol}&apikey=${ALPHA_MARKETS_API_KEY}`); + const data = await response.json(); + + if (response.ok) { + res.status(200).json({ data }); + } else { + res.status(500).json({ error: data.message }); + } + } catch (error) { + res.status(500).json({ error: 'Failed to fetch trading data' }); + } +}