Skip to content

A collection of useful images to research with Zipline in CLI & GUI environments

License

Notifications You must be signed in to change notification settings

adegtyarev/docker-zipline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A collection of Zipline images

  • Base Docker image with Zipline algorithmic trading library
  • Zipline & TA-lib libraries
  • Zipline & additional development modules
  • Zipline in JupyterLab research environment

Software specification

Build Status

Image Layers & size
adegtyarev/zipline:latest zipline:python3
adegtyarev/zipline:talib zipline:python3-talib
adegtyarev/zipline:dev zipline:python3-dev
adegtyarev/zipline:jupyterlab zipline:python3-jupyterlab

Quick start

Create a new volume to store permanent data (usually referred to as $ZIPLINE_ROOT):

docker volume create --name zipline-root

Run zipline command in a Docker container:

docker run --rm --volume zipline-root:/zipline adegtyarev/zipline
Usage: zipline [OPTIONS] COMMAND [ARGS]...

  Top level zipline entry point.
...

Usage

Command line tool

This image basically intended to be a drop-in replacement to zipline command in a Docker environment:

export ZIPLINE_CMD="docker run --rm -t -v zipline:/zipline adegtyarev/zipline zipline"

So that you just replace zipline with $ZIPLINE_CMD:

$ZIPLINE_CMD ingest -b quantopian-quandl
Downloading Bundle: quantopian-quandl  [####################################]  100%
INFO: ...: Writing data to /zipline/data/quantopian-quandl/2018-01-31T12;27;19.433422.

Run an example trading algorithm:

$ZIPLINE_CMD run -s 2017-1-1 -e 2018-1-1 -b quantopian-quandl -f zipline/examples/buy_and_hold.py

Research notebook

The image with jupyterlab is built with Zipline and JupyterLab computational environment. To use the image you will need a permanent volume to store notebooks:

docker volume create --name zipline-notes

docker run --rm -p 80:8888 \
    -v zipline-root:/zipline \
    -v zipline-notes:/notes \
    adegtyarev/zipline:jupyterlab

This will start a Jupyter HTTP-server with Zipline installed and notes volume attached to a directory which eventually is a chroot directory for the server. You can then connect to port 80 using a web browser.

Secure notebook with HTTPS

It is easy to secure your research environment by using SSL certificates from Let's Encrypt. You will need a new volume to keep certificates:

docker volume create --name zipline-certs

Run the following dummy command to attach the new volume with pre-defined permissions on directories inside /etc/letsencrypt:

docker run --rm -v zipline-certs:/etc/letsencrypt adegtyarev/zipline:jupyterlab true

Make sure you have port 80/tcp open to the outside world so that LE could connect to run a verification procedure. Use an official image of certbot/certbot to obtain SSL certificate and a key:

SSL_HOSTNAME=example.com    # Set this to the public domain name
SSL_EMAIL=$USER@$HOSTNAME   # Email address for important notifications from LE

docker run --rm -p 80:80 \
    -v zipline-certs:/etc/letsencrypt \
    certbot/certbot certonly --standalone \
    -d $SSL_HOSTNAME --agree-tos -m $SSL_EMAIL --non-interactive

Adjust permissions for a private key file to be able to run under a normal user instead of root:

docker run --rm -u root \
    -v zipline-certs:/etc/letsencrypt \
    adegtyarev/zipline:jupyterlab \
    chmod o+r /etc/letsencrypt/archive/$SSL_HOSTNAME/privkey1.pem

A secured JupyterLab should be ready to start now:

docker run --rm -p 443:8888 \
    -e SSL_HOSTNAME=$SSL_HOSTNAME \
    -v zipline-root:/zipline \
    -v zipline-notes:/notes \
    -v zipline-certs:/etc/letsencrypt \
    adegtyarev/zipline:jupyterlab lab-ssl

Note that a port to open in a browser has changed from 80 (HTTP) to 443 (HTTPS).

Using as a base image

The image may also be used as a base Docker image for Zipline-related tools:

    FROM    adegtyarev/zipline:latest

    COPY    --chown=zipline:zipline . /src/zipline-cool-feature

    RUN     cd /src/zipline-cool-feature && \
            pip3 install \
                --no-cache-dir \
                --user \
                -r requirements.txt && \
            pip3 install \
                --no-cache-dir \
                --user \
                --editable \
                .

    ...     # continue with zipline & cool feature installed

Author

Alexey Degtyarev [email protected]

About

A collection of useful images to research with Zipline in CLI & GUI environments

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published