-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working to create a Docker image to work with Visual Studio Code (#181)
Working to create a Dev Container image to work with Visual Studio Code
- Loading branch information
Showing
18 changed files
with
279 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# | ||
# Build trade-executor as a Docker container for backtesting notebooks | ||
# | ||
|
||
# Use Microsoft specific base image | ||
ARG VARIANT="3.10-bullseye" | ||
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} | ||
|
||
# Passed from Github Actions | ||
ARG GIT_VERSION_TAG=unspecified | ||
ARG GIT_COMMIT_MESSAGE=unspecified | ||
ARG GIT_VERSION_HASH=unspecified | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 \ | ||
PYTHONUNBUFFERED 1 | ||
|
||
RUN apt-get update \ | ||
&& apt-get install curl gcc python3-docutils -y \ | ||
&& curl -sSL https://install.python-poetry.org | python - --version 1.3.1 | ||
|
||
ENV PATH="/root/.local/bin:$PATH" | ||
|
||
WORKDIR /trading-strategy | ||
|
||
# Set the version control information within Github Actions | ||
# if available | ||
RUN echo $GIT_VERSION_TAG > GIT_VERSION_TAG.txt | ||
RUN echo $GIT_COMMIT_MESSAGE > GIT_COMMIT_MESSAGE.txt | ||
RUN echo $GIT_VERSION_HASH > GIT_VERSION_HASH.txt | ||
|
||
# Copy package source code to the Docker image | ||
COPY . . | ||
|
||
# Install all Python dependencies using Poetry | ||
RUN poetry config virtualenvs.create false | ||
RUN poetry install --no-dev --no-interaction --no-ansi -E web-server -E execution -E qstrader | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
See [Notebook Docker Image documentation](../docs). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the | ||
// README at: https://github.com/devcontainers/templates/tree/main/src/python | ||
// The original blog post this is based at: https://marioscalas.medium.com/using-python-and-poetry-inside-a-dev-container-33c80bc5a22c | ||
{ | ||
"name": "Trading Strategy notebooks", | ||
|
||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"context": "..", | ||
"args": { | ||
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6 | ||
// Append -bullseye or -buster to pin to an OS version. | ||
// Use -bullseye variants on local on arm64/Apple Silicon. | ||
"VARIANT": "3.10-bullseye" | ||
} | ||
}, | ||
|
||
// Features to add to the dev container. More info: https://containers.dev/features. | ||
// "features": {}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "pip3 install --user -r requirements.txt", | ||
|
||
// Configure tool-specific properties. | ||
"extensions": [ | ||
"ms-python.python", | ||
"ms-python.vscode-pylance", | ||
"ms-toolsai.jupyter", | ||
"ms-toolsai.jupyter-keymap", | ||
"ms-toolsai.jupyter-renderers", | ||
"vscode-icons-team.vscode-icons", | ||
"lextudio.restructuredtext-pack", | ||
"trond-snekvik.simple-rst" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,8 @@ | |
|
||
## 0.2 | ||
|
||
- Breaking API changes | ||
|
||
- Breaking API changes | ||
|
||
|
||
asdasd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule trading-strategy
updated
16 files
+0 −23 | CHANGELOG.md | |
+1 −1 | README.md | |
+236 −253 | poetry.lock | |
+1 −1 | pyproject.toml | |
+0 −27 | tests/test_candle_universe.py | |
+1 −1 | tests/test_liquidity_universe.py | |
+0 −37 | tests/test_trading_data_availability.py | |
+11 −11 | tests/transport/test_cache.py | |
+3 −38 | tradingstrategy/candle.py | |
+3 −3 | tradingstrategy/charting/candle_chart.py | |
+2 −58 | tradingstrategy/client.py | |
+0 −11 | tradingstrategy/pair.py | |
+5 −64 | tradingstrategy/transport/cache.py | |
+2 −2 | tradingstrategy/transport/jsonl.py | |
+39 −35 | tradingstrategy/types.py | |
+1 −1 | tradingstrategy/utils/summarydataframe.py |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 131 additions & 0 deletions
131
docs/visual-studio-code-docker-dev-container-for-jupyter-notebooks.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# Visual Studio Code Dev Container for Jupyter Notebooks | ||
|
||
These instructions are for using [Trading Strategy](https://tradingstrategy.ai) | ||
backtesting and decentralised finance research environment in [Microsoft Visual Studio Code](https://code.visualstudio.com/). | ||
|
||
 | ||
|
||
[Microsoft Visual Studio Code](https://code.visualstudio.com/), a popular editor for Jupyter notebooks. | ||
[Dev Container](https://code.visualstudio.com/docs/devcontainers/containers) is a Visual Studio Code | ||
feature to easily distribute ready-made development environments to users. | ||
Dev Containers work on any operating system (Windows, macOS, Linux). | ||
Dev Container users a special `.devcontainer` configuration format in supported Git repositories. | ||
|
||
The Trading Strategy Dev Container is a pre-made development environment | ||
for quant finance research in decentralised finance. | ||
|
||
It combines | ||
|
||
- Trading Strategy framework and libraries | ||
- Ready set up Python environment with correct Python interpreter | ||
- Visual Studio Code plugins and settings needed to run and | ||
edit these notebooks | ||
- Example notebooks and documentation notebooks ready in the file explorer | ||
- The Docker image can be re-used for other Python editors and purposes; | ||
in this documentation we focus on Visual Studio Code as it is the easiest | ||
- Apple Silicon (Macbook M1) friendliness | ||
|
||
## Prerequisites | ||
|
||
- Existing basic knowledge of Python programming, Jupyter notebooks and data science and trading | ||
- The set up will download 2 GB+ data, so we do not recommend to try this | ||
over a mobile connection | ||
|
||
## Setting up Visual Studio Code | ||
|
||
- [Install Visual Studio code](https://code.visualstudio.com/) | ||
- [Install Docker desktop](https://www.docker.com/products/docker-desktop/) | ||
- Install the [Dev Containers extension](https://code.visualstudio.com/docs/devcontainers/containers) | ||
within Visual Studio Code | ||
|
||
## Checkout the repository from Github | ||
|
||
After you are done with the local software installation steps above, | ||
you can check out the repository using Visual Studio Code. | ||
|
||
Press `F1` to bring up the command palette (`fn` + `F1` on Macs) | ||
|
||
Choose `Clone from Github`. | ||
|
||
Paste in the repository name: ``` | ||
|
||
## Start the Dev Container | ||
|
||
When `trade-executor` project opens you get a pop up *Reopen in container*. | ||
|
||
 | ||
|
||
Click it and Visual Studio Code will build the development environment for you. | ||
This will take 2 - 15 minutes depening on your Internet connection speed. | ||
|
||
You can also manually execute this action by pressing `F1` to bring up the command palette (`fn` + `F1` on Macs) | ||
and finding *Reopen in container* action. | ||
|
||
## Using the container | ||
|
||
After the container is started, open Terminal in Visual Studio Code (*View > Terminal*). | ||
|
||
Paste in the following command: | ||
|
||
```shell | ||
scripts/set-up-examples.sh | ||
``` | ||
|
||
This will create `examples` folder and copies all notebooks [from the documentation](https://tradingstrategy.ai/docs/) | ||
there. | ||
|
||
### Running an example | ||
|
||
Here are short instructions how to edit and run notebooks. | ||
|
||
Open `examples/synthetic-ema.ipynb` | ||
|
||
Edit the backtesting period in the first code cell: | ||
|
||
 | ||
|
||
|
||
Set to | ||
|
||
```python | ||
start_at = datetime.datetime(2022, 1, 1) | ||
end_at = datetime.datetime(2023, 1, 1) | ||
``` | ||
|
||
Then press Run all: | ||
|
||
 | ||
|
||
Now scroll to the bottom of the notebook and see you have updated results for 2022 - 2023: | ||
|
||
 | ||
|
||
### Using command line Python | ||
|
||
If you open Visual Studio Code terminal and run `python` command | ||
it comes with Trading Strategy packages installed. | ||
|
||
 | ||
|
||
## Troubleshooting | ||
|
||
### No space left on device error | ||
|
||
Make sure you clean up old Docker images, containers and volumes in your Docker for Desktop | ||
to reclaim disk apce. | ||
|
||
### Manual build | ||
|
||
Building the Docker image by hand: | ||
|
||
```shell | ||
docker build --file .devcontainer/Dockerfile . | ||
``` | ||
|
||
|
||
## Further reading | ||
|
||
- https://code.visualstudio.com/docs/devcontainers/containers | ||
- https://stackoverflow.com/questions/63998873/vscode-how-to-run-a-jupyter-notebook-in-a-docker-container-over-a-remote-serve | ||
- https://keestalkstech.com/2022/08/jupyter-notebooks-vscode-dev-container-with-puppeteer-support/ | ||
- https://marioscalas.medium.com/using-python-and-poetry-inside-a-dev-container-33c80bc5a22c |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Example notebooks | ||
|
||
This folder will contain example notebooks to be used with | ||
[Visual Studio Code Dev Container](../docs/visual-studio-code-docker-dev-container-for-jupyter-notebooks.md). | ||
|
||
Follow the Dev Container instructions to get the examples. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# | ||
# Build trade-executor as a Docker container for backtesting notebooks | ||
# | ||
# See https://stackoverflow.com/a/71786211/315168 for the recipe | ||
# | ||
|
||
# See official Python Docker images | ||
# https://hub.docker.com/_/python/ | ||
FROM python:3.10.9-slim-buster | ||
|
||
# FROM python:3.11.1-slim-buster | ||
|
||
# Passed from Github Actions | ||
ARG GIT_VERSION_TAG=unspecified | ||
ARG GIT_COMMIT_MESSAGE=unspecified | ||
ARG GIT_VERSION_HASH=unspecified | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 \ | ||
PYTHONUNBUFFERED 1 | ||
|
||
RUN apt-get update \ | ||
&& apt-get install curl gcc -y \ | ||
&& curl -sSL https://install.python-poetry.org | python - --version 1.3.1 | ||
|
||
ENV PATH="/root/.local/bin:$PATH" | ||
|
||
WORKDIR /trading-strategy | ||
|
||
# Set in Github Actions | ||
RUN echo $GIT_VERSION_TAG > GIT_VERSION_TAG.txt | ||
RUN echo $GIT_COMMIT_MESSAGE > GIT_COMMIT_MESSAGE.txt | ||
RUN echo $GIT_VERSION_HASH > GIT_VERSION_HASH.txt | ||
|
||
# package source code | ||
COPY . . | ||
|
||
RUN poetry config virtualenvs.create false | ||
RUN poetry install --no-dev --no-interaction --no-ansi -E web-server -E execution -E qstrader | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
# | ||
# This script will set up an examples folder for notebooks. | ||
# | ||
# It combines notebooks from tradd-executor and docs repos | ||
# | ||
|
||
set -e | ||
|
||
find ./notebooks -iname "*.ipynb" -exec cp {} examples \; | ||
git clone https://github.com/tradingstrategy-ai/docs.git /tmp/docs | ||
find /tmp/docs -iname "*.ipynb" -exec cp {} examples \; |