Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlphaVantage API Stock Market Indices

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>
like image 603
Hafssa Avatar asked Jun 25 '17 00:06

Hafssa


People also ask

Is there an API for the stock market?

The Investing API (provided by APIDojo) allows developers to access stock data for cryptocurrencies and markets. This API is ideal for tracking price changes and exchange rates.

Does Alpha Vantage support NSE?

AlphaVantage today informs us that they no longer support NSE.

Is there a free stock market API?

About Finnhub Stock API With the sole mission of democratizing financial data, we are proud to offer a FREE realtime API for stocks, forex and cryptocurrency. With this API, you can access realtime market data from stock exchanges, 10 forex brokers, and 15+ crypto exchanges.


1 Answers

I have a python library for alphavantage (MIT licensed) https://github.com/RomelTorres/alpha_vantage you can have a look at it. I have shared some examples there on how to work with the library.

like image 92
Romel Torres Avatar answered Sep 21 '22 20:09

Romel Torres