diff --git a/docker/alpaca_md_day.sh b/docker/alpaca_md_day.sh index 3d3b7c7..2ce6c3f 100755 --- a/docker/alpaca_md_day.sh +++ b/docker/alpaca_md_day.sh @@ -17,6 +17,33 @@ is_container_running() { fi } +export CalendarURL=http://cloud23.cvtt.vpn:8000/api/v1/markets/hours?mic=XNYS + +is_business_day() { + dt=${1} + + 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 + +get_prev_business_day() { + Start=${1} + while true; do + if is_business_day ${Start}; then + break + fi + echo "${Start} is not business day in US" >&2 + Start=$(date -d "${Start} - 1 day" "+%Y-%m-%d") + done + echo ${Start} +} +export -f get_prev_business_day if [ -z ${date_to_load} ] ; then echo "Yesterday data has priority. Running historical container will be stopped" @@ -68,8 +95,12 @@ else mv ${LastDayFile} ${LastDayFile}.prev date_to_load=$(date -d "${last_date} - 1 day" "+%Y-%m-%d") fi +fi +if [ -n "${date_to_load}" ]; then + date_to_load=$(get_prev_business_day ${date_to_load}) echo "Historical Data for ${date_to_load}" fi +exit Cmd="docker run" Cmd="${Cmd} --pull=always" diff --git a/release_version.txt b/release_version.txt index 65087b4..e25d8d9 100644 --- a/release_version.txt +++ b/release_version.txt @@ -1 +1 @@ -1.1.4 +1.1.5