load alpaca QAT
This commit is contained in:
parent
5bf2d043a2
commit
8f28c8b8ef
112
docker/market_data/hist/load_alpaca_qat.sh
Executable file
112
docker/market_data/hist/load_alpaca_qat.sh
Executable file
@ -0,0 +1,112 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $0 -S <symbols> [-L <LogDir>] [-d <YYYYMMDD Date>]"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
is_container_running() {
|
||||||
|
local container_name=$1
|
||||||
|
|
||||||
|
if [ "$(docker ps --filter "name=^/${container_name}$" --filter "status=running" -q)" ]; then
|
||||||
|
return 0 # true
|
||||||
|
else
|
||||||
|
return 1 # false
|
||||||
|
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
|
||||||
|
|
||||||
|
# ----- Settings
|
||||||
|
DockerRegistry=cloud21.cvtt.vpn:5500
|
||||||
|
DockerImage=${DockerRegistry}/alpaca_qat #:latest
|
||||||
|
ContainerName=alpaca_qat
|
||||||
|
LogDir=/home/cvtt/prod/logs
|
||||||
|
# ----- Settings
|
||||||
|
|
||||||
|
while getopts ":d:S:L:" opt; do
|
||||||
|
case ${opt} in
|
||||||
|
d )
|
||||||
|
date_to_load=$OPTARG
|
||||||
|
;;
|
||||||
|
S )
|
||||||
|
Symbols=$OPTARG
|
||||||
|
;;
|
||||||
|
L )
|
||||||
|
LogDir=$OPTARG
|
||||||
|
;;
|
||||||
|
\? )
|
||||||
|
echo "Invalid option: -$OPTARG" >&2
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
: )
|
||||||
|
echo "Option -$OPTARG requires an argument." >&2
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z ${Symbols} ] ; then
|
||||||
|
echo "symbols are not specified"
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
||||||
|
if is_container_running "$ContainerName"; then
|
||||||
|
echo "Container ${ContainerName} is already running."
|
||||||
|
exit 3
|
||||||
|
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
|
||||||
|
|
||||||
|
Cmd="docker run"
|
||||||
|
Cmd="${Cmd} --pull=always"
|
||||||
|
Cmd="${Cmd} --network=host"
|
||||||
|
Cmd="${Cmd} --name=${ContainerName}"
|
||||||
|
Cmd="${Cmd} --rm"
|
||||||
|
Cmd="${Cmd} --volume=${LogDir}:/logs"
|
||||||
|
Cmd="${Cmd} ${DockerImage}"
|
||||||
|
Cmd="${Cmd} -d ${date_to_load}"
|
||||||
|
Cmd="${Cmd} -S ${Symbols}"
|
||||||
|
|
||||||
|
echo $Cmd
|
||||||
|
eval $Cmd
|
||||||
|
|
||||||
|
if [ "$?" != "0" ] ; then
|
||||||
|
exit 1 # if killed we do not save last day
|
||||||
|
fi
|
||||||
|
|
||||||
|
# # truncate to avoid false positive
|
||||||
|
# date_to_load=$(echo "${date_to_load}" | xargs)
|
||||||
|
# if [ -n "${date_to_load}" ]; then
|
||||||
|
# echo "Saving date_to_load to ${LastDayFile}"
|
||||||
|
# echo ${date_to_load} > ${LastDayFile}
|
||||||
|
# fi
|
||||||
@ -1 +1 @@
|
|||||||
1.7.1,alpaca md hist converting date to the right format to be used for trading calendar
|
1.7.2,alpaca md QAT
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user