Compare commits

..

No commits in common. "master" and "v2.0.2" have entirely different histories.

22 changed files with 495 additions and 704 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
.history/

View File

@ -1 +1 @@
2.3.2 2.0.2,using HA trading-calendar and config service

View File

@ -10,7 +10,7 @@ if [ "" == "${prj}" ] ; then
usage usage
fi fi
Cmd="pushd /home/oleg/develop/cvtt2-ops" Cmd="pushd /home/oleg/develop/cvtt2"
Cmd="${Cmd} && (cd ${prj}" Cmd="${Cmd} && (cd ${prj}"
Cmd="${Cmd} && git pushall)" Cmd="${Cmd} && git pushall)"
Cmd="${Cmd} && ./build_release.sh -p ${prj}" Cmd="${Cmd} && ./build_release.sh -p ${prj}"

View File

@ -1,183 +0,0 @@
#!/usr/bin/env bash
# ---------------- Settings
repo=git@cloud21.cvtt.vpn:/works/git/cvtt2/ops.git
dist_root=/home/cvttdist/software/cvtt2
dist_user=cvttdist
dist_host="cloud21.cvtt.vpn"
dist_ssh_port="22"
dist_locations="cloud21.cvtt.vpn:22 hs01.cvtt.vpn:22"
version_file="VERSION"
prj=ops
brnch=master
interactive=N
# ---------------- Settings
# ---------------- cmdline
usage() {
echo "Usage: $0 [-b <branch (master)> -i (interactive)"
exit 1
}
while getopts "b:i" opt; do
case ${opt} in
b )
brnch=$OPTARG
;;
i )
interactive=Y
;;
\? )
echo "Invalid option: -$OPTARG" >&2
usage
;;
: )
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
# ---------------- cmdline
confirm() {
if [ "${interactive}" == "Y" ]; then
echo "--------------------------------"
echo -n "Press <Enter> to continue" && read
fi
}
if [ "${interactive}" == "Y" ]; then
echo -n "Enter project [${prj}]: "
read project
if [ "${project}" == "" ]
then
project=${prj}
fi
else
project=${prj}
fi
# repo=${git_repo_arr[${project}]}
if [ -z ${repo} ]; then
echo "ERROR: Project repository for ${project} not found"
exit -1
fi
echo "Project repo: ${repo}"
if [ "${interactive}" == "Y" ]; then
echo -n "Enter branch to build release from [${brnch}]: "
read branch
if [ "${branch}" == "" ]
then
branch=${brnch}
fi
else
branch=${brnch}
fi
tmp_dir=$(mktemp -d)
function cleanup {
cd ${HOME}
rm -rf ${tmp_dir}
}
trap cleanup EXIT
prj_dir="${tmp_dir}/${prj}"
cmd_arr=()
Cmd="git clone ${repo} ${prj_dir}"
cmd_arr+=("${Cmd}")
Cmd="cd ${prj_dir}"
cmd_arr+=("${Cmd}")
if [ "${interactive}" == "Y" ]; then
echo "------------------------------------"
echo "The following commands will execute:"
echo "------------------------------------"
for cmd in "${cmd_arr[@]}"
do
echo ${cmd}
done
fi
confirm
for cmd in "${cmd_arr[@]}"
do
echo ${cmd} && eval ${cmd}
done
Cmd="git checkout ${branch}"
echo ${Cmd} && eval ${Cmd}
if [ "${?}" != "0" ]; then
echo "ERROR: Branch ${branch} is not found"
cd ${HOME} && rm -rf ${tmp_dir}
exit -1
fi
release_version=$(cat ${version_file} | awk -F',' '{print $1}')
whats_new=$(cat ${version_file} | awk -F',' '{print $2}')
echo "--------------------------------"
echo "Version file: ${version_file}"
echo "Release version: ${release_version}"
confirm
version_tag="v${release_version}"
version_comment="'${version_tag} ${project} ${branch} $(date +%Y-%m-%d)\n${whats_new}'"
cmd_arr=()
Cmd="git tag -a ${version_tag} -m ${version_comment}"
cmd_arr+=("${Cmd}")
Cmd="git push origin --tags"
cmd_arr+=("${Cmd}")
Cmd="rm -rf .git"
cmd_arr+=("${Cmd}")
SourceLoc=../${project}
dist_path="${dist_root}/${project}/${release_version}"
for dist_loc in ${dist_locations}; do
dhp=(${dist_loc//:/ })
dist_host=${dhp[0]}
dist_port=${dhp[1]}
Cmd="rsync -avzh"
Cmd="${Cmd} --rsync-path=\"mkdir -p ${dist_path}"
Cmd="${Cmd} && rsync\" -e \"ssh -p ${dist_ssh_port}\""
Cmd="${Cmd} $SourceLoc ${dist_user}@${dist_host}:${dist_path}/"
cmd_arr+=("${Cmd}")
done
if [ "${interactive}" == "Y" ]; then
echo "------------------------------------"
echo "The following commands will execute:"
echo "------------------------------------"
for cmd in "${cmd_arr[@]}"
do
echo ${cmd}
done
fi
confirm
for cmd in "${cmd_arr[@]}"
do
pwd && echo ${cmd} && eval ${cmd}
done
echo "$0 Done ${project} ${release_version}"

View File

@ -0,0 +1,27 @@
#!/bin/bash
host=${1}
date=${2}
DockerRegistry=cloud21.cvtt.vpn:5500
DockerImage=${DockerRegistry}/crypto_md_day
if [ -z ${date} ] ; then
date=$(date -d "yesterday" +%Y%m%d)
fi
Cmd="docker run"
Cmd+=" --pull=always"
Cmd+=" --network=host"
Cmd+=" --name=crypto_md_day.${host}.${date}"
Cmd+=" --rm"
Cmd+=" --volume=${HOME}/.creds:/.creds"
Cmd+=" -e CONFIG_SERVICE=cloud16.cvtt.vpn:6789"
Cmd+=" ${DockerImage}"
Cmd+=" -h ${host}"
Cmd+=" -d ${date}"
# Cmd+=" -s coinbase,bnbspot,bnbfut"
Cmd+=" -s coinbase,bnbspot"
echo $Cmd
eval $Cmd

View File

@ -0,0 +1,107 @@
#!/bin/bash
usage() {
echo "Usage: $0 -N <num_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=https://trading-calendar.cvtt.net/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_hbar #:latest
ContainerName=alpaca_hbar
LogDir=/home/cvtt/prod/logs
# ----- Settings
while getopts ":d:N:L:" opt; do
case ${opt} in
d )
date_to_load=$OPTARG
;;
N )
NumSymbols=$OPTARG
;;
L )
LogDir=$OPTARG
;;
\? )
echo "Invalid option: -$OPTARG" >&2
usage
;;
: )
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
if is_container_running "$ContainerName"; then
echo "Container ${ContainerName} is already running."
exit 3
fi
if [ -z "${date_to_load}" ]; then
echo "date_to_load is empty"
date_to_load=$(get_prev_business_day $(date -d "yesterday" '+%Y-%m-%d'))
echo "Historical Data for ${date_to_load}"
fi
echo "date_to_load=${date_to_load}"
Cmd="docker run"
Cmd+=" --pull=always"
Cmd+=" --network=host"
Cmd+=" --name=${ContainerName}"
Cmd+=" --rm"
Cmd+=" --volume=${LogDir}:/logs"
Cmd+=" --volume=${HOME}/.creds:/.creds"
Cmd+=" -e CONFIG_SERVICE=cloud16.cvtt.vpn:6789"
Cmd+=" ${DockerImage}"
Cmd+=" -d ${date_to_load}"
if [ -n "${NumSymbols}" ]; then
Cmd+=" -N ${NumSymbols}"
fi
echo $Cmd
eval $Cmd
if [ "$?" != "0" ] ; then
exit 1 # if killed we do not save last day
fi

View File

@ -0,0 +1,110 @@
#!/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=https://trading-calendar.cvtt.net/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 [ -z "${date_to_load}" ]; then
echo "date_to_load is empty"
date_to_load=$(get_prev_business_day $(date -d "yesterday" '+%Y-%m-%d'))
echo "Historical Data for ${date_to_load}"
fi
echo "date_to_load=${date_to_load}"
Cmd="docker run"
Cmd+=" --pull=always"
Cmd+=" --network=host"
Cmd+=" --name=${ContainerName}"
Cmd+=" --rm"
Cmd+=" --volume=${LogDir}:/logs"
Cmd+=" --volume=${HOME}/.creds:/.creds"
Cmd+=" -e CONFIG_SERVICE=cloud16.cvtt.vpn:6789"
Cmd+=" ${DockerImage}"
Cmd+=" -d ${date_to_load}"
Cmd+=" -S ${Symbols}"
echo $Cmd
eval $Cmd
if [ "$?" != "0" ] ; then
exit 1 # if killed we do not save last day
fi

View File

@ -1,275 +0,0 @@
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: $0 <source_database_file> <features_database_file>"
exit 1
fi
SRC_DB=$1
DEST_DB=$2
if [ ! -f "$SRC_DB" ]; then
echo "Error: Source database file $SRC_DB does not exist"
exit 1
fi
echo "Creating feature tables in $DEST_DB using data from $SRC_DB..."
# Create md_1min_trade_features table
echo "Creating md_1min_trade_features table..."
sqlite3 "$DEST_DB" "
DROP TABLE IF EXISTS md_1min_trade_features;
CREATE TABLE IF NOT EXISTS md_1min_trade_features (
bin_tstamp TEXT,
tstamp_ns INTEGER,
exchange_id TEXT,
instrument_id TEXT,
price_mean REAL,
price_median REAL,
volume REAL,
vwap REAL,
signed_volume REAL,
order_flow_imbalance REAL,
num_trades INTEGER,
avg_trade_size REAL,
PRIMARY KEY (bin_tstamp, exchange_id, instrument_id)
);"
# Create index for md_1min_trade_features
echo "Creating index for md_1min_trade_features..."
sqlite3 "$DEST_DB" "
CREATE UNIQUE INDEX IF NOT EXISTS md_1min_trade_features_uidx
ON md_1min_trade_features(bin_tstamp, exchange_id, instrument_id);"
# Populate md_1min_trade_features using source database
echo "Populating md_1min_trade_features..."
sqlite3 "$SRC_DB" "ATTACH DATABASE '$DEST_DB' AS dest;
WITH trade_metrics AS (
SELECT
tstamp,
strftime('%Y-%m-%d %H:%M:00', tstamp) as bin_tstamp,
exchange_id,
instrument_id,
px as price,
qty,
CASE
WHEN condition = 'B' THEN qty
WHEN condition = 'S' THEN -qty
ELSE 0
END as signed_qty
FROM md_trades
),
trade_metrics_agg AS (
SELECT
bin_tstamp,
exchange_id,
instrument_id,
COUNT(*) as cnt,
MIN(tstamp) as min_tstamp,
MAX(tstamp) as max_tstamp
FROM trade_metrics
GROUP BY bin_tstamp, exchange_id, instrument_id
)
INSERT INTO dest.md_1min_trade_features
SELECT
tm.bin_tstamp,
CAST(strftime('%s', tm.bin_tstamp) * 1000000000 AS INTEGER) as tstamp_ns,
tm.exchange_id,
tm.instrument_id,
AVG(price) as price_mean,
AVG(CASE WHEN rank_num >= FLOOR(cnt/2.0) AND rank_num <= CEIL(cnt/2.0) THEN price ELSE NULL END) as price_median,
SUM(qty) as volume,
SUM(price * qty) / SUM(qty) as vwap,
SUM(signed_qty) as signed_volume,
SUM(CASE WHEN signed_qty > 0 THEN signed_qty ELSE 0 END) -
SUM(CASE WHEN signed_qty < 0 THEN ABS(signed_qty) ELSE 0 END) as order_flow_imbalance,
COUNT(*) as num_trades,
AVG(qty) as avg_trade_size
FROM (
SELECT
tm.*,
tma.cnt,
ROW_NUMBER() OVER (PARTITION BY tm.bin_tstamp, tm.exchange_id, tm.instrument_id ORDER BY price) as rank_num
FROM trade_metrics tm
JOIN trade_metrics_agg tma
ON tm.bin_tstamp = tma.bin_tstamp
AND tm.exchange_id = tma.exchange_id
AND tm.instrument_id = tma.instrument_id
) tm
GROUP BY tm.bin_tstamp, tm.exchange_id, tm.instrument_id;"
# Create md_1min_quote_features table in destination database
echo "Creating md_1min_quote_features table..."
sqlite3 "$DEST_DB" "
DROP TABLE IF EXISTS md_1min_quote_features;
CREATE TABLE IF NOT EXISTS md_1min_quote_features (
bin_tstamp TEXT,
tstamp_ns INTEGER,
exchange_id TEXT,
instrument_id TEXT,
mid_price_open REAL,
mid_price_high REAL,
mid_price_low REAL,
mid_price_close REAL,
mid_price_mean REAL,
rel_spread_mean REAL,
rel_spread_min REAL,
rel_spread_max REAL,
rel_spread_first REAL,
rel_spread_last REAL,
l1_imbalance_mean REAL,
l1_imbalance_min REAL,
l1_imbalance_max REAL,
l1_imbalance_first REAL,
l1_imbalance_last REAL,
micro_price_mean REAL,
micro_price_min REAL,
micro_price_max REAL,
micro_price_first REAL,
micro_price_last REAL,
weighted_mid_mean REAL,
weighted_mid_min REAL,
weighted_mid_max REAL,
weighted_mid_first REAL,
weighted_mid_last REAL,
PRIMARY KEY (bin_tstamp, exchange_id, instrument_id)
);"
# Create index for md_1min_quote_features
echo "Creating index for md_1min_quote_features..."
sqlite3 "$DEST_DB" "
CREATE UNIQUE INDEX IF NOT EXISTS md_1min_quote_features_uidx
ON md_1min_quote_features(bin_tstamp, exchange_id, instrument_id);"
# Populate md_1min_quote_features using source database
echo "Populating md_1min_quote_features..."
sqlite3 "$SRC_DB" "ATTACH DATABASE '$DEST_DB' AS dest;
INSERT INTO dest.md_1min_quote_features
SELECT
strftime('%Y-%m-%d %H:%M:00', tstamp) as bin_tstamp,
CAST(strftime('%s', tstamp) * 1000000000 AS INTEGER) as tstamp_ns,
exchange_id,
instrument_id,
FIRST_VALUE((ask_px + bid_px) / 2.0) OVER w as mid_price_open,
MAX((ask_px + bid_px) / 2.0) as mid_price_high,
MIN((ask_px + bid_px) / 2.0) as mid_price_low,
LAST_VALUE((ask_px + bid_px) / 2.0) OVER w as mid_price_close,
AVG((ask_px + bid_px) / 2.0) as mid_price_mean,
AVG((ask_px - bid_px) / ((ask_px + bid_px) / 2.0)) as rel_spread_mean,
MIN((ask_px - bid_px) / ((ask_px + bid_px) / 2.0)) as rel_spread_min,
MAX((ask_px - bid_px) / ((ask_px + bid_px) / 2.0)) as rel_spread_max,
FIRST_VALUE((ask_px - bid_px) / ((ask_px + bid_px) / 2.0)) OVER w as rel_spread_first,
LAST_VALUE((ask_px - bid_px) / ((ask_px + bid_px) / 2.0)) OVER w as rel_spread_last,
AVG((bid_qty - ask_qty) / (bid_qty + ask_qty)) as l1_imbalance_mean,
MIN((bid_qty - ask_qty) / (bid_qty + ask_qty)) as l1_imbalance_min,
MAX((bid_qty - ask_qty) / (bid_qty + ask_qty)) as l1_imbalance_max,
FIRST_VALUE((bid_qty - ask_qty) / (bid_qty + ask_qty)) OVER w as l1_imbalance_first,
LAST_VALUE((bid_qty - ask_qty) / (bid_qty + ask_qty)) OVER w as l1_imbalance_last,
AVG((ask_px * bid_qty + bid_px * ask_qty) / (bid_qty + ask_qty)) as micro_price_mean,
MIN((ask_px * bid_qty + bid_px * ask_qty) / (bid_qty + ask_qty)) as micro_price_min,
MAX((ask_px * bid_qty + bid_px * ask_qty) / (bid_qty + ask_qty)) as micro_price_max,
FIRST_VALUE((ask_px * bid_qty + bid_px * ask_qty) / (bid_qty + ask_qty)) OVER w as micro_price_first,
LAST_VALUE((ask_px * bid_qty + bid_px * ask_qty) / (bid_qty + ask_qty)) OVER w as micro_price_last,
AVG((ask_px * ask_qty + bid_px * bid_qty) / (bid_qty + ask_qty)) as weighted_mid_mean,
MIN((ask_px * ask_qty + bid_px * bid_qty) / (bid_qty + ask_qty)) as weighted_mid_min,
MAX((ask_px * ask_qty + bid_px * bid_qty) / (bid_qty + ask_qty)) as weighted_mid_max,
FIRST_VALUE((ask_px * ask_qty + bid_px * bid_qty) / (bid_qty + ask_qty)) OVER w as weighted_mid_first,
LAST_VALUE((ask_px * ask_qty + bid_px * bid_qty) / (bid_qty + ask_qty)) OVER w as weighted_mid_last
FROM md_quotes
GROUP BY strftime('%Y-%m-%d %H:%M:00', tstamp), exchange_id, instrument_id
WINDOW w AS (
PARTITION BY strftime('%Y-%m-%d %H:%M:00', tstamp), exchange_id, instrument_id
ORDER BY tstamp
RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
);"
# Copy the md_1min_bars table to destination database
echo "Copying md_1min_bars to destination..."
sqlite3 "$DEST_DB" "
DROP TABLE IF EXISTS md_1min_bars;
CREATE TABLE IF NOT EXISTS md_1min_bars (
bin_tstamp TEXT,
tstamp_ns INTEGER,
exchange_id TEXT,
instrument_id TEXT,
open REAL,
high REAL,
low REAL,
close REAL,
volume REAL,
vwap REAL,
num_trades INTEGER,
PRIMARY KEY (bin_tstamp, exchange_id, instrument_id)
);"
echo "Creating index for md_1min_bars..."
sqlite3 "$DEST_DB" "
CREATE UNIQUE INDEX IF NOT EXISTS md_1min_bars_uidx
ON md_1min_bars(bin_tstamp, exchange_id, instrument_id);"
echo "Populating md_1min_bars..."
sqlite3 "$SRC_DB" "ATTACH DATABASE '$DEST_DB' AS dest;
INSERT INTO dest.md_1min_bars
SELECT * FROM md_1min_bars;"
# Create the combined features view in destination database
echo "Creating combined features view..."
sqlite3 "$DEST_DB" "
DROP VIEW IF EXISTS md_1min_features_view;
CREATE VIEW IF NOT EXISTS md_1min_features_view AS
SELECT
b.bin_tstamp,
b.tstamp_ns,
b.exchange_id,
b.instrument_id,
-- OHLCV data from md_1min_bars
b.open,
b.high,
b.low,
b.close,
b.volume,
b.vwap,
b.num_trades,
-- Quote features
q.mid_price_open,
q.mid_price_high,
q.mid_price_low,
q.mid_price_close,
q.mid_price_mean,
q.rel_spread_mean,
q.rel_spread_min,
q.rel_spread_max,
q.rel_spread_first,
q.rel_spread_last,
q.l1_imbalance_mean,
q.l1_imbalance_min,
q.l1_imbalance_max,
q.l1_imbalance_first,
q.l1_imbalance_last,
q.micro_price_mean,
q.micro_price_min,
q.micro_price_max,
q.micro_price_first,
q.micro_price_last,
q.weighted_mid_mean,
q.weighted_mid_min,
q.weighted_mid_max,
q.weighted_mid_first,
q.weighted_mid_last,
-- Trade features
t.price_mean as trade_price_mean,
t.price_median as trade_price_median,
t.signed_volume,
t.order_flow_imbalance,
t.avg_trade_size
FROM md_1min_bars b
LEFT JOIN md_1min_quote_features q
ON b.bin_tstamp = q.bin_tstamp
AND b.exchange_id = q.exchange_id
AND b.instrument_id = q.instrument_id
LEFT JOIN md_1min_trade_features t
ON b.bin_tstamp = t.bin_tstamp
AND b.exchange_id = t.exchange_id
AND b.instrument_id = t.instrument_id;"
echo "Feature tables created and populated successfully in $DEST_DB!"

