Sitemap
Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

How to Get Real-Time and Historical Forex Data Using the EODHD API (with Python Examples)

4 min readOct 21, 2025

--

Press enter or click to view image in full size

The Real Problem

Every trader and developer who’s tried to build a Forex dashboard or trading bot has hit the same wall: reliable data is hard to find, and good APIs are expensive.

Many APIs claim to offer “real-time Forex data,” but:

  • They limit requests or charge per call.
  • They don’t provide full historical coverage.
  • Or they make integration painful.

And without clean, accessible data, your analysis or trading algorithm is blind.

The Solution: The EODHD Forex Data API

EODHD offers one of the most practical and developer-friendly Forex APIs out there.

It allows you to:

  • 📈 Get real-time and historical Forex data in JSON or CSV format
  • 💱 Access major, minor, and exotic currency pairs
  • 🧠 Integrate with Python, Excel, Power BI, or Streamlit in minutes
  • 💸 Combine multiple data sources (stocks, crypto, commodities) under one API key

It’s the ideal API for traders, analysts, and developers looking to automate insights or run algorithmic trading experiments.

🧪 Case 1: Get the Current Exchange Rate (EUR/USD)

import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://eodhd.com/api/real-time"
symbol = "EURUSD.FOREX"
url = f"{BASE_URL}/{symbol}?api_token={API_KEY}&fmt=json"
data = requests.get(url).json()
print(data)

Output Example:

{
"code": "EURUSD.FOREX",
"timestamp": 1725537000,
"open": 1.0862,
"high": 1.0884,
"low": 1.0837,
"close": 1.0871
}

Perfect for updating dashboards or trading bots with live market prices.

Case 2: Get Historical Forex Data

import requests
import pandas as pd
API_KEY = "YOUR_API_KEY"
url = f"https://eodhd.com/api/eod/EURUSD.FOREX?api_token={API_KEY}&fmt=json"
df = pd.DataFrame(requests.get(url).json())
df["date"] = pd.to_datetime(df["date"])
print(df.head())

You’ll get a clean DataFrame with open, high, low, close, and volume data — ready for analysis or visualization.

Case 3: Visualize Forex Data in Plotly

import plotly.express as px
fig = px.line(df, x="date", y="close", title="EUR/USD Historical Prices")
fig.show()

Simple, interactive, and perfect for analytics dashboards.

Case 4: Real-Time Forex Data Monitoring

You can easily fetch live Forex updates every few seconds. Here’s a basic example using Python’s time library:

import requests, time
API_KEY = "YOUR_API_KEY"
symbol = "EURUSD.FOREX"
while True:
url = f"https://eodhd.com/api/real-time/{symbol}?api_token={API_KEY}&fmt=json"
data = requests.get(url).json()
print(f"{data['code']}: {data['close']}")
time.sleep(5) # fetch every 5 seconds

Tip: Combine this with Telegram or Slack bots to send real-time alerts when a currency crosses a key threshold.

Case 5: Build a Simple Forex Trading Bot (Moving Average Cross Strategy)

Let’s implement a basic trading strategy using two moving averages — a common beginner’s approach.

  • Buy signal → when the short-term MA crosses above the long-term MA.
  • Sell signal → when it crosses below.
import pandas as pd
import requests
import numpy as np
API_KEY = "YOUR_API_KEY"
url = f"https://eodhd.com/api/eod/EURUSD.FOREX?api_token={API_KEY}&fmt=json"
df = pd.DataFrame(requests.get(url).json())
df["date"] = pd.to_datetime(df["date"])
df["close"] = df["close"].astype(float)
# Moving averages
df["MA_10"] = df["close"].rolling(window=10).mean()
df["MA_30"] = df["close"].rolling(window=30).mean()
# Trading signals
df["Signal"] = np.where(df["MA_10"] > df["MA_30"], 1, 0)
df["Position"] = df["Signal"].diff()
# Display buy/sell signals
print(df[df["Position"] == 1][["date", "close"]].head()) # Buy
print(df[df["Position"] == -1][["date", "close"]].head()) # Sell

This gives you clear buy/sell signals based on moving average crossovers. From here, you can integrate it with your broker’s API or MetaTrader for real trades.

Case 6: Backtesting Your Forex Strategy

Before risking real money, it’s essential to test your idea using historical data.

Get Kevin Meneses González’s stories in your inbox

Join Medium for free to get updates from this writer.

Here’s how to do a simple backtest using your signals:

initial_balance = 10000
balance = initial_balance
position = 0
for i in range(1, len(df)):
if df["Position"].iloc[i] == 1: # Buy
position = balance / df["close"].iloc[i]
balance = 0
elif df["Position"].iloc[i] == -1 and position > 0: # Sell
balance = position * df["close"].iloc[i]
position = 0
final_balance = balance + (position * df["close"].iloc[-1])
profit = final_balance - initial_balance
print(f"Final balance: ${final_balance:.2f} | Profit: ${profit:.2f}")

With this, you’ll see how your strategy would have performed using real historical Forex data from EODHD.

✅ Pro Tip: Once you have signals, try using libraries like backtrader or vectorbt for professional backtesting and portfolio optimization.

Case 7: Create a Simple Forex Dashboard (Streamlit Example)

import streamlit as st
import requests
import pandas as pd
import plotly.express as px
st.title("💹 Forex Dashboard (Powered by EODHD API)")
symbol = st.text_input("Enter Forex Pair", "EURUSD.FOREX")
api_key = st.text_input("Your EODHD API Key", "YOUR_API_KEY")
if st.button("Load Data"):
url = f"https://eodhd.com/api/eod/{symbol}?api_token={api_key}&fmt=json"
df = pd.DataFrame(requests.get(url).json())
df["date"] = pd.to_datetime(df["date"])
fig = px.line(df, x="date", y="close", title=f"{symbol} Historical Prices")
st.plotly_chart(fig)

In a few seconds, you can visualize historical Forex data interactively — perfect for traders, analysts, or fintech developers.

Key Takeaways

  • The EODHD Forex Data API is ideal for real-time monitoring, trading bots, and backtesting.
  • It’s affordable, simple, and integrates perfectly with Python and financial libraries.
  • Whether you’re building dashboards, trading systems, or analytics tools — this API gives you clean, reliable data.

“Data is the new oil, but only if you know how to refine it.”

🔗 Start Building Your Forex Projects Today

Get access to real-time and historical Forex data from EODHD and start experimenting today. You’ll also get a 10% discount through my affiliate link: 👉 https://eodhd.com/pricing-special-10?via=kmg&ref1=Meneses

Build dashboards, bots, and trading systems — all powered by the EODHD API.

If you’re interested in consulting or collaboration, feel free to reach out at kevinmenesesgonzalez@gmail.com.

A message from our Founder

Hey, Sunil here. I wanted to take a moment to thank you for reading until the end and for being a part of this community.

Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? We don’t receive any funding, we do this to support the community. ❤️

If you want to show some love, please take a moment to follow me on LinkedIn, TikTok, Instagram. You can also subscribe to our weekly newsletter.

And before you go, don’t forget to clap and follow the writer️!

--

--

Kevin Meneses González
Kevin Meneses González

Written by Kevin Meneses González

SAP-Salesforce CRM consultant & data analyst with Python. Chess enthusiast & content creator. Bridging data with strategy. Investor in stocks and AI enthusiast

Python in Plain English
Python in Plain English

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.