我正在使用 python 及其框架烧瓶来构建前端后端项目。该项目需要库存数据。在它停止工作之前我使用了 Yahoo 的 Api,现在我使用的是 Alpha Vantage API。它运行得很好,但我在纳斯达克、道琼斯等股票市场指数方面遇到了困难。我在雅虎使用他们的股票代码(如符号)(^IXIC、^DJI...)但它似乎不起作用具有阿尔法优势。有人用过 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 代码:
<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>