progress
This commit is contained in:
@@ -1,19 +1,26 @@
|
||||
FROM python:3.10-slim
|
||||
|
||||
WORKDIR /
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
# Update the package list and install required packages
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
apt-utils \
|
||||
software-properties-common \
|
||||
curl \
|
||||
rsync \
|
||||
openssh-client \
|
||||
parallel \
|
||||
jq
|
||||
|
||||
RUN pip install --upgrade pip
|
||||
|
||||
|
||||
COPY docker_dev/alpaca_md_day/requirements.txt /
|
||||
RUN pip install --upgrade pip --root-user-action=ignore
|
||||
RUN pip install -r /requirements.txt --root-user-action=ignore
|
||||
RUN pip install -r /requirements.txt
|
||||
|
||||
COPY cvttpy /cvttpy
|
||||
COPY docker_dev/alpaca_md_day/.creds /.creds
|
||||
COPY docker_dev/alpaca_md_day/.creds /root/.creds
|
||||
COPY docker_dev/alpaca_md_day/alpaca_md_day.sh /alpaca_md_day.sh
|
||||
|
||||
# RUN apt install openssh-client -y
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends rsync openssh-client && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY docker_dev/shared/id_rsa /root/.ssh/id_rsa
|
||||
COPY docker_dev/shared/id_rsa.pub /root/.ssh/id_rsa.pub
|
||||
COPY docker_dev/shared/known_hosts /root/.ssh/known_hosts
|
||||
@@ -26,7 +33,9 @@ RUN mkdir -p /app/data
|
||||
RUN mkdir /logs
|
||||
RUN chmod +x /alpaca_md_day.sh
|
||||
|
||||
WORKDIR /
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
ENV PYTHONPATH=/
|
||||
ENTRYPOINT [ "/alpaca_md_day.sh" ]
|
||||
|
||||
ENV PYTHONPATH=/
|
||||
CMD [ "echo", "alpaca_md_day"]
|
||||
# CMD [ "echo", "alpaca_md_day"]
|
||||
|
||||
Executable
+212
@@ -0,0 +1,212 @@
|
||||
#!/bin/bash
|
||||
|
||||
# --- Settings
|
||||
export PYTHONPATH=/
|
||||
export Python=python3.10
|
||||
export Config=http://cloud16.cvtt.vpn:6789/apps/minimal_md
|
||||
export PyScript=/cvttpy/exchanges/alpaca/hist_md/hist_md_bars.py
|
||||
|
||||
export OutputDir=/app/data/alpaca_md # Local
|
||||
export LogDir=/logs
|
||||
|
||||
mkdir -p ${OutputDir}
|
||||
mkdir -p ${LogDir}
|
||||
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 <date (YYYY-MM-DD)> [<num-jobs> (30}) ] [<instrument_list_file>] "
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "CommandLine: ${*}"
|
||||
|
||||
Start=${1}
|
||||
NumJobs=${2}
|
||||
# InstListFile=${3}
|
||||
|
||||
export CalendarURL=http://cloud16.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
|
||||
|
||||
|
||||
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
|
||||
|
||||
End=$(date -d "${Start} + 1 day" "+%Y-%m-%d")
|
||||
|
||||
# Exclude today
|
||||
if [ "${End}" == $(date '+%Y-%m-%d') ] ; then
|
||||
End=$(date -d 'yesterday' ''+%Y-%m-%d'')
|
||||
fi
|
||||
|
||||
if [ "${NumJobs}" == "" ] ; then
|
||||
NumJobs=30
|
||||
fi
|
||||
|
||||
echo "Start=${Start} End=${End} NumJobs=${NumJobs}"
|
||||
|
||||
|
||||
run_proc() {
|
||||
Inst=${1}
|
||||
Start=${2}
|
||||
End=${3}
|
||||
echo "Running for $Inst"
|
||||
|
||||
Cmd="${Python} ${PyScript}"
|
||||
Cmd="${Cmd} --config=${Config}"
|
||||
Cmd="${Cmd} --output_dir=${OutputDir}/${Start:0:4}"
|
||||
Cmd="${Cmd} --instruments=ALPACA:${Inst}"
|
||||
Cmd="${Cmd} --start=${Start}"
|
||||
if [ "${End}" != "" ]; then
|
||||
Cmd="${Cmd} --end=${End}"
|
||||
fi
|
||||
Cmd="${Cmd} --log_file=${LogDir}/${Inst}.log"
|
||||
Cmd="${Cmd} --log_level=WARNING"
|
||||
echo ${Cmd}
|
||||
eval ${Cmd}
|
||||
}
|
||||
|
||||
export -f run_proc
|
||||
|
||||
key=$(jq -r '.["ALPACA_SANDBOX"] | .api_key' ~/.creds)
|
||||
secret=$(jq -r '.["ALPACA_SANDBOX"] | .secret_key' ~/.creds)
|
||||
|
||||
Cmd="curl -s --request GET --url 'https://paper-api.alpaca.markets/v2/assets?status=active'"
|
||||
Cmd="${Cmd} --header 'APCA-API-KEY-ID: ${key}'"
|
||||
Cmd="${Cmd} --header 'APCA-API-SECRET-KEY: ${secret}'"
|
||||
Cmd="${Cmd} --header 'accept: application/json'"
|
||||
Cmd="${Cmd} | jq '.[] | select(.class == \"us_equity\" and .exchange != \"OTC\") | .symbol'"
|
||||
Cmd="${Cmd} | sed 's/\"//g'"
|
||||
Cmd="${Cmd} | sed 's/^/STOCK-/'"
|
||||
# split string into array
|
||||
Instruments=()
|
||||
for Inst in $(eval ${Cmd})
|
||||
do
|
||||
Instruments+=("$Inst")
|
||||
done
|
||||
|
||||
slice_size=500 # 10K symbols parallel cannot handle
|
||||
for ((ii=0; ii <${#Instruments[@]}; ii+=slice_size)); do
|
||||
InstSlice=("${Instruments[@]:ii:slice_size}")
|
||||
|
||||
parallel -j ${NumJobs} run_proc {} ${Start} ${End} ::: "${InstSlice[@]}"
|
||||
done
|
||||
|
||||
echo "Compressing"
|
||||
for file in $(find ${OutputDir} -type f -name '*db' -print )
|
||||
do
|
||||
echo "Compressing ${file}"
|
||||
gzip ${file}
|
||||
done
|
||||
|
||||
|
||||
Source=/app/data/
|
||||
Targets=
|
||||
Targets="${Targets} oleg@homestore.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
|
||||
|
||||
|
||||
|
||||
# DbHost=""
|
||||
# Date=""
|
||||
# Schemas=coinbase,bnbspot,bnbfut
|
||||
|
||||
# while getopts ":h:d:s:" opt; do
|
||||
# case ${opt} in
|
||||
# h )
|
||||
# DbHost=$OPTARG
|
||||
# ;;
|
||||
# d )
|
||||
# Date=$OPTARG
|
||||
# ;;
|
||||
# s )
|
||||
# Schemas=$OPTARG
|
||||
# ;;
|
||||
# \? )
|
||||
# echo "Invalid option: -$OPTARG" >&2
|
||||
# usage
|
||||
# ;;
|
||||
# : )
|
||||
# echo "Option -$OPTARG requires an argument." >&2
|
||||
# usage
|
||||
# ;;
|
||||
# esac
|
||||
# done
|
||||
|
||||
# if [ -z "${DbHost}" ] || [ -z "$Date" ]; then
|
||||
# echo "DbHost=${DbHost} Date=${Date}. Cmdline: ${*}"
|
||||
# usage
|
||||
# fi
|
||||
|
||||
# CredKey=""
|
||||
# if [ "${DbHost}" == "cvttdata" ] ; then
|
||||
# CredKey=TSDB_MD_CVTTDATA_RO
|
||||
# elif [ "${DbHost}" == "cloud21" ] ; then
|
||||
# CredKey=TSDB_MD_CLD21_RO
|
||||
# else
|
||||
# echo "host ${DbHost} is not valid source"
|
||||
# usage
|
||||
# fi
|
||||
|
||||
# export PYTHONPATH=/
|
||||
|
||||
# Cmd="python3.10"
|
||||
# Cmd="${Cmd} cvttpy/research/utils/archive_ts_md.py"
|
||||
# Cmd="${Cmd} --config=http://cloud16.cvtt.vpn:6789/apps/md_recorder"
|
||||
# Cmd="${Cmd} --db_credentials_key=${CredKey}"
|
||||
# Cmd="${Cmd} --credentials_file=/.creds"
|
||||
# Cmd="${Cmd} --date=${Date}"
|
||||
# Cmd="${Cmd} --schemas=${Schemas}"
|
||||
# Cmd="${Cmd} --root_dir=/app/data/${DbHost}"
|
||||
# Cmd="${Cmd} --format=SQLite"
|
||||
# Cmd="${Cmd} --compress"
|
||||
# # Cmd="${Cmd} --log_file=/logs/%T.crypto_md_day.log"
|
||||
|
||||
# echo ${Cmd}
|
||||
# eval ${Cmd}
|
||||
|
||||
# echo "Data Sync"
|
||||
|
||||
# Source=/app/data/
|
||||
# Targets=
|
||||
# Targets="${Targets} oleg@homestore.cvtt.vpn:/works/cvtt/md_archive/crypto"
|
||||
# Targets="${Targets} cvtt@cloud21.cvtt.vpn:/opt/store/cvtt/md_archive/crypto"
|
||||
|
||||
|
||||
# for tgt in ${Targets}
|
||||
# do
|
||||
# Cmd="/usr/bin/rsync -ahv ${Source} ${tgt}"
|
||||
# echo $Cmd
|
||||
# eval $Cmd
|
||||
# done
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 -h <db host> -d <YYYYMMDD Date> -s <schemas|coinbase,bnbspot,bnbfut>"
|
||||
exit 1
|
||||
}
|
||||
|
||||
DbHost=""
|
||||
Date=""
|
||||
Schemas=coinbase,bnbspot,bnbfut
|
||||
|
||||
while getopts ":h:d:s:" opt; do
|
||||
case ${opt} in
|
||||
h )
|
||||
DbHost=$OPTARG
|
||||
;;
|
||||
d )
|
||||
Date=$OPTARG
|
||||
;;
|
||||
s )
|
||||
Schemas=$OPTARG
|
||||
;;
|
||||
\? )
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
usage
|
||||
;;
|
||||
: )
|
||||
echo "Option -$OPTARG requires an argument." >&2
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "${DbHost}" ] || [ -z "$Date" ]; then
|
||||
echo "DbHost=${DbHost} Date=${Date}. Cmdline: ${*}"
|
||||
usage
|
||||
fi
|
||||
|
||||
CredKey=""
|
||||
if [ "${DbHost}" == "cvttdata" ] ; then
|
||||
CredKey=TSDB_MD_CVTTDATA_RO
|
||||
elif [ "${DbHost}" == "cloud21" ] ; then
|
||||
CredKey=TSDB_MD_CLD21_RO
|
||||
else
|
||||
echo "host ${DbHost} is not valid source"
|
||||
usage
|
||||
fi
|
||||
|
||||
export PYTHONPATH=/
|
||||
|
||||
Cmd="python3.10"
|
||||
Cmd="${Cmd} cvttpy/research/utils/archive_ts_md.py"
|
||||
Cmd="${Cmd} --config=http://cloud16.cvtt.vpn:6789/apps/md_recorder"
|
||||
Cmd="${Cmd} --db_credentials_key=${CredKey}"
|
||||
Cmd="${Cmd} --credentials_file=/.creds"
|
||||
Cmd="${Cmd} --date=${Date}"
|
||||
Cmd="${Cmd} --schemas=${Schemas}"
|
||||
Cmd="${Cmd} --root_dir=/app/data/${DbHost}"
|
||||
Cmd="${Cmd} --format=SQLite"
|
||||
Cmd="${Cmd} --compress"
|
||||
# Cmd="${Cmd} --log_file=/logs/%T.crypto_md_day.log"
|
||||
|
||||
echo ${Cmd}
|
||||
eval ${Cmd}
|
||||
|
||||
echo "Data Sync"
|
||||
|
||||
Source=/app/data/
|
||||
Targets=
|
||||
Targets="${Targets} oleg@homestore.cvtt.vpn:/works/cvtt/md_archive/crypto"
|
||||
Targets="${Targets} cvtt@cloud21.cvtt.vpn:/opt/store/cvtt/md_archive/crypto"
|
||||
|
||||
|
||||
for tgt in ${Targets}
|
||||
do
|
||||
Cmd="/usr/bin/rsync -ahv ${Source} ${tgt}"
|
||||
echo $Cmd
|
||||
eval $Cmd
|
||||
done
|
||||
|
||||
@@ -3,4 +3,5 @@ nest-asyncio>=1.5.5
|
||||
asyncpg>=0.27.0
|
||||
hjson>=3.1.0
|
||||
pandas>=1.5.3
|
||||
sortedcontainers>=2.4.0
|
||||
sortedcontainers>=2.4.0
|
||||
aioredis>=2.0.1
|
||||
Reference in New Issue
Block a user