View File

@ -1,10 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
usage() { usage() {
echo -n "Usage: $0 [-h <host (hs01*/cloud21)>]" echo "Usage: $0 [-h <host (hs01*/cloud21)>] [-d <YYYYMMDD> (yesterday*)] [-s <source> (cvttdata/cloud21*)>]"
echo -n " [-d <YYYYMMDD> (yesterday*)]"
echo -n " [-s <source> (cloud28/cloud21*)>]"
echo " [-t <target_dir> (/opt/jupyter_gpu/data/crypto_md)]"
exit 1 exit 1
} }
@ -22,15 +19,11 @@ is_valid() {
return 1 return 1
} }
# ------- D E F A U L T S
date="" date=""
host=hs01 host=hs01
source=cloud21 source=cloud21
TargetDir="/opt/jupyter_gpu/data/crypto_md"
# ------- D E F A U L T S
while getopts ":h:d:s:" opt; do
while getopts ":h:d:s:t:" opt; do
case ${opt} in case ${opt} in
d ) d )
date=$OPTARG date=$OPTARG
@ -41,9 +34,6 @@ while getopts ":h:d:s:t:" opt; do
s ) s )
source=$OPTARG source=$OPTARG
;; ;;
t )
TargetDir=$OPTARG
;;
\? ) \? )
echo "Invalid option: -$OPTARG" >&2 echo "Invalid option: -$OPTARG" >&2
usage usage
@ -67,7 +57,7 @@ if ! is_valid "${host}" "${valid_hosts[@]}" ; then
usage usage
fi fi
valid_sources=('cloud21' 'cloud28') valid_sources=('cloud21' 'cvttdata')
if ! is_valid ${source} ${valid_sources[@]} ; then if ! is_valid ${source} ${valid_sources[@]} ; then
echo "Source '${source}' is not valid" echo "Source '${source}' is not valid"
usage usage
@ -92,6 +82,7 @@ SourceFile=$(date -d ${date} "+%Y%m%d.mktdata.db")
SourceFileZip="${SourceFile}.gz" SourceFileZip="${SourceFile}.gz"
SourceFilePath=$(date -d ${date} "+${SourceRootDir}/%Y/%m/${SourceFileZip}") SourceFilePath=$(date -d ${date} "+${SourceRootDir}/%Y/%m/${SourceFileZip}")
TargetDir="/opt/jupyter_gpu/data/crypto_md"
TargetFile=$(date -d ${date} "+%Y%m%d.mktdata.ohlcv.db") TargetFile=$(date -d ${date} "+%Y%m%d.mktdata.ohlcv.db")
TargetFilePath="${TargetDir}/${TargetFile}" TargetFilePath="${TargetDir}/${TargetFile}"

