Exemplo n.º 1
0
def update1YearForAll():
    wb = openpyxl.load_workbook(
        'C:/Users/aj282/OneDrive/Desktop/pythonStocks/my1000Xl.xlsx'
    )  #if file exists
    sheet = wb.active
    api = getApi()
    myTickers = sp1000Wiki.getWiki1000()
    params = getParams()

    for i, v in enumerate(myTickers):
        try:
            myURL = 'https://api.polygon.io/v1/open-close/{}/{}'.format(
                v, stockDataFrames.get1Y())
            resp = api.polygon._session.request('GET', myURL, params=params)

            if (i + 1) % 26 == 0:
                time.sleep(5)

            jjson = resp.json()
            #print(jjson)
            try:
                rowC = 'C' + str(i + 2)
                print(jjson['symbol'])
                print(jjson['low'])
                sheet[rowC] = jjson['low']
            except:
                rowC = 'C' + str(i + 2)
                print("Error occured at {}".format(rowC))
                sheet[rowC] = "N/A"
        except:
            sheet[rowC] = "N/A"
            print("Error occured at {}".format(rowC))
            print("Entered \"N\\A\" at {}".format(rowC))
    wb.save('C:/Users/aj282/OneDrive/Desktop/pythonStocks/my1000Xl.xlsx')
Exemplo n.º 2
0
def write1000TickersExcel():
    wb = openpyxl.Workbook()  #if file is being created first time
    sheet = wb.active

    myTickers = sp1000Wiki.getWiki1000()

    for i, v in enumerate(myTickers):
        cell = 'A' + str((i + 2))

        sheet[cell] = v

    wb.save('C:/Users/aj282/OneDrive/Desktop/pythonStocks/my1000Xl.xlsx')
Exemplo n.º 3
0
def update1000TickersExcel():
    wb = openpyxl.load_workbook(
        'C:/Users/aj282/OneDrive/Desktop/pythonStocks/my1000Xl.xlsx'
    )  #if file exists
    sheet = wb.active

    myTickers = sp1000Wiki.getWiki1000()

    for i, v in enumerate(myTickers):
        cell = 'A' + str((i + 2))

        sheet[cell] = v

    wb.save('C:/Users/aj282/OneDrive/Desktop/pythonStocks/my1000Xl.xlsx')
Exemplo n.º 4
0
def openMarket():
    wb = openpyxl.load_workbook(
        'C:/Users/aj282/OneDrive/Desktop/pythonStocks/my1000Xl.xlsx'
    )  #if file exists
    sheet = wb.active
    api = getApi()
    myTickers = sp1000Wiki.getWiki1000()
    params = getParams()

    for i, v in enumerate(myTickers):
        myURL = 'https://api.polygon.io/v2/snapshot/locale/us/markets/stocks/tickers/{}'.format(
            v)
        try:
            resp = api.polygon._session.request('GET', myURL, params=params)

            if (i + 1) % 100 == 0:
                time.sleep(5)

            jjson = resp.json()
            #print(jjson)
            jjson = resp.json()
            print(json.dumps(jjson, indent=4))
            try:
                rowG = 'G' + str(i + 2)
                if jjson['ticker']['lastTrade']['p'] == 0:
                    print('Val was 0')
                else:
                    sheet[rowG] = jjson['ticker']['lastTrade']['p']
            except:
                rowG = 'G' + str(i + 2)
                print("Error occured at {}".format(rowG))
                sheet[rowG] = "N/A"
        except:
            rowG = 'G' + str(i + 2)
            print("Error occured at {}".format(rowG))
            sheet[rowG] = "N/A"

    wb.save('C:/Users/aj282/OneDrive/Desktop/pythonStocks/my1000Xl.xlsx')