diff --git a/.gitignore b/.gitignore index 513fa7d..b254bd6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ __pycache__/StockData.cpython-37.pyc __pycache__/ *.pyc +quickstart.py +creds.json diff --git a/StockData.py b/StockData.py index 112a8da..a562b00 100644 --- a/StockData.py +++ b/StockData.py @@ -14,12 +14,14 @@ Barchart: No # Alpha Vantage API Key: O42ICUV58EIZZQMU # Barchart API Key: a17fab99a1c21cd6f847e2f82b592838 # Possible other one? f40b136c6dc4451f9136bb53b9e70ffa # Tiingo API Key: 2e72b53f2ab4f5f4724c5c1e4d5d4ac0af3f7ca8 +# Tradier API Key: n26IFFpkOFRVsB5SNTVNXicE5MPD # If you're going to take these API keys and abuse it, you should really reconsider your life priorities apiAV = 'O42ICUV58EIZZQMU' #apiBarchart = 'a17fab99a1c21cd6f847e2f82b592838' # 150 getHistory queries per day apiBarchart = 'f40b136c6dc4451f9136bb53b9e70ffa' apiTiingo = '2e72b53f2ab4f5f4724c5c1e4d5d4ac0af3f7ca8' +apiTradier = 'n26IFFpkOFRVsB5SNTVNXicE5MPD' ''' Monthly Bandwidth = 5 GB Hourly Requests = 500 @@ -451,16 +453,16 @@ class Stock: return listOfFirstLastDates = [] + self.allLists = [] # IEX - print("\nIEX") listIEX = Stock.getIEX(self) #print(listIEX) if listIEX != 'Not available': listOfFirstLastDates.append((listIEX[0], listIEX[1])) self.allLists.append(listIEX) - + # Alpha Vantage print("\nAlpha Vantage (AV)") listAV = Stock.getAV(self) @@ -481,9 +483,9 @@ class Stock: #print(self.allLists) #print(listOfFirstLastDates) - print("\n") - print(len(self.allLists), "available sources for", self.name) if (len(self.allLists) > 0): + print("\n") + print(len(self.allLists), "available sources for", self.name) self.absFirstLastDates = Stock.getFirstLastDate(self, listOfFirstLastDates) print("\nThe absolute first date with close values is:", self.absFirstLastDates[0]) print("The absolute last date with close values is:", self.absFirstLastDates[1]) @@ -501,7 +503,7 @@ class Stock: print("No sources have data for", self.name) def main(): # For testing purposes - stockName = 'IWV' + stockName = 'spy' stock1 = Stock(stockName) print("Finding available dates and close values for", stock1.name) Stock.main(stock1) diff --git a/listGoogle.py b/listGoogle.py new file mode 100644 index 0000000..f911dba --- /dev/null +++ b/listGoogle.py @@ -0,0 +1,54 @@ +# https://support.google.com/docs/answer/3093281?hl=en +# Historical data cannot be downloaded or accessed via the Sheets API or Apps Script. If you attempt to do so, you will see a #N/A error in place of the values in the corresponding cells of your spreadsheet. + +import gspread, time, webbrowser, msvcrt +from oauth2client.service_account import ServiceAccountCredentials + +def main(): + scope = ['https://spreadsheets.google.com/feeds', + 'https://www.googleapis.com/auth/drive'] + + credentials = ServiceAccountCredentials.from_json_keyfile_name('creds.json', scope) + + gc = gspread.authorize(credentials) + ''' + # Just by ID: + #sheet = gc.open_by_key('1YS8qBQCXKNfSgQgXeUdSGOd6lM2wm-inV0_1YE36vQM') + sheet = gc.open_by_url('https://docs.google.com/spreadsheets/d/1YS8qBQCXKNfSgQgXeUdSGOd6lM2wm-inV0_1YE36vQM') + worksheet = sheet.get_worksheet(0) + worksheet.update_acell('B1', 'bingo!') + #worksheet.update_cell(1, 2, 'Bingo!') + val = worksheet.acell('B1').value + #val = worksheet.cell(1, 2).value + print(val) + ''' + url = 'https://docs.google.com/spreadsheets/d/1YS8qBQCXKNfSgQgXeUdSGOd6lM2wm-inV0_1YE36vQM' + surl = 'https://www.andrewkdinh.com/u/listGoogle' + print("Opening", url) + #webbrowser.open(surl) + sheet = gc.open_by_url(url) + worksheet = sheet.get_worksheet(0) + print('Writing Google Finance function to A1') + worksheet.update_cell(1, 1, '=GOOGLEFINANCE("GOOG", "price", DATE(2014,1,1), DATE(2014,12,31), "DAILY")') + print('\nOpening link to the Google Sheet. Please download the file as comma-separated values (.csv) and move it to the directory of this Python file', + '\nFile > Download as > Comma-separated values(.csv,currentsheet)') + print("If the link did not open, please go to", surl) + print("Press any key to continue") + #time.sleep(45) + ''' + for i in range(60, 0, -1): + print(i, end='\r') + time.sleep(1) + ''' + waiting = True + while waiting == True: + if msvcrt.kbhit(): + waiting = False + + print("e") + + #val = worksheet.acell('A1').value + #print(val) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/main.py b/main.py index ecaa6e9..436088b 100644 --- a/main.py +++ b/main.py @@ -20,17 +20,21 @@ from StockData import Stock listOfStocks = [] numberOfStocks = int(input("How many stocks or mutual funds would you like to analyze? ")) for i in range(0, numberOfStocks, 1): - print("Stock", i+1, ": ", end='') - stockName = str(input()) - listOfStocks.append(i) - listOfStocks[i] = Stock() - listOfStocks[i].setName(stockName) - print(listOfStocks[i].name) + print("Stock", i+1, ": ", end='') + stockName = str(input()) + listOfStocks.append(i) + listOfStocks[i] = Stock() + listOfStocks[i].setName(stockName) + #print(listOfStocks[i].name) for i in range(0, numberOfStocks, 1): - print("\n") - print(listOfStocks[i].name) - Stock.main(listOfStocks[i]) + print("\n") + print(listOfStocks[i].name) + Stock.main(listOfStocks[i]) + +#print(listOfStocks[0].name, listOfStocks[0].absFirstLastDates, listOfStocks[0].finalDatesAndClose) +print("\nWhich indicator would you like to look at? \n1. Expense Ratio") +indicator = str(input) ''' stockName = 'IWV' stock1 = Stock(stockName)