Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forex historical data in Python

Tags:

python

api

forex

Have been searching for hours so please be kind.

Need solutions to get historical Forex data in Python.

For stocks it is easy:

import pandas as pd
import pandas_datareader as pdr

start = dt.date.today() - dt.timedelta(days=30)
end = dt.date.today()

df = pdr.DataReader('AAPL', 'google', start, end)
print(df.head())

Have tried google, yahoo, fred and oanda. Nothing seems to work.

Please give a code example of how to request the data. (In most cases one line should be fine).

Thank you.

like image 344
Yster Avatar asked Jun 17 '17 12:06

Yster


People also ask

How do I get forex data in Python?

When using the Python programming language to get live forex data using CurrencyAPI.io, there are two options. One is by importing the 'http. client' module' using 'import http. client' and the other is by importing the 'requests' module using 'import requests'.

Does Yfinance have forex?

However, when you have a good strategy, forex assets can help you earn a decent amount of money. As an algo trader exploring this amazing market, the yfinance library will helps us to do download forex price data easily.

What is forex Python library?

Forex Python is a Free Foreign exchange rates and currency conversion. Features: List all currency rates. BitCoin price for all curuncies. Converting amount to BitCoins. Get historical rates for any day since 1999.

How do I download forex data?

Open the History Center in MetaTrader from Tools. Select the asset you want to trade with in the “Symbols” list. Double click and load the data in the table. Use the Import option to select the downloaded Forex Historical data from the App.


1 Answers

Do you just need historical currency values?

Try using the forex_python module with the datetime class ( from the datetime module ). I'm using python 3 but I doubt that matters too much.

These exchange rates are the 3pm (CET) data from the European Central Bank, since 1999.

>>> from datetime import datetime
>>> from forex_python.converter import get_rate

>>> t = datetime(2001, 10, 18)  # the 18th of October, 2001
>>> get_rate("USD", "GBP", t)
0.69233
>>> get_rate("GBP", "USD", t)
1.4444
>>> 1 / 1.4444   # check
0.6923289947382997 

>>> t = datetime(2006, 6, 26)  # June 26th, 2006
>>> get_rate("GBP", "USD", t)
1.8202

So
on 18/10/01, 1 USD == 0.69 GBP,
on 26th June, 2006, 1 GBP == 1.82 USD.

like image 83
Gregory Fenn Avatar answered Sep 21 '22 01:09

Gregory Fenn