109 lines
2.0 KiB
Bash
Executable File
109 lines
2.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
usage() {
|
|
echo "Usage: $0 [-d <YYYYMMDD Date>] -S <symbols>"
|
|
exit 1
|
|
}
|
|
|
|
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
|
|
|
|
# --- Settings
|
|
export Bin=/alpaca_md_qat_loader
|
|
export OutputDir=/data/alpaca_md # Local
|
|
export LogDir=/logs
|
|
# --- Settings
|
|
|
|
while getopts ":d:S:" opt; do
|
|
case ${opt} in
|
|
d )
|
|
Start=$OPTARG
|
|
;;
|
|
S )
|
|
Symbols=$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
|
|
|
|
mkdir -p ${OutputDir}
|
|
mkdir -p ${LogDir}
|
|
|
|
|
|
echo "CommandLine: ${*}"
|
|
|
|
export CalendarURL=http://cloud23.cvtt.vpn:8000/api/v1/markets/hours?mic=XNYS
|
|
|
|
|
|
if [ -z ${Start} ] ; then
|
|
echo "start is not specified, getting yesterday..."
|
|
Start=$(date -d "yesterday" "+%Y-%m-%d")
|
|
echo "Start=${Start}"
|
|
fi
|
|
|
|
while true; do
|
|
if is_business_day ${Start}; then
|
|
break
|
|
fi
|
|
echo "${Start} is not business day in US"
|
|
Start=$(date -d "${Start} - 1 day" "+%Y-%m-%d")
|
|
done
|
|
|
|
|
|
echo "Start=${Start}"
|
|
Dstamp=$(date -d "${Start}" "+%Y%m%d")
|
|
|
|
Cmd="${Bin}"
|
|
Cmd="${Cmd} --credentials_file=/.creds"
|
|
Cmd="${Cmd} --output_directory=${OutputDir}"
|
|
Cmd="${Cmd} --start=${Start}"
|
|
Cmd="${Cmd} --symbols=${Symbols}"
|
|
Cmd="${Cmd} > ${LogDir}/${Dstamp}.alpaca_qat.log 2>&1"
|
|
|
|
echo ${Cmd}
|
|
eval ${Cmd}
|
|
|
|
echo "Compressing"
|
|
for file in $(find ${OutputDir} -type f -name '*db' -print )
|
|
do
|
|
echo "Compressing ${file}"
|
|
gzip ${file}
|
|
done
|
|
|
|
|
|
Source=/data/
|
|
Targets=
|
|
Targets="${Targets} cvtt@hs01.cvtt.vpn:/works/cvtt/md_archive/equity"
|
|
Targets="${Targets} cvtt@cloud21.cvtt.vpn:/opt/store/cvtt/md_archive/equity"
|
|
|
|
|
|
for tgt in ${Targets}
|
|
do
|
|
Cmd="/usr/bin/rsync -ahv ${Source} ${tgt}"
|
|
echo $Cmd
|
|
eval $Cmd
|
|
done
|
|
|