-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from Tinkoff/download_md
загрузка исторической marketdata
- Loading branch information
Showing
3 changed files
with
2,862 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
figi_list=figi.txt | ||
token=insert_token_here | ||
current_year=$(date +%Y) | ||
url=https://invest-public-api.tinkoff.ru/history-data | ||
function download { | ||
local figi=$1 | ||
local year=$2 | ||
local file_name=${figi}_${year}.zip | ||
echo "downloading $figi for year $year" | ||
local response_code=$(curl -s --location "${url}?figi=${figi}&year=${year}" \ | ||
-H "Authorization: Bearer ${token}" -o "${file_name}" -w '%{http_code}\n') | ||
if [ "$response_code" = "200" ]; then | ||
((year--)) | ||
download "$figi" "$year"; | ||
fi | ||
#Если превышен лимит запросов в минуту (30) - повторяем запрос | ||
if [ "$response_code" = "429" ]; then | ||
echo "rate limit exceed. sleep 5" | ||
sleep 5 | ||
download "$figi" "$year"; | ||
fi | ||
#Если невалидный токен - выходим | ||
if [ "$response_code" = "401" ] || [ "$response_code" = "500" ]; then | ||
echo 'invalid token' | ||
exit 1 | ||
fi | ||
} | ||
|
||
while read -r figi; do | ||
download "$figi" "$current_year" | ||
done < ${figi_list} |
Oops, something went wrong.