Created
March 3, 2019 18:34
-
-
Save hardenchant/26a5d88e77160e31ea667c75990b6010 to your computer and use it in GitHub Desktop.
Download data to excel table from moex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import xlsxwriter | |
import json | |
start_date = "2000-03-01" | |
end_date = "2019-03-02" | |
link = f"https://iss.moex.com/iss/history/engines/stock/markets/shares/boardgroups/57/securities/SBER.jsonp?lang=ru&from=2000-03-01&till=2019-03-02&iss.json=extended&iss.meta=off&sort_order=TRADEDATE&sort_order_desc=desc&start=" | |
resp = requests.get(link + "0") | |
data_json = resp.json() | |
record_count = data_json[1]['history.cursor'][0]['TOTAL'] | |
data = data_json[1]['history'] | |
for page in range(0, record_count, 100): | |
resp = requests.get(link + str(page)) | |
data += resp.json()[1]['history'] | |
workbook = xlsxwriter.Workbook('data.xlsx') | |
worksheet = workbook.add_worksheet() | |
keys = list(enumerate(data[0].keys())) | |
for col, key in keys: | |
worksheet.write(0, col, key) | |
for row, obj in enumerate(data): | |
for col, key in keys: | |
worksheet.write(row + 1, col, str(obj[key])) | |
workbook.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment