Compare commits

..

6 Commits

Author SHA1 Message Date
oleg ed43a900a2 progress 2024-04-09 09:41:37 -04:00
oleg 9de86bf3e3 progress 2024-03-28 09:53:52 -04:00
oleg 4873af1673 fix 2024-03-26 12:07:54 -04:00
oleg c2dae20d7b improvements to alpaca md 2024-03-26 11:30:41 -04:00
oleg 8607db6506 fix 2024-03-25 20:42:35 -04:00
oleg 465d4c746e progress 2024-03-25 18:04:49 -04:00
4 changed files with 102 additions and 22 deletions
+1 -1
View File
@@ -1 +1 @@
0.6.5 0.7.2
+28
View File
@@ -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
+23 -21
View File
@@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
Start=${1} Start=${1}
End=${2} NumJobs=${2}
NumJobs=${3} InstListFile=${3}
export CalendarURL=http://cloud16.cvtt.vpn:8000/api/v1/markets/hours?mic=XNYS export CalendarURL=http://cloud16.cvtt.vpn:8000/api/v1/markets/hours?mic=XNYS
@@ -29,22 +29,19 @@ if ! is_business_day ${Start}; then
exit exit
fi fi
if [ "${End}" == "" ] ; then End=$(date -d "${Start} + 1 day" "+%Y-%m-%d")
End=$(date -d "${Start} + 1 day" "+%Y-%m-%d")
fi
if [ "${NumJobs}" == "" ] ; then if [ "${NumJobs}" == "" ] ; then
NumJobs=25 NumJobs=30
fi fi
echo "Start=${Start} End=${End} NumJobs=${NumJobs}" echo "Start=${Start} End=${End} NumJobs=${NumJobs}"
export PYTHONPATH=/home/cvtt/prod export PYTHONPATH=/home/cvtt/prod
export Python=/home/cvtt/.pyenv/python3.10-venv/bin/python3 export Python=/home/cvtt/.pyenv/python3.10-venv/bin/python3
export PyScript=/home/cvtt/prod/cvttpy/exchanges/alpaca/hist_mkt_data.py export PyScript=/home/cvtt/prod/cvttpy/exchanges/alpaca/hist_mkt_data.py
export OutputDir=/home/cvtt/alpaca_md export OutputDir=/home/cvtt/host_drive/alpaca_md # Local
export Config=http://cloud16.cvtt.vpn:6789/apps/minimal_md export Config=http://cloud16.cvtt.vpn:6789/apps/minimal_md
export LogDir=/home/cvtt/prod/logs/alpaca_md export LogDir=/home/cvtt/prod/logs/alpaca_md
@@ -56,32 +53,37 @@ run_proc() {
End=${3} End=${3}
echo "Running for $Inst" echo "Running for $Inst"
Cmd="${Python} ${PyScript}" Cmd="${Python} ${PyScript}"
Cmd="${Cmd} --config=${Config}" Cmd="${Cmd} --config=${Config}"
Cmd="${Cmd} --output_dir=${OutputDir}" Cmd="${Cmd} --output_dir=${OutputDir}/${Start:0:4}"
Cmd="${Cmd} --instruments=ALPACA:${Inst}" Cmd="${Cmd} --instruments=ALPACA:${Inst}"
Cmd="${Cmd} --start=${Start}" Cmd="${Cmd} --start=${Start}"
if [ "${End}" != "" ]; then if [ "${End}" != "" ]; then
Cmd="${Cmd} --end=${End}" Cmd="${Cmd} --end=${End}"
fi fi
Cmd="${Cmd} --log_file=${LogDir}/${Start}.${Inst}.log" Cmd="${Cmd} --log_file=${LogDir}/${Inst}.log"
Cmd="${Cmd} --log_level=WARNING"
echo ${Cmd} echo ${Cmd}
eval ${Cmd} eval ${Cmd}
} }
export -f run_proc export -f run_proc
key=$(jq -r '.["ALPACA_SANDBOX"] | .api_key' ~/.creds) if [ -n $InstListFile ]; then
secret=$(jq -r '.["ALPACA_SANDBOX"] | .secret_key' ~/.creds)
Cmd="curl -s --request GET --url 'https://paper-api.alpaca.markets/v2/assets?status=active'" key=$(jq -r '.["ALPACA_SANDBOX"] | .api_key' ~/.creds)
Cmd="${Cmd} --header 'APCA-API-KEY-ID: ${key}'" secret=$(jq -r '.["ALPACA_SANDBOX"] | .secret_key' ~/.creds)
Cmd="${Cmd} --header 'APCA-API-SECRET-KEY: ${secret}'"
Cmd="${Cmd} --header 'accept: application/json'" Cmd="curl -s --request GET --url 'https://paper-api.alpaca.markets/v2/assets?status=active'"
Cmd="${Cmd} | jq '.[] | select(.class == \"us_equity\" and .exchange != \"OTC\") | .symbol'" Cmd="${Cmd} --header 'APCA-API-KEY-ID: ${key}'"
Cmd="${Cmd} | sed 's/\"//g'" Cmd="${Cmd} --header 'APCA-API-SECRET-KEY: ${secret}'"
Cmd="${Cmd} | sed 's/^/STOCK-/'" 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 # split string into array
Instruments=() Instruments=()
@@ -90,7 +92,7 @@ do
Instruments+=("$Inst") Instruments+=("$Inst")
done done
slice_size=100 # 10K symbols parallel cannot handle slice_size=500 # 10K symbols parallel cannot handle
for ((ii=0; ii <${#Instruments[@]}; ii+=slice_size)); do for ((ii=0; ii <${#Instruments[@]}; ii+=slice_size)); do
InstSlice=("${Instruments[@]:ii:slice_size}") InstSlice=("${Instruments[@]:ii:slice_size}")
+50
View File
@@ -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)"