ops/scripts/alpaca_hist_md/run_alpaca_hist_md.sh
2024-03-26 12:07:54 -04:00

51 lines
973 B
Bash
Executable File

#!/bin/bash
is_business_day() {
dt=${1}
CalendarURL=http://cloud16.cvtt.vpn:8000/api/v1/markets/hours?mic=XNYS
open_time=$(curl -s "${CalendarURL}&start=${dt}&end=${dt}" | jq '.[] | .open_time')
if [ -n "${open_time}" ]; then
return 0
else
return 1
fi
}
export -f is_business_day
# Dates are in descending order
FinishedDateFile=${HOME}/prod/run/alpaca_md_last_date
Script=${HOME}/prod/run/alpaca_md.sh
last_date=$(cat ${FinishedDateFile})
if [ "${last_date}" == "" ]; then
echo "process is currently on"
exit
fi
while true; do
new_date=$(date -d "${last_date} - 1 day" "+%Y-%m-%d")
if is_business_day ${new_date}; then
break
else
last_date=${new_date}
fi
done
echo Collecting data for ${new_date}
Cmd="${Script} ${new_date}"
echo "${0} Starting at $(date)"
echo > ${FinishedDateFile}
echo ${Cmd} && eval ${Cmd}
echo $new_date > ${FinishedDateFile}
echo "${0} Done at $(date)"