Skip to content

How to use with Pandas Datareader? #53

@windowshopr

Description

@windowshopr

Would love some input on how to make that work, specifically when using DataReader and the Yahoo Finance API to get stock data. I can make requests for stock data using the DataReader once, and then after that I get an error, until the next day. My code looks simple:

import pandas as pd
import pandas_datareader.data as web
from datetime import datetime
from time import sleep
from http_request_randomizer.requests.proxy.requestProxy import RequestProxy

# list of stock's data to get
stocks = [

'USO',
'FXI',
'EEM'

]

start = datetime(2018, 9, 19)
end = datetime.now()

for i in stocks:
    sleep(5)
    
    try:
        data = web.DataReader(i, 'yahoo', start, end)
        df = data[['Date','Open','High','Low','Close','Adj Close','Volume']]
        # Round some of the results to 2 decimal places, then save .csv file
        df = df.round({"Open":2, "High":2, "Low":2, "Close":2, "Adj Close":2})
        df.to_csv(str(i) + '.csv')
        print('Successfully downloaded ' + str(i))
        continue
    
    except:
        print('Failed to download ' + str(i))
        continue

So how could one integrate the http randomizer into that? I tried playing around with it a bit but couldn't figure it out. Something like replacing the url used in the request with the datareader somehow? If that makes sense?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions