Reputation: 11
So I'm pretty new to the world of tech and coding. I have a python script that i would like to host on google cloud platform, so it can continuously scrape yahoo finance and save prices at 5min intervals. Im able to run it on my personal machine but struggle to get it up on GCP. I already made an account a compute engine. Im just not sure where i need to go to install the extra packages and then run the script.
!pip install numpy
!pip install pandas
!pip install yfinance
!pip install datetime
from pandas_datareader import data as pdr
import yfinance as yf
import datetime
import pandas as pd
import numpy as np
def test_yfinance():
# list of stocks, ETF, Currencies you would like to test or trade
for symbol in ['SPY', 'AAPL', 'MSFT', 'IWO', 'VFINX']:
# START DATE FOR THE BACKTEST
data = yf.download(symbol, start='1993-01-01', interval='5')
# SAVE DATA TO THIS LOCATION AS A CSV AND XLSX FILE
data.to_csv("/content/drive/MyDrive/yfinanceData/stocks/{}.csv".format(symbol))
if __name__ == "__main__":
test_yfinance()
I was running this code on Googles Colaboratory's Jupyter Notebook
The VM instances that im running on GCP is Ubuntu-Pro-1604-xenial
Upvotes: 1
Views: 970
Reputation: 1979
I would recommend using Cloud Functions and Cloud Scheduler! Cloud Functions is where you will deploy your code and then Cloud Scheduler will let you easily schedule it to be called ever 5 minutes!
Here is a great post to walk your through the steps in more detail.
How to schedule a recurring Python script on Google Cloud
Upvotes: 2