From 494241ec6603d963dfec84ccea603f4e76cb3d87 Mon Sep 17 00:00:00 2001 From: Oleg Sheynin Date: Sat, 24 Aug 2024 20:52:24 -0400 Subject: [PATCH] progress --- market_data/md_portal/run_md_portal.sh | 22 ++--- trading/trading_recorder/.creds | 12 +++ trading/trading_recorder/Dockerfile | 23 +++++ trading/trading_recorder/requirements.txt | 15 ++++ .../trading_recorder/run_trading_recorder.sh | 84 +++++++++++++++++++ 5 files changed, 146 insertions(+), 10 deletions(-) create mode 100644 trading/trading_recorder/.creds create mode 100644 trading/trading_recorder/Dockerfile create mode 100644 trading/trading_recorder/requirements.txt create mode 100755 trading/trading_recorder/run_trading_recorder.sh diff --git a/market_data/md_portal/run_md_portal.sh b/market_data/md_portal/run_md_portal.sh index d07c01c..2680609 100755 --- a/market_data/md_portal/run_md_portal.sh +++ b/market_data/md_portal/run_md_portal.sh @@ -2,29 +2,31 @@ # runs in container - - # runs on host to start container usage() { - echo -n "Usage: $0 -c " - echo -n " -e " - echo -n " -a " - echo -n " -n " + echo -n "Usage: ${0}" + echo -n " [-C ]" + echo -n " [-c ]" + echo -n " [-e ]" + echo -n " [-a ]" + echo -n " [-n ]" echo exit 1 } - - # ConfigServer=cloud16.cvtt.vpn ConfigServer=cloud23.cvtt.vpn:6789 +Config=apps/cvtt_eqt_alpaca ActiveExchanges=ALPACA_SNDBX PortalName=MD_PORTAL_ALPACA_SNDBX AdminPort=7220 -while getopts ":c:e:a:n:" opt; do +while getopts ":C:c:e:a:n:" opt; do case ${opt} in + C ) + Config=$OPTARG + ;; c ) ConfigServer=$OPTARG ;; @@ -51,7 +53,7 @@ done Cmd="python3.10" Cmd="${Cmd} cvttpy/apps/md/md_portal.py" -Cmd="${Cmd} --config=http://${ConfigServer}/apps/md_portal" +Cmd="${Cmd} --config=http://${ConfigServer}/${Config}" Cmd="${Cmd} --credentials_file=/.creds" Cmd="${Cmd} --active_exchanges=${ActiveExchanges}" Cmd="${Cmd} --portal_name=${PortalName}" diff --git a/trading/trading_recorder/.creds b/trading/trading_recorder/.creds new file mode 100644 index 0000000..4b66d91 --- /dev/null +++ b/trading/trading_recorder/.creds @@ -0,0 +1,12 @@ +{ + "__dummy__": null + , "ALPACA_SANDBOX": { + "api_key": "PKLZSLFZMFMN1R28K9HK" + , "secret_key": "SKbxwLWJNs4kpn618DgGaopN6x1xzKwLM4Z7aymA" + } + , "MATTERMOST": { + "url": "https://mattermost.cryptovaltrading.com" + , "team": "CVTT" + , "bearer": "5ysaaxjeijrwjbmhuzcuos9ano" + } +} diff --git a/trading/trading_recorder/Dockerfile b/trading/trading_recorder/Dockerfile new file mode 100644 index 0000000..9bc977c --- /dev/null +++ b/trading/trading_recorder/Dockerfile @@ -0,0 +1,23 @@ +FROM python:3.10-slim + +ARG FROM_DIR=docker_dev/trading/trading_recorder + +COPY ${FROM_DIR}/requirements.txt / +RUN pip install --upgrade pip --root-user-action=ignore +RUN pip install -r /requirements.txt --root-user-action=ignore + +COPY cvttpy /cvttpy +COPY ${FROM_DIR}/.creds /.creds + + +COPY ${FROM_DIR}/run_trading_recorder.sh /run_trading_recorder.sh +RUN chmod +x /run_trading_recorder.sh + +RUN mkdir /logs + + +WORKDIR / +SHELL ["/bin/bash", "-c"] +ENV PYTHONPATH=/ +ENTRYPOINT [ "/run_trading_recorder.sh" ] + diff --git a/trading/trading_recorder/requirements.txt b/trading/trading_recorder/requirements.txt new file mode 100644 index 0000000..34d80a4 --- /dev/null +++ b/trading/trading_recorder/requirements.txt @@ -0,0 +1,15 @@ +aiohttp>=3.7.4.post0 +nest-asyncio>=1.5.5 +hjson>=3.1.0 +sortedcontainers>=2.4.0 +pandas>=1.5.3 +# +redis>=5.0.8 +# +python-dateutil>=2.8.2 +types-python-dateutil>=2.8.19.6 +# +psycopg>=3.2.1 +psycopg-binary>=3.2.1 +psycopg2-binary>=2.9.6 + diff --git a/trading/trading_recorder/run_trading_recorder.sh b/trading/trading_recorder/run_trading_recorder.sh new file mode 100755 index 0000000..f2ee0b9 --- /dev/null +++ b/trading/trading_recorder/run_trading_recorder.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +#[program:trading_rec_alpaca] +#directory=/home/cvtt/prod +#command=/home/cvtt/.pyenv/python3.10-venv/bin/python3 +# -u /home/cvtt/prod/cvttpy/apps/trade_recorder.py +# --config=http://cloud16.cvtt.vpn:6789/apps/cvtt_eqt_alpaca +# --active_exchanges=ALPACA_SNDBX-MDPORTAL +# --book=ALPACA_BK02 +# --dynamic_instruments=ALPACA_SNDBX +# --admin_port=7225 +# --log_level=INFO +# --log_file=/home/cvtt/prod/logs/%%T.TRADING_REC_APP.log +# # --debug_mode +#autostart=true +#autorestart=true +#startretries=1 +#startsecs=3 +#priority=2 +#user=cvtt + + + +# runs on host to start container +usage() { + echo -n "Usage: $0" + echo -n " -b " + echo -n " [-C ]" + echo -n " [-c ]" + echo -n " [-e ]" + echo -n " [-a "] + echo + exit 1 +} + +# ConfigServer=cloud16.cvtt.vpn +ConfigServer=cloud23.cvtt.vpn:6789 +ActiveExchanges=ALPACA_SNDBX-MDPORTAL +AdminPort=7225 +Book="" +Config=apps/cvtt_eqt_alpaca + +while getopts ":C:b:c:e:a:" opt; do + case ${opt} in + c ) + ConfigServer=$OPTARG + ;; + e ) + ActiveExchanges=$OPTARG + ;; + a ) + AdminPort=$OPTARG + ;; + b ) + Book=$OPTARG + ;; + \? ) + echo "Invalid option: -$OPTARG" >&2 + usage + ;; + : ) + echo "Option -$OPTARG requires an argument." >&2 + usage + ;; + esac +done + +if [ "${Book}" == "" ]; then + echo "Book is missing" + usage +fi + +Cmd="python3.10" +Cmd="${Cmd} cvttpy/apps/trader_app.py" +Cmd="${Cmd} --config=http://${ConfigServer}/${Config}" +Cmd="${Cmd} --credentials_file=/.creds" +Cmd="${Cmd} --book=${Book}" +Cmd="${Cmd} --allow_dynamic_exch_inst" +Cmd="${Cmd} --active_exchanges=${ActiveExchanges}" +Cmd="${Cmd} --admin_port=${AdminPort}" +Cmd="${Cmd} --log_file=/logs/%T.TRADING_RECORDER.${Book}.log" +Cmd="${Cmd} --compress_log" +echo ${Cmd} +eval ${Cmd}