From 11ab9dd2c2a432bfd458e21714e63298616b15c9 Mon Sep 17 00:00:00 2001 From: Oleg Sheynin Date: Fri, 6 Dec 2024 17:34:37 -0500 Subject: [PATCH] prepare sim for crypto (before added num_trades) --- release_version.txt | 2 +- research/prepare_crypto_simdata.sh | 322 ++++++++++++++++++++++------- 2 files changed, 244 insertions(+), 80 deletions(-) diff --git a/release_version.txt b/release_version.txt index e6edfcd..3a50647 100644 --- a/release_version.txt +++ b/release_version.txt @@ -1 +1 @@ -1.9.1,16->23 +1.9.2,prepare_crypto_simdata diff --git a/research/prepare_crypto_simdata.sh b/research/prepare_crypto_simdata.sh index 1c2a014..b839a4d 100755 --- a/research/prepare_crypto_simdata.sh +++ b/research/prepare_crypto_simdata.sh @@ -1,41 +1,30 @@ #!/bin/bash +# SQLite DDL for simulation +# ========================= + + +# -- md_quotes + +# -- md_1min_bars + + usage() { - echo "Usage: $0 -S -d [-O ]" + echo "Usage: $0 -d YYYMMDD Date> [-O ]" exit 1 } # --------------------- Settings SourceHost=cloud21.cvtt.vpn -SourceRootDir=/opt/store/cvtt/md_archive/crypto/alpaca_md +SourceRootDir=/opt/store/cvtt/md_archive/crypto +DbSource=cloud21 # --------------------- Settings - -is_business_day() { - dt=${1} - date=$(date -d "${dt}" +"%Y-%m-%d") - - CalendarURL=http://cloud23.cvtt.vpn:8000/api/v1/markets/hours?mic=XNYS - URL="${CalendarURL}&start=${date}&end=${date}" - open_time=$(curl -s "${URL}" | jq '.[] | .open_time') - if [ -n "${open_time}" ]; then - return 0 - else - return 1 - fi - -} -export -f is_business_day - - -while getopts ":d:S:O:" opt; do +while getopts ":d:O:" opt; do case ${opt} in d ) Date=$OPTARG ;; - S ) - SymList=$OPTARG - ;; O ) OutputDir=$OPTARG ;; @@ -50,10 +39,6 @@ while getopts ":d:S:O:" opt; do esac done -if [ -z ${SymList} ] ; then - echo "symbols are not specified" - usage -fi if [ -z ${Date} ] ; then echo "date is not specified" usage @@ -63,84 +48,263 @@ if [ -z ${OutputDir} ] ; then fi mkdir -p ${OutputDir} -if ! is_business_day ${Date}; then - echo "${Date} is not business day" - usage -fi +# --- 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 ) -OLD_IFS=${IFS} -IFS="," -read -ra Symbols <<< "${SymList}" -IFS=${OLD_IFS} +# --- Coinbase +Instruments+=( PAIR-ADA-USD ) +Instruments+=( PAIR-BCH-USD ) +Instruments+=( PAIR-BTC-USD ) +Instruments+=( PAIR-DOT-USD ) +Instruments+=( PAIR-ETH-USD ) +Instruments+=( PAIR-LTC-USD ) +Instruments+=( PAIR-SOL-USD ) +Instruments+=( PAIR-XRP-USD ) -echo "Date=${Date} Symbols=${Symbols[@]} OutputDir=${OutputDir}" +echo "Date=${Date} Instruments=${Instruments[@]} OutputDir=${OutputDir}" echo Getting data from ${DataHost} ... year=$(date -d ${Date} +"%Y") -for sym in ${Symbols[@]}; do - inst_id="STOCK-${sym}" - capital=${sym:0:1} - SourceDir="${SourceRootDir}/${year}/${capital}/${sym}" - SourceHbarFile="${SourceDir}/${Date}.${sym}.alpaca_1m_bars.db.gz" - SourceQatFile="${SourceDir}/${Date}.${sym}.alpaca_qat.db.gz" +month=$(date -d ${Date} +"%m") +SourceDir="${SourceRootDir}/${DbSource}/${year}/${month}" +SourceFile="${SourceDir}/${Date}.mktdata.db.gz" - for src_file in ${SourceHbarFile} ${SourceQatFile}; do - Cmd="rsync -ahv" - Cmd+=" ${SourceHost}:${src_file}" - Cmd+=" $OutputDir/" - echo ${Cmd} - eval ${Cmd} - done -done +Cmd="rsync -ahv" +Cmd+=" ${SourceHost}:${SourceFile}" +Cmd+=" $OutputDir/" +echo ${Cmd} +eval ${Cmd} Cmd="(cd ${OutputDir} && gunzip *.db.gz)" echo ${Cmd} eval ${Cmd} -ResultDbFile="${OutputDir}/${Date}.alpaca_sim_md.db" +SourceDbFile="${OutputDir}/${Date}.mktdata.db" +ResultDbFile="${OutputDir}/${Date}.crypto_sim_md.db" + echo "Creating Result Database File ${ResultDbFile}" -sym=${Symbols[0]} -for db_file in ${OutputDir}/${Date}.${sym}.alpaca_1m_bars.db ${OutputDir}/${Date}.${sym}.alpaca_qat.db ; do - Cmd="sqlite3" - Cmd+=" ${db_file} .schema" - Cmd+=" | sqlite3 ${ResultDbFile}" - echo ${Cmd} - eval ${Cmd} -done -set -f # not to expand * +echo "Creating table md_trades ..." +sqlite3 ${ResultDbFile} <