AlphaVantage API股票市场指数 [英] AlphaVantage API Stock Market Indices

查看:1297
本文介绍了AlphaVantage API股票市场指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python及其框架构建一个frontEnd backEnd项目。
项目需要库存数据。在停止工作之前,我使用了Yahoo的Api,现在我正在使用Alpha Vantage API。它工作得很好,但我在股票市场指数像纳斯达克,道琼斯..与雅虎我使用他们的代价(像symboles)(^ IXIC,^ DJI ...),但似乎并没有工作与阿尔法有利。有没有人与阿尔法有利?

获取Microsoft数据的url示例:

https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&outputsize=full&apikey=CN3J <

Python代码:

  @ 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'))

coursIn ():$ b $ listInd.append(elt)
listInd = []
listInd = []
for elt in dataInd ['Time Series(Daily)']。 sort(reverse = True)
for listInd:
coursIndice.append(float(dataInd ['Time Series(Daily)'] [e] ['4。关闭']))

lenIndice = len(coursIndice)

rentabIndice = []
在范围内(lenIndice-1):
rentabIice .append(100 *(coursIndice [j + 1] / coursIndice [j] -1))

moyenneMarche = sum(rentabIndice)/ len(rentabIndice)


$ b HTML代码:

 < section class =cols pad_left1> 
< form action =http:// localhost:5000 / pfa / medaf / IndActmethod =post>
Tickers:
< input type =textname =code1placeholder =Ticker here>< br>
< input type =textname =code2placeholder =Ticker here>< br>< br>
指数:< br>
< select name =Indsize =1>
< option value =^ IXIC>纳斯达克综合指数< / option>
< option value =^ FCHI> CAC40< / option>
< option value =^ DJI>道琼斯< /期权>
< / select>< br>< br>
< input type =submitvalue =submit/>
< / form>
< / section>


解决方案

https://github.com/RomelTorres/alpha_vantage 你可以看看它。我在这里分享了一些关于如何使用这个库的例子。


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>

解决方案

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.

这篇关于AlphaVantage API股票市场指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