Skip to content

CoCalc docker image for running a server for backtesting

Notifications You must be signed in to change notification settings

tradingstrategy-ai/cocalc-env

Repository files navigation

Trading Strategy CoCalc environment

Dockerized CoCalc environment for Trading Strategy algorithmic trading framework and protocol.

CoCalc benefits over vanilla Jupyter notebooks

  • CoCalc Docker image offers a multi-user environment, where each user gets their own username, password and project folders
  • The notebook execution continues even if you close the browser or a notebook
  • The output will correctly resumed and stored on the server

Overview

Prerequisites

To run this project you need:

  • Docker
  • Docker Compose

Notes

  • When you sign in, you need to create a new user - the email verification is disabled
  • Choose ipykernel - Sage Kernel does not seem to support our custom installed packages

Get started

Clone this repository:

git clone https://github.com/tradingstrategy-ai/cocalc-env.git
cd cocalc-end

# Pull in trade-executor pinned down branch
git submodule update --init --recursive  

Create HTTP Basic Auth username and password that will protect the server. These are stored in secrets.env Docker environment file. Note that it is important to wrap variable values to '' as otherwise Docker attempts to expand dollar sign. Replace "tradingstrategy" / "mypassword" with your own username and password combination:

echo "HTTP_BASIC_AUTH_USER='tradingstrategy'" >> secrets.env
HASHED_PASSWORD=$(docker-compose run caddy caddy hash-password --plaintext "mypassword")
echo "HTTP_BASIC_AUTH_PASSWORD='$HASHED_PASSWORD'" >> secrets.env

Build a local image of the environment:

export COCALC_ENV_VERSION=local
docker build -t ghcr.io/tradingstrategy-ai/cocalc-env:$COCALC_ENV_VERSION .

# Show the versions we took
docker run ghcr.io/tradingstrategy-ai/cocalc-env:$COCALC_ENV_VERSION pip3 list

Use docker compose to bring up the environment for the first time:

docker-compose up 

The default port is 9998 and we will listen to any IPs:

docker-compose up -d

# or one liner
COCALC_ENV_BIND=9999 docker-compose up -d

Then open http://localhost:9999 in your web browser. You can browse available

Update to latest version of the pre-built environment

Assuming you have existing secrets and user database, and you want to update the current environment to the latest trade-exeuctor master:

cd deps/trade-executor
git checkout master  # Pull latest changes
git pull
cd ../..
git add deps/trade-executor
poetry update  # Rebuild Poetry lock file
git commit -m "Updated to the latest master"
git push

And then rebuild the image based on the above instructions.

export COCALC_ENV_VERSION=local
docker build -t ghcr.io/tradingstrategy-ai/cocalc-env:$COCALC_ENV_VERSION .
docker compose up -d 

Develop this environment

Build the Docker image from the scratch:

git submodule update --init --recursive  
# Warning: 15 GB download
docker build -t ghcr.io/tradingstrategy-ai/cocalc-env:local .

Test the built image:

COCALC_ENV_VERSION=local docker-compose up 

Or:

docker run -v ~/cocalc:/projects -p 443:443 ghcr.io/tradingstrategy-ai/cocalc-env:local
docker run -v ~/cocalc:/projects --env NOSSL=true -p 9999:80 ghcr.io/tradingstrategy-ai/cocalc-env:local

Testing with vanilla CoCalc

docker run --name=cocalc --env NOSSL=true -d -v ~/cocalc:/projects -p 8080:80 sagemathinc/cocalc-v2

Then open http://localhost:9999 in your web browser to test.

See Dockerfile for more details.

Troubleshooting the instance

When CoCalc is running you can shell in. To view installed packages:

docker-compose exec cocalc /bin/bash
pip3 list

If docker-compose up refuses to shutdown via CTRL+C, suspend via CTRL+Z and then do:

kill -SIGKILL %1 && fg

License

AGPL

About

CoCalc docker image for running a server for backtesting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages