I'm using python and its framework flask to build a frontEnd backEnd project. The project needs stock data. I used Yahoo's Api before it stopped working and now I'm using Alpha Vantage API. It's working pretty well but I'm having difficulties with stock market Indices like Nasdaq, Dow Jones.. with yahoo I was using their tickers(like symboles) (^IXIC, ^DJI...) but it doesn't seem to work with alpha vantage. Has anyone worked with alpha vantage?
example of url to get data for Microsoft:
https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=full&apikey=CN3J
Python code:
@app.route('/pfa/medaf/IndAct', methods = ['POST'])
def donnee():
Action1 = request.form['code1']
Action2 = request.form['code2']
Indice = request.form['Ind']
url="https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol="
urlInd=url+Indice+"&apikey=CN3J"
urlAct1=url+Action1+"&apikey=CN3J"
urlAct2=url+Action2+"&apikey=CN3J"
respInd = urlopen(urlInd)
dataInd = json.loads(respInd.read().decode(respInd.info().get_param('charset') or 'utf-8'))
coursIndice=[]
listInd=[]
for elt in dataInd['Time Series (Daily)'].keys():
listInd.append(elt)
listInd.sort(reverse=True)
for e in listInd:
coursIndice.append(float(dataInd['Time Series (Daily)'][e]['4. close']))
lenIndice = len(coursIndice)
rentabIndice=[]
for j in range(lenIndice-1):
rentabIndice.append(100*(coursIndice[j+1]/coursIndice[j] -1 ))
moyenneMarche=sum(rentabIndice)/len(rentabIndice)
HTML code:
<section class="cols pad_left1">
<form action = "http://localhost:5000/pfa/medaf/IndAct" method = "post">
Tickers:
<input type = "text" name = "code1" placeholder="Ticker here"><br>
<input type = "text" name = "code2" placeholder="Ticker here"><br><br>
Indice:<br>
<select name="Ind" size="1" >
<option value="^IXIC" > NASDAQ Composite </option>
<option value="^FCHI" > CAC40 </option>
<option value="^DJI" > Dow Jones</option>
</select><br><br>
<input type = "submit" value = "submit" />
</form>
</section>