【问题标题】:How do I get a forex ticker working in yahoo finance?我如何让外汇行情在雅虎金融工作?
【发布时间】:2019-11-09 04:08:41
【问题描述】:

当我使用任何不是外汇对的代码时,它都有效。但是对于 fx 代码,它不会。我最终得到一个错误。

from yahoo_fin.stock_info import get_live_price
get_live_price('EURUSD=X')

下面是我遇到的错误。

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-15-a1b6fb5ddbd7> in <module>
     4 
     5 #Stock = input('Stock:')
----> 6 get_live_price('EURUSD=X')
     7 #stockprice = get_live_price(str(Stock))
     8 

//anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_live_price(ticker)
   336     '''    
   337 
--> 338     df = get_data(ticker, end_date = pd.Timestamp.today() + pd.DateOffset(10))
   339 
   340 

//anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_data(ticker, start_date, end_date, index_as_date)
    58     html = html.decode()
    59 
---> 60     start = html.index('"HistoricalPriceStore"')
    61     end = html.index("firstTradeDate")
    62 

ValueError: substring not found

有什么想法吗?这显然与股票行情有关。当我使用“nflx”或“aapl”时,它就像一个魅力。似乎是外汇交易行为不端?

【问题讨论】:

    标签: python finance yahoo yahoo-finance stock


    【解决方案1】:

    如果标签是由垃圾组成的,这与您得到的错误相同。 您能否尝试请求格式错误的标签/代码?

    In [12]: from yahoo_fin.stock_info import get_live_price 
        ...: get_live_price('poop') 
        ...:  
        ...:                                                                                                                                                                                     
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-12-17c9a30a78a2> in <module>
          1 from yahoo_fin.stock_info import get_live_price
    ----> 2 get_live_price('poop')
          3 
    
    ~/anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_live_price(ticker)
        336     '''    
        337 
    --> 338     df = get_data(ticker, end_date = pd.Timestamp.today() + pd.DateOffset(10))
        339 
        340 
    
    ~/anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_data(ticker, start_date, end_date, index_as_date)
         58     html = html.decode()
         59 
    ---> 60     start = html.index('"HistoricalPriceStore"')
         61     end = html.index("firstTradeDate")
         62 
    
    ValueError: substring not found
    

    【讨论】:

    • 是的,这就是问题所在。雅虎提供的代码是垃圾。我想知道为了获得外汇对的当前价格而实际使用的股票代码
    • 当我检查谷歌页面时,我看到...

      Alphabet Inc. (GOOG)

      当我调用 GOOG 时,我得到了一个值,但是当我尝试使用你的

      EUR/USD (EURUSD=X)

      时,EURUSD =X 不起作用
    • quant.stackexchange.com/questions/34249/…这是你的问题,雅虎财经不支持。
    猜你喜欢
    • 2017-10-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多