Skip to content

Commit

Permalink
Merge pull request #183 from Tinkoff/download_md
Browse files Browse the repository at this point in the history
загрузка исторической marketdata
  • Loading branch information
AlexanderVolkovTCS authored May 27, 2022
2 parents 3c8beff + 72b268f commit 7e52614
Show file tree
Hide file tree
Showing 3 changed files with 2,862 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Tinkoff Invest API — это интерфейс для взаимодейств

Через API можно загрузить как исторические котировки, так и котировки в режиме реального времени по всем бумагам

Для загрузки всех исторических котировок (по всем годам и бумагам) рекомендуем использовать [скрипт](https://tinkoff.github.io/investAPI/src/marketdata/download_md.sh)

### Сигналы на покупку или продажу

Торговлю по алгоритму можно автоматизировать, запрограммировав выставление сигналов
Expand Down
31 changes: 31 additions & 0 deletions src/marketdata/download_md.sh
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}
Loading

0 comments on commit 7e52614

Please sign in to comment.