View File

@ -1,94 +1,99 @@
#!/bin/bash #!/bin/bash
# SQLite DDL for simulation
# =========================
# -- md_quotes
# -- md_1min_bars
usage() {
echo "Usage: $0 -d YYYMMDD Date> [-O <output dir (./) >]"
exit 1
}
# --------------------- Settings # --------------------- Settings
# SOURCE_HOST=cloud21.cvtt.vpn SourceHost=cloud21.cvtt.vpn
# SOURCE_ROOT_DIR=/opt/store/cvtt/md_archive/crypto SourceRootDir=/opt/store/cvtt/md_archive/crypto
# DB_SOURCES=cloud28,cloud29 DbSource=cloud21
# OUTPUT_DIR=/tmp
# DATE=20250516
# RSYNC_TARGETS="cvtt@hs01.cvtt.vpn:/works/cvtt/md_archive/crypto/sim/ cvtt@cloud21.cvtt.vpn:/opt/store/cvtt/md_archive/crypto/sim/"
# --------------------- Settings # --------------------- Settings
if [ -z ${DATE} ] ; then while getopts ":d:O:" opt; do
DATE=$(date -d 'yesterday' +'%Y%m%d') case ${opt} in
fi d )
Date=$OPTARG
if [ -z ${OUTPUT_DIR} ] ; then ;;
OUTPUT_DIR=. O )
fi OutputDir=$OPTARG
;;
echo "DATE=${DATE} SOURCE_HOST=${SOURCE_HOST}" \? )
echo "Invalid option: -$OPTARG" >&2
mkdir -p ${OUTPUT_DIR} usage
;;
year=$(date -d ${DATE} +"%Y") : )
month=$(date -d ${DATE} +"%m") echo "Option -$OPTARG requires an argument." >&2
usage
if [ -z "${DB_SOURCES}" ]; then ;;
echo "DB_SOURCES is empty" esac
exit
fi
IFS=',' read -r -a db_source_hosts <<< "${DB_SOURCES}"
SourceFile="${DATE}.mktdata.db.gz"
SelectedSourceHost=""
SelectedSourceFilePath=""
SelectedSourceSize=0
for db_source_host in "${db_source_hosts[@]}"; do
SourceDir="${SOURCE_ROOT_DIR}/${db_source_host}/${year}/${month}"
CandidatePath="${SourceDir}/${SourceFile}"
remote_stat_cmd="if [ -f '${CandidatePath}' ]; then stat -c %s '${CandidatePath}'; else exit 1; fi"
CandidateSize=$(ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${SOURCE_HOST} "${remote_stat_cmd}" 2>/dev/null)
if [ $? -eq 0 ] && [ -n "${CandidateSize}" ]; then
echo "Found ${SOURCE_HOST}:${CandidatePath} (${CandidateSize} bytes)"
if [ -z "${SelectedSourceHost}" ] || [ "${CandidateSize}" -gt "${SelectedSourceSize}" ]; then
SelectedSourceHost=${db_source_host}
SelectedSourceFilePath=${CandidatePath}
SelectedSourceSize=${CandidateSize}
fi
fi
done done
if [ -z ${Date} ] ; then
if [ -z "${SelectedSourceHost}" ]; then echo "date is not specified"
echo "File ${SourceFile} NOT FOUND on any DB_SOURCES host" usage
exit
fi fi
if [ -z ${OutputDir} ] ; then
OutputDir=.
fi
mkdir -p ${OutputDir}
echo "Using source ${SelectedSourceHost} with ${SelectedSourceFilePath} (${SelectedSourceSize} bytes)" # --- Binance
Instruments=( PAIR-ADA-USDT )
Instruments+=( PAIR-BCH-USDT )
Instruments+=( PAIR-BTC-USDT )
Instruments+=( PAIR-DOT-USDT )
Instruments+=( PAIR-ETH-USDT )
Instruments+=( PAIR-LTC-USDT )
Instruments+=( PAIR-SOL-USDT )
Instruments+=( PAIR-USDC-USDT )
Instruments+=( PAIR-XRP-USDT )
Cmd="/usr/bin/rsync -ahv" # --- Coinbase
Cmd+=" --mkpath" Instruments+=( PAIR-ADA-USD )
Cmd+=" -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'" Instruments+=( PAIR-BCH-USD )
Cmd+=" ${SOURCE_HOST}:${SelectedSourceFilePath}" Instruments+=( PAIR-BTC-USD )
Cmd+=" $OUTPUT_DIR/" Instruments+=( PAIR-DOT-USD )
Instruments+=( PAIR-ETH-USD )
Instruments+=( PAIR-LTC-USD )
Instruments+=( PAIR-SOL-USD )
Instruments+=( PAIR-XRP-USD )
echo "Date=${Date} Instruments=${Instruments[@]} OutputDir=${OutputDir}"
echo Getting data from ${DataHost} ...
year=$(date -d ${Date} +"%Y")
month=$(date -d ${Date} +"%m")
SourceDir="${SourceRootDir}/${DbSource}/${year}/${month}"
SourceFile="${SourceDir}/${Date}.mktdata.db.gz"
Cmd="rsync -ahv"
Cmd+=" ${SourceHost}:${SourceFile}"
Cmd+=" $OutputDir/"
echo ${Cmd} echo ${Cmd}
eval ${Cmd} eval ${Cmd}
if [ ! -f ${OUTPUT_DIR}/${SourceFile} ] ; then Cmd="(cd ${OutputDir} && gunzip *.db.gz)"
echo "File ${OUTPUT_DIR}/${SourceFile} NOT FOUND"
exit
fi
Cmd="(cd ${OUTPUT_DIR} && gunzip -f *.db.gz)"
echo ${Cmd} echo ${Cmd}
eval ${Cmd} eval ${Cmd}
SourceDbFile="${OUTPUT_DIR}/${DATE}.mktdata.db" SourceDbFile="${OutputDir}/${Date}.mktdata.db"
ResultDbFile="${OUTPUT_DIR}/${DATE}.crypto_sim_md.db" ResultDbFile="${OutputDir}/${Date}.crypto_sim_md.db"
echo "SourceDbFile=${SourceDbFile}"
echo "Creating Result Database File ${ResultDbFile}" echo "Creating Result Database File ${ResultDbFile}"
cleanup() {
rm ${SourceDbFile}
}
trap cleanup EXIT
echo "Creating table md_trades ..." echo "Creating table md_trades ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
CREATE TABLE IF NOT EXISTS md_trades ( CREATE TABLE IF NOT EXISTS md_trades (
tstamp text, tstamp text,
tstamp_ns integer, tstamp_ns integer,
@ -101,14 +106,12 @@ CREATE TABLE IF NOT EXISTS md_trades (
condition text, condition text,
tape text tape text
); );
CREATE UNIQUE INDEX IF NOT EXISTS md_trades_uidx CREATE UNIQUE INDEX IF NOT EXISTS md_trades_uidx
ON md_trades(tstamp_ns, exchange_id, instrument_id); ON md_trades(tstamp_ns, exchange_id, instrument_id);
EOF EOF
echo "Creating table md_quotes ..." echo "Creating table md_quotes ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
CREATE TABLE IF NOT EXISTS md_quotes ( CREATE TABLE IF NOT EXISTS md_quotes (
tstamp text, tstamp text,
tstamp_ns integer, tstamp_ns integer,
@ -127,7 +130,6 @@ EOF
echo "Creating table md_1min_bars ..." echo "Creating table md_1min_bars ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
CREATE TABLE IF NOT EXISTS md_1min_bars ( CREATE TABLE IF NOT EXISTS md_1min_bars (
tstamp text, tstamp text,
tstamp_ns integer, tstamp_ns integer,
@ -147,7 +149,6 @@ EOF
echo "Loading md_trades ..." echo "Loading md_trades ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
ATTACH '${SourceDbFile}' AS source_db; ATTACH '${SourceDbFile}' AS source_db;
BEGIN; BEGIN;
INSERT OR IGNORE INTO md_trades SELECT INSERT OR IGNORE INTO md_trades SELECT
@ -185,7 +186,6 @@ EOF
echo "Loading md_quotes ..." echo "Loading md_quotes ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
ATTACH '${SourceDbFile}' AS source_db; ATTACH '${SourceDbFile}' AS source_db;
BEGIN; BEGIN;
INSERT OR IGNORE INTO md_quotes SELECT INSERT OR IGNORE INTO md_quotes SELECT
@ -224,7 +224,6 @@ EOF
echo "Loading md_1min_bars ..." echo "Loading md_1min_bars ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
ATTACH '${SourceDbFile}' AS source_db; ATTACH '${SourceDbFile}' AS source_db;
BEGIN; BEGIN;
INSERT OR IGNORE INTO md_1min_bars SELECT INSERT OR IGNORE INTO md_1min_bars SELECT
@ -261,18 +260,25 @@ COMMIT;
DETACH source_db; DETACH source_db;
EOF EOF
Cmd="rm ${SourceDbFile}"
echo ${Cmd}
eval ${Cmd}
Cmd="gzip ${ResultDbFile}" Cmd="gzip ${ResultDbFile}"
echo ${Cmd} echo ${Cmd}
eval ${Cmd} eval ${Cmd}
for tgt in ${RSYNC_TARGETS} ; do Cmd="rsync -ahvv ${ResultDbFile}.gz cvtt@hs01.cvtt.vpn:/works/cvtt/md_archive/crypto/sim/"
tgt="${tgt}/${year}/${month}/" echo ${Cmd}
Cmd="/usr/bin/rsync -ahv" eval ${Cmd}
Cmd+=" --mkpath"
Cmd+=" -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'" Cmd="rsync -ahvv ${ResultDbFile}.gz cvtt@cloud21.cvtt.vpn:/opt/store/cvtt/md_archive/crypto/sim/"
Cmd+=" ${ResultDbFile}.gz ${tgt}" echo ${Cmd}
echo ${Cmd} eval ${Cmd}
eval ${Cmd}
done Cmd="rm ${ResultDbFile}.gz"
echo ${Cmd}
eval ${Cmd}
echo Done $0 ${*} echo Done $0 ${*}

View File

@ -1,27 +1,23 @@
#!/bin/bash #!/bin/bash
usage() {
echo "Usage: $0 -S <symbols> -d <YYYYMMDD Date> [-O <output dir (./) >]"
exit 1
}
# --------------------- Settings # --------------------- Settings
# SOURCE_HOST=cloud21.cvtt.vpn SourceHost=cloud21.cvtt.vpn
# SOURCE_ROOT_DIR=/opt/store/cvtt/md_archive/equity/alpaca_md SourceRootDir=/opt/store/cvtt/md_archive/equity/alpaca_md
# SYMBOL_LIST=CAN #,COIN,GBTC,HOOD,MSTR,PYPL,XYZ
# OUTPUT_DIR=/tmp
# DATE=20250514
# RSYNC_TARGETS="cvtt@hs01.cvtt.vpn:/works/cvtt/md_archive/equity/test/alpaca_md/sim/"
# RSYNC_TARGETS="cvtt@hs01.cvtt.vpn:/works/cvtt/md_archive/equity/alpaca_md/sim/
#cvtt@cloud21.cvtt.vpn:/opt/store/cvtt/md_archive/equity/alpaca_md/sim/"
# --------------------- Settings # --------------------- Settings
is_business_day() { is_business_day() {
dt=${1} dt=${1}
date=$(date -d "${dt}" +"%Y-%m-%d") date=$(date -d "${dt}" +"%Y-%m-%d")
CalendarURL=https://trading-calendar.cvtt.net/api/v1/markets/hours?mic=XNYS CalendarURL=https://trading-calendar.cvtt.net/api/v1/markets/hours?mic=XNYS
URL="${CalendarURL}&start=${date}&end=${date}" URL="${CalendarURL}&start=${date}&end=${date}"
echo "URL=${URL}"
# curl $URL
open_time=$(curl -s "${URL}" | jq '.[] | .open_time') open_time=$(curl -s "${URL}" | jq '.[] | .open_time')
echo "open_time=${open_time}"
if [ -n "${open_time}" ]; then if [ -n "${open_time}" ]; then
return 0 return 0
else else
@ -31,59 +27,83 @@ is_business_day() {
} }
export -f is_business_day export -f is_business_day
if [ -z ${SYMBOL_LIST} ] ; then
while getopts ":d:S:O:" opt; do
case ${opt} in
d )
Date=$OPTARG
;;
S )
SymList=$OPTARG
;;
O )
OutputDir=$OPTARG
;;
\? )
echo "Invalid option: -$OPTARG" >&2
usage
;;
: )
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
if [ -z ${SymList} ] ; then
echo "symbols are not specified" echo "symbols are not specified"
exit usage
fi fi
if [ -z ${DATE} ] ; then if [ -z ${Date} ] ; then
DATE=$(date -d 'yesterday' +'%Y%m%d') echo "date is not specified"
usage
fi fi
if [ -z ${OutputDir} ] ; then
OutputDir=.
fi
mkdir -p ${OutputDir}
mkdir -p ${OUTPUT_DIR} if ! is_business_day ${Date}; then
echo "${Date} is not business day"
if ! is_business_day ${DATE}; then usage
echo "${DATE} is not business day"
exit
fi fi
OLD_IFS=${IFS} OLD_IFS=${IFS}
IFS="," IFS=","
read -ra Symbols <<< "${SYMBOL_LIST}" read -ra Symbols <<< "${SymList}"
IFS=${OLD_IFS} IFS=${OLD_IFS}
echo "DATE=${DATE} Symbols=${Symbols[@]} OUTPUT_DIR=${OUTPUT_DIR}" echo "Date=${Date} Symbols=${Symbols[@]} OutputDir=${OutputDir}"
echo Getting data from ${DataHost} ... echo Getting data from ${DataHost} ...
year=$(date -d ${DATE} +"%Y") year=$(date -d ${Date} +"%Y")
month=$(date -d ${DATE} +"%m")
for sym in ${Symbols[@]}; do for sym in ${Symbols[@]}; do
inst_id="STOCK-${sym}" inst_id="STOCK-${sym}"
capital=${sym:0:1} capital=${sym:0:1}
SourceDir="${SOURCE_ROOT_DIR}/${year}/${capital}/${sym}" SourceDir="${SourceRootDir}/${year}/${capital}/${sym}"
SourceHbarFile="${SourceDir}/${DATE}.${sym}.alpaca_1m_bars.db.gz" SourceHbarFile="${SourceDir}/${Date}.${sym}.alpaca_1m_bars.db.gz"
SourceQatFile="${SourceDir}/${DATE}.${sym}.alpaca_qat.db.gz" SourceQatFile="${SourceDir}/${Date}.${sym}.alpaca_qat.db.gz"
for src_file in ${SourceHbarFile} ${SourceQatFile}; do for src_file in ${SourceHbarFile} ${SourceQatFile}; do
Cmd="rsync -ahv" Cmd="rsync -ahv"
Cmd+=" -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'" Cmd+=" ${SourceHost}:${src_file}"
Cmd+=" ${SOURCE_HOST}:${src_file}" Cmd+=" $OutputDir/"
Cmd+=" $OUTPUT_DIR/"
echo ${Cmd} echo ${Cmd}
eval ${Cmd} eval ${Cmd}
done done
done done
Cmd="(cd ${OUTPUT_DIR} && gunzip *.db.gz)" Cmd="(cd ${OutputDir} && gunzip *.db.gz)"
echo ${Cmd} echo ${Cmd}
eval ${Cmd} eval ${Cmd}
ResultDbFile="${OUTPUT_DIR}/${DATE}.alpaca_sim_md.db" ResultDbFile="${OutputDir}/${Date}.alpaca_sim_md.db"
echo "Creating Result Database File ${ResultDbFile}"
echo "Creating Result Database File ${ResultDbFile}" echo "Creating Result Database File ${ResultDbFile}"
echo "Creating table md_trades ..." echo "Creating table md_trades ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
CREATE TABLE IF NOT EXISTS md_trades ( CREATE TABLE IF NOT EXISTS md_trades (
tstamp text, tstamp text,
tstamp_ns integer, tstamp_ns integer,
@ -102,7 +122,6 @@ EOF
echo "Creating table md_quotes ..." echo "Creating table md_quotes ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
CREATE TABLE IF NOT EXISTS md_quotes ( CREATE TABLE IF NOT EXISTS md_quotes (
tstamp text, tstamp text,
tstamp_ns integer, tstamp_ns integer,
@ -142,12 +161,11 @@ EOF
# set -f # not to expand * # set -f # not to expand *
for sym in ${Symbols[@]}; do for sym in ${Symbols[@]}; do
src_hbar_db=${OUTPUT_DIR}/${DATE}.${sym}.alpaca_1m_bars.db src_hbar_db=${OutputDir}/${Date}.${sym}.alpaca_1m_bars.db
src_qat_db=${OUTPUT_DIR}/${DATE}.${sym}.alpaca_qat.db src_qat_db=${OutputDir}/${Date}.${sym}.alpaca_qat.db
echo "Loading md_trades and md_quotes from ${src_qat_db} ..." echo "Loading md_trades and md_quotes from ${src_qat_db} ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
ATTACH '${src_qat_db}' AS source_db; ATTACH '${src_qat_db}' AS source_db;
BEGIN; BEGIN;
INSERT OR IGNORE INTO md_trades SELECT INSERT OR IGNORE INTO md_trades SELECT
@ -182,7 +200,6 @@ EOF
echo "Loading md_1min_bars from ${src_hbar_db} ..." echo "Loading md_1min_bars from ${src_hbar_db} ..."
sqlite3 ${ResultDbFile} <<EOF sqlite3 ${ResultDbFile} <<EOF
.echo ON
ATTACH '${src_hbar_db}' AS source_db; ATTACH '${src_hbar_db}' AS source_db;
BEGIN; BEGIN;
INSERT OR IGNORE INTO md_1min_bars SELECT INSERT OR IGNORE INTO md_1min_bars SELECT
@ -203,7 +220,7 @@ COMMIT;
DETACH source_db; DETACH source_db;
EOF EOF
Cmd="rm ${src_hbar_db} ${src_qat_db}" Cmd="rm ${src_hbar_db} ${src_qat_db}"
echo ${Cmd} echo ${Cmd}
eval ${Cmd} eval ${Cmd}
done done
@ -212,13 +229,16 @@ Cmd="gzip ${ResultDbFile}"
echo ${Cmd} echo ${Cmd}
eval ${Cmd} eval ${Cmd}
for tgt in ${RSYNC_TARGETS} ; do Cmd="rsync -ahvv ${ResultDbFile}.gz cvtt@hs01.cvtt.vpn:/works/cvtt/md_archive/equity/alpaca_md/sim/"
Cmd="/usr/bin/rsync -ahv" echo ${Cmd}
Cmd+=" --mkpath" eval ${Cmd}
Cmd+=" -e 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'"
Cmd+=" ${ResultDbFile}.gz ${tgt}/${year}/${month}/" Cmd="rsync -ahvv ${ResultDbFile}.gz cvtt@cloud21.cvtt.vpn:/opt/store/cvtt/md_archive/equity/alpaca_md/sim/"
echo ${Cmd} echo ${Cmd}
eval ${Cmd} eval ${Cmd}
done
Cmd="rm ${ResultDbFile}.gz"
echo ${Cmd}
eval ${Cmd}
echo Done $0 ${*} echo Done $0 ${*}

View File

@ -0,0 +1,44 @@
#!/bin/bash
Python=/home/cvtt/.pyenv/python3.12-venv/bin/python3.12
RootDir=/home/cvtt/prod
export PYTHONPATH=${RootDir}
host=${1}
if [ "${host}" == "cvttdata" ]
then
ArchiveRootDir=/home/cvtt/prod/archive/md_archive/crypto/cvttdata
CredKey=TSDB_MD_CVTTDATA_RO
elif [ "${host}" == "cloud21" ]
then
ArchiveRootDir=/home/cvtt/prod/archive/md_archive/crypto/cloud21
CredKey=TSDB_MD_CLD21_RO
else
echo "Unknown host ${host}. ${0} Aborted."
exit 1
fi
mkdir -p ${ArchiveRootDir}
yesterday=$(date -d "yesterday" +%Y%m%d)
Schemas=${2}
if [ "${Schemas}" == "" ]
then
Schemas="coinbase,bnbspot,bnbfut"
fi
echo "Schemas=${Schemas}"
Cmd=
Cmd="${Python}"
Cmd="${Cmd} ${RootDir}/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} --date=${yesterday}"
Cmd="${Cmd} --schemas=${Schemas}"
Cmd="${Cmd} --root_dir=${ArchiveRootDir}"
Cmd="${Cmd} --format=SQLite"
Cmd="${Cmd} --compress"
echo ${Cmd}
eval ${Cmd}
echo "${0} ${*} Done."

View File

@ -26,11 +26,9 @@ run_checklist() {
declare -A Commands declare -A Commands
Commands=( Commands=(
["hs01:cloud21"]="ssh cvtt@hs01.cvtt.vpn ls -l /works/cvtt/md_archive/crypto/cloud21/${yr}/${mn} | tail -5" ["hs01:cloud21"]="ssh cvtt@hs01.cvtt.vpn ls -l /works/cvtt/md_archive/crypto/cloud21/${yr}/${mn} | tail -5"
["hs01:cloud28"]="ssh cvtt@hs01.cvtt.vpn ls -l /works/cvtt/md_archive/crypto/cloud28/${yr}/${mn} | tail -5" ["hs01:cvttdata"]="ssh cvtt@hs01.cvtt.vpn ls -l /works/cvtt/md_archive/crypto/cvttdata/${yr}/${mn} | tail -5"
["hs01:sim"]="ssh cvtt@hs01.cvtt.vpn ls -l /works/cvtt/md_archive/crypto/sim/ | tail -5" ["cloud21:cloud21"]="ssh cvtt@cloud21.cvtt.vpn ls -l /opt/store/cvtt/md_archive/crypto/cloud21/${yr}/${mn} | tail -5"
["cloud21:cloud21"]="ssh cvtt@cloud21.cvtt.vpn ls -l /works/cvtt/md_archive/crypto/cloud21/${yr}/${mn} | tail -5" ["cloud21:cvttdata"]="ssh cvtt@cloud21.cvtt.vpn ls -l /opt/store/cvtt/md_archive/crypto/cvttdata/${yr}/${mn} | tail -5"
["cloud21:cloud28"]="ssh cvtt@cloud21.cvtt.vpn ls -l /works/cvtt/md_archive/crypto/cloud28/${yr}/${mn} | tail -5"
["cloud21:sim"]="ssh cvtt@cloud21.cvtt.vpn ls -l /works/cvtt/md_archive/crypto/sim | tail -5"
["gpushnik"]="ssh oleg@gpushnik.cvtt.vpn 'ls -l /opt/jupyter_gpu/data/crypto_md | tail -10'" ["gpushnik"]="ssh oleg@gpushnik.cvtt.vpn 'ls -l /opt/jupyter_gpu/data/crypto_md | tail -10'"
) )

View File

@ -29,14 +29,12 @@ run_checklist() {
Commands["hs01"]+="ssh cvtt@hs01.cvtt.vpn ls -l /works/cvtt/md_archive/equity/alpaca_md/${yr}/${sym} | tail -3; " Commands["hs01"]+="ssh cvtt@hs01.cvtt.vpn ls -l /works/cvtt/md_archive/equity/alpaca_md/${yr}/${sym} | tail -3; "
done done
Commands["hs01"]+="echo" Commands["hs01"]+="echo"
Commands["hs01:sim"]="ssh cvtt@hs01.cvtt.vpn ls -l /works/cvtt/md_archive/equity/alpaca_md/sim | tail -5"
Commands["cloud21"]="" Commands["cloud21"]=""
for sym in ${CheckSymbols}; do for sym in ${CheckSymbols}; do
Commands["cloud21"]+="ssh cvtt@cloud21.cvtt.vpn ls -l /works/cvtt/md_archive/equity/alpaca_md/${yr}/${sym} | tail -3; " Commands["cloud21"]+="ssh cvtt@cloud21.cvtt.vpn ls -l /opt/store/cvtt/md_archive/equity/alpaca_md/${yr}/${sym} | tail -3; "
done done
Commands["cloud21"]+="echo" Commands["cloud21"]+="echo"
Commands["cloud21:sim"]="ssh cvtt@cloud21.cvtt.vpn ls -l /works/cvtt/md_archive/equity/alpaca_md/sim | tail -5"
Commands["gpushnik"]="ssh oleg@gpushnik.cvtt.vpn 'ls -l /opt/jupyter_gpu/data/eqty_md | tail -10'" Commands["gpushnik"]="ssh oleg@gpushnik.cvtt.vpn 'ls -l /opt/jupyter_gpu/data/eqty_md | tail -10'"
@ -48,13 +46,6 @@ run_checklist() {
done done
} }
tmpfile=$(mktemp)
function cleanup {
cd ${HOME}
rm -f ${tmpfile}
}
trap cleanup EXIT
# run_checklist # run_checklist
tmpfile=$(mktemp) tmpfile=$(mktemp)

View File

@ -1,63 +1,36 @@
#!/bin/bash #!/bin/bash
function usage { function usage {
echo -n "Usage: ${0}" echo "Usage: ${0} <log directory> [days (default 2)]"
echo -n " -L <log directory>"
echo -n " [ -A <archive_logs_dir> (default /works/archive/logs)]"
echo -n " [-D <older than time criteria> (default: '2 days ago')]"
echo
exit 1 exit 1
} }
echo Starting $0 $* echo Starting $0 $*
# ---- D e f a u l t s LogDir=${1}
LogArchiveDir=/works/archive/logs
DateCriteria="2 days ago"
# ---- D e f a u l t s
# ---------------- cmdline
while getopts "A:L:D:" opt; do
case ${opt} in
A )
LogArchiveDir=$OPTARG
;;
L )
LogDir=$OPTARG
;;
D )
DateCriteria=$OPTARG
;;
\? )
echo "Invalid option: -$OPTARG" >&2
usage
;;
: )
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
# ---------------- cmdline
if [ "${LogDir}" == "" ] if [ "${LogDir}" == "" ]
then then
usage usage
fi fi
Cmd="mkdir -p ${LogArchiveDir}" Days=${2}
echo ${Cmd} && eval ${Cmd} if [ "${Days}" == "" ]
then
Days=2
fi
echo "Looking for log files older than '${DateCriteria}' in ${LogDir}" DateCriteria="${Days} days ago"
Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d %H:%M:%S') Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d')
Cmd="find ${LogDir}/ '(' -name '*.log' -o -name '*.log.*' ')' -type f -not -newermt \"${Oldest}\"" echo "Looking for log files older than ${DateCriteria} in ${LogDir}"
echo $Cmd
files=$(eval ${Cmd}) LogArchiveDir=${HOME}/prod/archive/logs
mkdir -p ${LogArchiveDir}
echo "find ${LogDir}/ '(' -name '*.log' -o -name '*.log.*' ')' -type f -not -newermt ${Oldest})"
files=$(find ${LogDir}/ '(' -name '*.log' -o -name '*.log.*' ')' -type f -not -newermt ${Oldest})
if [ "$files" == "" ] if [ "$files" == "" ]
then then
echo "No files found older than ${Oldest} in ${LogDir}" echo "No files found older than ${Oldest} in ${LogDir}"

