Dockerized CoCalc environment for Trading Strategy algorithmic trading framework and protocol.
- 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
- Comes with Trading Strategy Python packages preinstalled
- User database is managed via CoCalc's built-in PostgreSQL server
- Any user can create their own CoCalc projects
- Users' ipynb files will be under
cocalc-data/$UID
, a folder per user
- Users' ipynb files will be under
- Use Caddy web server to protect the instance using HTTP Basic Auth
- Access log files with Caddy
To run this project you need:
- Docker
- Docker Compose
- 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
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
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
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.
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
AGPL