diff --git a/microservices/.creds b/microservices/.creds new file mode 100644 index 0000000..0a3b012 --- /dev/null +++ b/microservices/.creds @@ -0,0 +1,7 @@ +{ + "__dummy__": null + , "ALPACA_SANDBOX": { + "api_key": "PKLZSLFZMFMN1R28K9HK" + , "secret_key": "SKbxwLWJNs4kpn618DgGaopN6x1xzKwLM4Z7aymA" + } +} diff --git a/microservices/docker-compose.yml b/microservices/docker-compose.yml new file mode 100644 index 0000000..84828cf --- /dev/null +++ b/microservices/docker-compose.yml @@ -0,0 +1,60 @@ +version: "3.9" + +services: + md_gateway: + image: md_gateway:latest + container_name: md_gateway + environment: + - REDIS_HOST=redis + volumes: + - ./config:/shared/config + - ./logs:/shared/logs + depends_on: + - redis + + redis: + image: redis:latest + container_name: redis + ports: + - "6379:6379" + volumes: + - redis_data:/data + +volumes: + redis_data: +# version: "3.9" + +# services: +# redis: +# image: redis:latest +# container_name: redis +# ports: +# - "6379:6379" +# volumes: +# - redis_data:/data + +# market_data_gateway: +# image: your_market_data_gateway_image:latest +# container_name: market_data_gateway +# environment: +# - REDIS_HOST=redis +# volumes: +# - ./config:/shared/config +# - ./logs:/shared/logs +# depends_on: +# - redis + +# test_program: +# image: your_test_program_image:latest +# container_name: test_program +# environment: +# - REDIS_HOST=redis +# volumes: +# - ./config:/shared/config +# - ./logs:/shared/logs +# depends_on: +# - market_data_gateway +# - redis + +# volumes: +# redis_data: diff --git a/microservices/md_gateway/.dockerignore b/microservices/md_gateway/.dockerignore new file mode 100644 index 0000000..a4f7c14 --- /dev/null +++ b/microservices/md_gateway/.dockerignore @@ -0,0 +1,3 @@ +.git +**/__pycache__ +.pipenv \ No newline at end of file diff --git a/microservices/md_gateway/Dockerfile b/microservices/md_gateway/Dockerfile new file mode 100644 index 0000000..9edc896 --- /dev/null +++ b/microservices/md_gateway/Dockerfile @@ -0,0 +1,25 @@ +FROM python:3.12-slim + +ARG ROOT_MCRSVC_DIR=docker_dev/microservices +ARG FROM_DIR=${ROOT_MCRSVC_DIR}/md_gateway + +COPY ${ROOT_MCRSVC_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 ${ROOT_MCRSVC_DIR}/.creds /.creds + + +COPY ${FROM_DIR}/run_mdgw.sh /run_mdgw.sh +RUN chmod +x /run_mdgw.sh + +RUN mkdir /logs +RUN mkdir -p /config + + +WORKDIR / +SHELL ["/bin/bash", "-c"] +ENV PYTHONPATH=/ +ENTRYPOINT [ "/run_mdgw.sh" ] + diff --git a/microservices/md_gateway/run_mdgw.sh b/microservices/md_gateway/run_mdgw.sh new file mode 100755 index 0000000..b68481b --- /dev/null +++ b/microservices/md_gateway/run_mdgw.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# runs in container + +# runs on host to start container +usage() { + echo -n "Usage: ${0}" + echo -n " [-c ]" + echo -n " [-e ]" + echo -n " [-a ]" + echo -n " [-n ]" + echo -n " [-z (compress log)"] + echo + exit 1 +} + +Config=/config/cvtt.cfg +ActiveExchanges=ALPACA_SNDBX +PortalName=MD_PORTAL_ALPACA_SNDBX +AdminPort=7220 +COMPRESS_LOG=false + + +while getopts "c:e:a:n:z" opt; do + case ${opt} in + c ) Config=$OPTARG ;; + e ) ActiveExchanges=$OPTARG ;; + a ) AdminPort=$OPTARG ;; + z ) COMPRESS_LOG=true ;; + n ) PortalName=$OPTARG ;; + \? ) + echo "Invalid option: -$OPTARG" >&2 + usage + ;; + : ) + echo "Option -$OPTARG requires an argument." >&2 + usage + ;; + esac +done + +Cmd="python3.12" +Cmd="${Cmd} cvttpy/apps/microservices/mkt_data_gateway/md_gateway.py" +Cmd="${Cmd} --config=${Config}" +Cmd="${Cmd} --credentials_file=/.creds" +Cmd="${Cmd} --active_exchanges=${ActiveExchanges}" +Cmd="${Cmd} --portal_name=${PortalName}" +Cmd="${Cmd} --admin_port=${AdminPort}" +Cmd="${Cmd} --log_file=/logs/%T.${PortalName}.log" +if ${COMPRESS_LOG}; then + Cmd="${Cmd} --compress_log" +fi +echo ${Cmd} +eval ${Cmd} + + diff --git a/microservices/requirements.txt b/microservices/requirements.txt new file mode 100644 index 0000000..852e647 --- /dev/null +++ b/microservices/requirements.txt @@ -0,0 +1,7 @@ +aiohttp>=3.7.4.post0 +nest-asyncio>=1.5.5 +hjson>=3.1.0 +sortedcontainers>=2.4.0 +redis>=5.0.8 +python-dateutil>=2.8.2 +types-python-dateutil>=2.8.19.6