简体   繁体   中英

Is it possible to read real live (Energy and Metal)data from Forex using python

I have python code which only read real live data such currencies:

 df1 = yf.download(tickers = 'audusd' ,period ='1d', interval = '1h')  
 df2 = yf.download(tickers = 'usdjpy' ,period ='1d', interval = '1h')

but for gold (xauusd) and Natural Gas(xbrusd) and others does not work:

df2 = yf.download(tickers = 'xauusd' ,period ='1d', interval = '1h')  does not work
df3 = yf.download(tickers = 'xbrusd' ,period ='1d', interval = '1h') 

does not work

How I can read metal or energy or other from forex using yfinance library ?

Use pip to install pandas-datareader :

pip install pandas-datareader

If I'm not mistaken, the correct tickers are GC=F for gold and NG=F for natural gas.

from pandas_datareader import data as pdr
import yfinance as yf
yf.pdr_override()

df1 = pdr.get_data_yahoo('AUDUSD=X', period='1d', interval='1h')
df2 = pdr.get_data_yahoo('JPY=X', period='1d', interval='1h')
df3 = pdr.get_data_yahoo('GC=F', period='5d', interval='1h')
df4 = pdr.get_data_yahoo('NG=F', period='5d', interval='1h')

This does work when period='5d' , but doesn't work when period='1d' .

Here's a quick start guide on using yfinance .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM