AlphaVantage API股票市场指数

时间:2017-06-25 00:06:07

标签: python flask alphavantage

我使用python及其框架瓶来构建一个frontEnd backEnd项目。 该项目需要库存数据。在雅虎停止工作之前,我使用了雅虎的Api,现在我正在使用Alpha Vantage API。它运作良好,但我在股票市场上遇到困难像纳斯达克,道琼斯这样的指数..雅虎我正在使用他们的代号(如符号)(^ IXIC,^ DJI ......)但它似乎没有使用alpha优势。有没有人使用alpha vantage?

获取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'))

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>

3 个答案:

答案 0 :(得分:5)

我有一个alphavantage的python库(MIT许可)https://github.com/RomelTorres/alpha_vantage你可以查看它。我在那里分享了一些关于如何使用库的例子。

答案 1 :(得分:1)

我能够使用您问题中的示例网址和我的密钥获取索引的数据,并进行以下更改:

使用IXIC而不是^ IXIC。 使用DJI代替^ DJI。 使用FCHI而不是FCHI。

e.g。     https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=FCHI&outputsize=full&apikey=

基本上,只需从符号中删除克拉(^)前缀。

答案 2 :(得分:0)

您可以通过导入时间序列来连接时间序列

import pandas as pd
from alpha_vantage.timeseries import TimeSeries
import time
ts = TimeSeries (key=api_key, output_format = "pandas")
daily_results = ts.get_daily_adjusted(symbol="MSFT")
print(daily_results)

或者其他诸如资产负债表之类的东西

 base_url = 'https://www.alphavantage.co/query?'
 params = {'function': 'INCOME_STATEMENT',
     'symbol': stock_ticker,
     'apikey': keys}
 response_data_income = requests.get(base_url, params=params)

 data_income_annual_last_fiscalDateEnding = 
 response_data_income.json()['annualReports'][0]['fiscalDateEnding']
相关问题