View File

@ -1,57 +1,40 @@
#!/bin/bash #!/bin/bash
# FOR hosts with limited disk space - move to storage server
# FOR cloud hosts with limited disk space - move to storage server
function usage { function usage {
echo -n "Usage: ${0}" echo "Usage: ${0} <host> <from_dir> <days>"
echo -n " -H <host_label>"
echo -n " [ -A <archive_dir> (default /works/archive)]"
echo -n " [-D <older than time criteria> (default: '2 days ago')]"
echo
exit 1 exit 1
} }
echo Starting $0 $* echo Starting $0 $*
# ---- D e f a u l t s
ArchiveDir=/works/archive
DateCriteria="2 days ago"
FromHost=$(hostname -s) FromHost=$(hostname -s)
# ---- D e f a u l t s
# ---------------- cmdline
while getopts "A:H:D:" opt; do
case ${opt} in
A )
ArchiveDir=$OPTARG
;;
H )
FromHost=$OPTARG
;;
D )
DateCriteria=$OPTARG
;;
\? )
echo "Invalid option: -$OPTARG" >&2
usage
;;
: )
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
# ---------------- cmdline
if [ "${FromHost}" == "" ] if [ "${FromHost}" == "" ]
then then
usage usage
fi fi
ArchiveDir=${2}
if [ "${ArchiveDir}" == "" ]
then
usage
fi
Days=${3}
if [ "${Days}" == "" ]
then
Days=2
fi
DateCriteria="${Days} days ago"
TargetHost=cloud21.cvtt.vpn TargetHost=cloud21.cvtt.vpn
TargetRootDir=/opt/store/cvtt/archive TargetRootDir=/opt/store/cvtt/archive
Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d %H:%M:%S') Oldest=$(date -d "${DateCriteria}" '+%Y-%m-%d')
Now=$(date '+%Y%m%d_%H%M%S')
echo "Looking for log files older than ${DateCriteria} in ${ArchiveDir}" echo "Looking for log files older than ${DateCriteria} in ${ArchiveDir}"
Cmd="find ${ArchiveDir}/" Cmd="find ${ArchiveDir}/"
@ -62,7 +45,7 @@ Cmd="${Cmd} -o -name '*.logs.*'"
Cmd="${Cmd} -o -name '*.tgz'" Cmd="${Cmd} -o -name '*.tgz'"
Cmd="${Cmd} ')'" Cmd="${Cmd} ')'"
Cmd="${Cmd} -type f" Cmd="${Cmd} -type f"
Cmd="${Cmd} -not -newermt \"${Oldest}\"" Cmd="${Cmd} -not -newermt ${Oldest}"
echo ${Cmd} echo ${Cmd}
files=$(eval ${Cmd}) files=$(eval ${Cmd})