I'm having trouble figuring out how to make this work. I have this dataframe read from a csv:
Ticker Nome File Ticker No - Data Inizio Data Fine
0 AABA-201910 AABA_NQ AABA 16/09/1998 16/06/2017
1 AAL AAL_NQ AAL 22/12/2014 17/04/2020
2 AAPL AAPL_NQ AAPL 03/01/1995 12/09/2021
3 ABGX-200603 ABGX_NQ ABGX 18/12/2000 20/12/2002
And i need to use data from every row in a link like this: "https://api.tiingo.com/tiingo/daily/AAPL/prices?startDate=1995-03-01&endDate=2021-01-01"
With the code below I get data in the right format (I suppose) but I still get error because of wrong format data:
Ticker Nome File Ticker No - Data Inizio Data Fine
0 AABA-201910 AABA_NQ AABA 1998-09-16 2017-06-16
1 AAL AAL_NQ AAL 2014-12-22 2020-04-17
2 AAPL AAPL_NQ AAPL 1995-03-01 2021-12-09
3 ABGX-200603 ABGX_NQ ABGX 2000-12-18 2002-12-20
Thats the code I'm trying to use:
import requests
import time
from bs4 import BeautifulSoup
import json
import os
import pandas as pd
from win32com.client import Dispatch
df= pd.read_csv('NQ TICKER BIAS 1.csv',delimiter=";")
symbol=df["Ticker No -"].to_string(index=False)
symbolfile=df["Nome File"].to_string(index=False)
df["Data Inizio"]=pd.to_datetime(df["Data Inizio"]).dt.strftime('%Y-%m-%d')
df["Data Fine"]=pd.to_datetime(df["Data Fine"]).dt.strftime('%Y-%m-%d')
start_date=df["Data Inizio"].to_string(index=False)
end_date=df["Data Fine"].to_string(index=False)
headers = {MY API}
#print ("downloading",symbol, "...")
try:
response = requests.get("https://api.tiingo.com/tiingo/daily/"+symbol+"/prices?startDate="+start_date+"&endDate="+end_date,headers=headers)
soup = BeautifulSoup(response.content, "html.parser")
print(soup)
print ("finished writing ",symbol,"txt file.")
except:
print ("error downloading ",symbol)
The result of print(soup):
["Error: Symbol format was not correct."]
["Error: Start date format was not correct. Must be in YYYY-MM-DD format."]
["Error: End date format was not correct. Must be in YYYY-MM-DD format."]
When I use as end_date dateToday I dont get any error for End date:
dateToday = str(time.strftime("%Y-%m-%d"))
So I believe I'm doing something wrong on converting dataframe to string