Skip to content

Commit

Permalink
refacto(all): new version
Browse files Browse the repository at this point in the history
  • Loading branch information
cimourdain committed Nov 5, 2020
1 parent da0d818 commit 99e8635
Show file tree
Hide file tree
Showing 157 changed files with 9,409 additions and 5,485 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__
.vim

#### virtualenv
venv/*
Expand All @@ -17,7 +18,7 @@ dist/*

#### sample testing
data/*
reports/*
reports/
errors.log
samples/providers/database/migration.py

Expand All @@ -30,6 +31,7 @@ _build/*
### pytest
htmlcov/*
.coverage
.coveragerc
htmlcov/

# mypy
Expand Down
24 changes: 18 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
language: python

env:
- PYVERSION=py36
- PYVERSION=py37
- PYVERSION=py38
global:
- DOCKER_COMPOSE_VERSION=1.25.5
jobs:
- PYVERSION=3.6.10
- PYVERSION=3.7.8
- PYVERSION=3.8.3

services:
- docker

before_install:
- curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o ./docker-compose
- chmod +x ./docker-compose
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
# command to install dependencies
# before_install:
# - curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o ./docker-compose
# - chmod +x ./docker-compose
# - sudo mv docker-compose /usr/local/bin

install:
- make init

script:
- make ci
96 changes: 91 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,93 @@
ARG image_name
FROM python:$image_name
##################################################
#
# Base image
#
##################################################
ARG IMAGE_NAME
FROM python:${IMAGE_NAME} as base

RUN mkdir /estrade
WORKDIR /estrade
ARG POETRY_VERSION
ARG USER_NAME

RUN pip install poetry
##################################################
# ENVIRONMENT VARIABLES
##################################################
# python
ENV PYTHONUNBUFFERED=1 \
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
\
# pip
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100

# poetry
ENV POETRY_VERSION=${POETRY_VERSION} \
POETRY_HOME="/home/${USER_NAME}/.local/" \
POETRY_NO_INTERACTION=1

ENV PROJECT_DIRECTORY=/home/${USER_NAME}/app

##################################################
# UPDATE SYSTEM
##################################################
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
# deps for installing poetry
curl \
# deps for building python deps
build-essential \
# git for coveralls
git

##################################################
# CREATE USER (based on system user uid/gid)
##################################################
# create user
ARG USER_UID
ARG USER_GID

# Create group if not found in /etc/group
RUN if ! $(awk -F':' '{print $3}' /etc/group |grep -q ${USER_GID}) ; then groupadd -g ${USER_GID} appgroup; fi
# create user
RUN useradd -rm -g ${USER_GID} -G sudo -u ${USER_UID} ${USER_NAME}

USER ${USER_NAME}
WORKDIR ${PROJECT_DIRECTORY}


##################################################
# INSTALL & CONFIGURE POETRY
##################################################
# install poetry - respects $POETRY_VERSION & $POETRY_HOME
RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python


ENV VENV_PATH="/home/${USER_NAME}/.poetry_cache/virtualenvs"
ENV PATH="${POETRY_HOME}bin:${VENV_PATH}/bin:$PATH"

# configure poetry
RUN poetry config cache-dir "/home/${USER_NAME}/.poetry_cache/"
RUN poetry config virtualenvs.create true
RUN poetry config virtualenvs.in-project false
RUN poetry config virtualenvs.path "{cache-dir}/virtualenvs"



##################################################
# INSTALL PROJECT DEPENDENCIES (no dev)
##################################################
COPY poetry.lock pyproject.toml ./
RUN poetry install --no-dev


###################################################
##
## Developement image (used for dev/testing)
##
###################################################
FROM base as development

# install dev dependencies
RUN poetry install
85 changes: 67 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,83 @@
PYVERSION ?= py36
PROJECT_NAME = estrade
PYVERSION ?= 3.6.10
POETRY_VERSION ?= 1.0.9

DOCKER_CONTAINER_NAME = $(APP_NAME)-$(PYVERSION)
DOCKER_CMD_ENV_VARS = PROJECT_NAME=$(PROJECT_NAME) PYVERSION=$(PYVERSION)
DOCKER_RUN = $(DOCKER_CMD_ENV_VARS) docker-compose run --rm development
DOCKER_RUN_TESTS_COVERALLS = $(DOCKER_CMD_ENV_VARS) COVERALLS_REPO_TOKEN=$(COVERALLS_REPO_TOKEN) docker-compose run --rm development

BLACK_FOLDERS = $(PROJECT_NAME) tests
ISORT_FOLDERS = $(PROJECT_NAME) tests
FLAKE8_FOLDERS = $(PROJECT_NAME) tests
MYPY_FOLDERS = $(PROJECT_NAME)
RADON_FOLDERS = $(PROJECT_NAME)

PYTEST_OPTIONS = -x -vvv --cov=$(PROJECT_NAME)

DOCKER_RUN = docker-compose run --rm estrade-$(PYVERSION)

shell:
$(DOCKER_RUN) bash

init:
docker build --pull \
--rm \
-f Dockerfile \
-t "$(PROJECT_NAME)/dev:$(PYVERSION)" \
--target development \
--build-arg IMAGE_NAME="$(PYVERSION)-slim" \
--build-arg POETRY_VERSION=$(POETRY_VERSION) \
--build-arg PROJECT_NAME=$(PROJECT_NAME) \
--build-arg USER_NAME=$(PROJECT_NAME) \
--build-arg USER_UID=$(shell id -u $$USER) \
--build-arg USER_GID=$(shell id -g $$USER) \
.

# create container and intsall lib
$(DOCKER_CMD_ENV_VARS) docker-compose run development

test-integration:
$(DOCKER_RUN) bash -c "poetry run pytest tests/integration/ tests/doc/ $(PYTEST_OPTIONS)"

test-unit:
$(DOCKER_RUN) bash -c "poetry run pytest tests/unit/ $(PYTEST_OPTIONS)"

test:
$(DOCKER_RUN) make test-local
$(DOCKER_RUN) bash -c "poetry run pytest tests/ $(PYTEST_OPTIONS)"

test-report:
$(DOCKER_RUN) bash -c "poetry run pytest tests/unit/ $(PYTEST_OPTIONS) --cov-report html"

format:
$(DOCKER_RUN) bash -c "poetry run black $(BLACK_FOLDERS)"
$(DOCKER_RUN) bash -c "poetry run isort -rc $(ISORT_FOLDERS)"
$(DOCKER_RUN) bash -c "poetry run radon cc -a -nb $(RADON_FOLDERS)"

lint:
$(DOCKER_RUN) make lint-local
style:
$(DOCKER_RUN) bash -c "poetry run black $(BLACK_FOLDERS) --check --diff"
$(DOCKER_RUN) bash -c "poetry run flake8 $(FLAKE8_FOLDERS)"
$(DOCKER_RUN) bash -c "poetry run isort --check-only -rc $(ISORT_FOLDERS)"
$(DOCKER_RUN) bash -c "poetry run mypy $(MYPY_FOLDERS)"
$(DOCKER_RUN) bash -c "poetry run xenon --max-absolute B --max-modules A --max-average A $(RADON_FOLDERS)"

docs:
$(DOCKER_RUN) make docs-local
$(DOCKER_RUN) bash -c "poetry run mkdocs build --clean"

ci:
$(DOCKER_RUN) make ci-local
docs-serve:
$(DOCKER_RUN) bash -c "poetry run mkdocs serve"

readme-build:
$(DOCKER_RUN) bash -c "poetry run python scripts/pre.py render-readme"

init-local:
poetry install
readme-check:
$(DOCKER_RUN) bash -c "poetry run python scripts/pre.py render-readme --check-only=1"

test-local: init-local
poetry run pytest --cov=estrade/ tests/ -x

lint-local: init-local
poetry run flake8 estrade
poetry run black estrade -S --check --diff
ci: style test docs readme-check

docs-local: init-local
poetry run mkdocs build --clean
clean:
bash scripts/docker stop_running_containers estrade*
bash scripts/docker remove_containers estrade*
bash scripts/docker clean_images estrade*

ci-local: test-local lint-local docs-local
.PHONY: ci clean docs docs-serve format init readme-check shell style test-unit test-integration test-unit test test-report
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Estrade

[![Build Status](https://travis-ci.com/cimourdain/estrade.svg?branch=master)](https://travis-ci.com/cimourdain/estrade)
[![Documentation Status](https://readthedocs.org/projects/estrade/badge/?version=latest)](https://estrade.readthedocs.io/en/latest/?badge=latest)

[![Build Status](https://travis-ci.com/cimourdain/estrade.svg?branch=0.2a1)](https://travis-ci.com/cimourdain/estrade)
[![Documentation Status](https://readthedocs.org/projects/estrade/badge/?version=0.2a1)](https://estrade.readthedocs.io/en/0.2a1/?badge=0.2a1)
![python](https://badgen.net/badge/python/3.6,3.7,3.8?list=|)
![version](https://badgen.net/badge/version/0.2a1)
[![pypi](https://badgen.net/pypi/v/estrade)](https://pypi.org/project/estrade/)
[![black](https://badgen.net/badge/code%20style/black/000)](https://github.com/ambv/black)
[![mypy](https://badgen.net/badge/static%20typing/mypy/pink)](https://github.com/python/mypy)


# Estrade: Trading bot manager

Expand All @@ -19,7 +24,7 @@ Estrade focus on providing tools so you mainly focus on your strategy definition
- Trades result calculation
- Candle Graph building
- Indicators calculation
- Estrade allows you to define your strategies based on market events (new tick received, new candle created)
- Estrade allows you to define your strategies to run on every tick
- Estrade allows you to create your own data providers to generate ticks data and manage trades (open/close)
- Estrade allows you to create your own indicators
- Estrade allows you to create your own reporting
Expand All @@ -32,6 +37,4 @@ Estrade focus on providing tools so you mainly focus on your strategy definition

## Documentation

[Documentation](https://estrade.readthedocs.io/)


[Documentation](https://estrade.readthedocs.io/)
40 changes: 40 additions & 0 deletions README.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Estrade
{% if include_badges %}

[![Build Status](https://travis-ci.com/cimourdain/estrade.svg?branch={{git_branch}})](https://travis-ci.com/cimourdain/estrade)
[![Documentation Status](https://readthedocs.org/projects/estrade/badge/?version={{readthedocs_version}})](https://estrade.readthedocs.io/en/{{readthedocs_version}}/?badge={{readthedocs_version}})
![python](https://badgen.net/badge/python/3.6,3.7,3.8?list=|)
![version](https://badgen.net/badge/version/{{app_version}})
[![pypi](https://badgen.net/pypi/v/estrade)](https://pypi.org/project/estrade/)
[![black](https://badgen.net/badge/code%20style/black/000)](https://github.com/ambv/black)
[![mypy](https://badgen.net/badge/static%20typing/mypy/pink)](https://github.com/python/mypy)

{% endif %}
# Estrade: Trading bot manager

Estrade is a python library that allows you to easily backtest and run stock trading strategies.

Estrade focus on providing tools so you mainly focus on your strategy definition.

> **WARNING**: Estrade is still in an alpha state of developpement and very unmature. Do not use it for other purposes than testing.

## Features

- Estrade provides a **market environnement**, so you do not have to worry about
- Trades result calculation
- Candle Graph building
- Indicators calculation
- Estrade allows you to define your strategies to run on every tick
- Estrade allows you to create your own data providers to generate ticks data and manage trades (open/close)
- Estrade allows you to create your own indicators
- Estrade allows you to create your own reporting


## What Estrade does NOT provides

- **Data**: You have to define your own data provider (live or static)
- **Strategies**: Although some very basic (and useless) strategies are provided as examples in samples, Estrate does not provide any financially relevant strategy.

## Documentation

[Documentation](https://estrade.readthedocs.io/)
38 changes: 14 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
version: "2.1"
version: "2.3"

services:
estrade:
build:
context: .
volumes:
- ${PWD}:/estrade
estrade-py36:
extends:
service: estrade
build:
args:
image_name: "3.6.10-stretch"
estrade-py37:
extends:
service: estrade
build:
args:
image_name: "3.7.6-stretch"
estrade-py38:
extends:
service: estrade
build:
args:
image_name: "3.8.2-buster"
development:
# FIXME use the PROJECT_DIRECTORY env var
environment:
- PYTHONPATH=/home/${PROJECT_NAME}/app/
image: ${PROJECT_NAME}/dev:${PYVERSION}
user: ${PROJECT_NAME}
working_dir: /home/${PROJECT_NAME}/app/
container_name: ${PROJECT_NAME}-dev-${PYVERSION}
command: bash -c "poetry install"
ports:
- "8000:8000"
volumes:
- ${PWD}/:/home/${PROJECT_NAME}/app/

0 comments on commit 99e8635

Please sign in to comment.