progress - intermediate for md checklists
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
CredsFile=${1}
|
||||
CredKey=${2}
|
||||
|
||||
if [ "${CredsFile}" == "" ] ; then
|
||||
CredsFile="${HOME}/.creds"
|
||||
fi
|
||||
|
||||
if [ "${CredKey}" == "" ] ; then
|
||||
CredKey="ALPACA_SANDBOX"
|
||||
fi
|
||||
|
||||
key=$(jq -r ".[\"${CredKey}\"] | .api_key" ${CredsFile})
|
||||
secret=$(jq -r ".[\"${CredKey}\"] | .secret_key" ${CredsFile})
|
||||
|
||||
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'"
|
||||
|
||||
eval ${Cmd}
|
||||
|
||||
# split string into array
|
||||
Instruments=()
|
||||
for Inst in $(eval ${Cmd})
|
||||
do
|
||||
Instruments+=("$Inst")
|
||||
done
|
||||
Executable
+114
@@ -0,0 +1,114 @@
|
||||
#!/bin/bash
|
||||
|
||||
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 [ "${Start}" == "" ] ; then
|
||||
Start=$(date -d "yesterday" "+%Y-%m-%d")
|
||||
fi
|
||||
|
||||
if ! is_business_day ${Start}; then
|
||||
echo "${Start} is not business day in US"
|
||||
exit
|
||||
fi
|
||||
|
||||
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}"
|
||||
|
||||
# export PyScript=/home/cvtt/prod/cvttpy/exchanges/alpaca/hist_mkt_data.py
|
||||
|
||||
export PYTHONPATH=/home/cvtt/prod
|
||||
export Python=/home/cvtt/.pyenv/python3.10-venv/bin/python3
|
||||
export Config=http://cloud16.cvtt.vpn:6789/apps/minimal_md
|
||||
export PyScript=/home/cvtt/prod/cvttpy/exchanges/alpaca/hist_md/hist_md_bars.py
|
||||
|
||||
export OutputDir=/home/cvtt/prod/archive/md_archive/equity/alpaca_md # Local
|
||||
export LogDir=/home/cvtt/prod/logs/alpaca_md
|
||||
|
||||
mkdir -p ${LogDir}
|
||||
|
||||
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
|
||||
|
||||
if [ "$InstListFile" == "" ]; then
|
||||
|
||||
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-/'"
|
||||
else
|
||||
Cmd="cat ${InstListFile}"
|
||||
fi
|
||||
|
||||
# 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
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
export PYTHONPATH=${HOME}/prod
|
||||
|
||||
Python=${HOME}/.pyenv/python3.10-venv/bin/python3
|
||||
Script=${HOME}/prod/cvttpy/exchanges/alpaca/hist_md/rl_calc_loader.py
|
||||
DbFile=${HOME}/prod/data/rel_liquidity.db
|
||||
Config=http://cloud23.cvtt.vpn:6789/apps/minimal_md_eqt
|
||||
|
||||
Cmd="${Python}"
|
||||
Cmd="${Cmd} ${Script}"
|
||||
Cmd="${Cmd} --config=${Config}"
|
||||
Cmd="${Cmd} --db_file=${DbFile}"
|
||||
|
||||
echo ${Cmd}
|
||||
eval ${Cmd}
|
||||
|
||||
echo Done ${0} ${*}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#!/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)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user