Skip to content

Commit

Permalink
refactor(all): new version
Browse files Browse the repository at this point in the history
  • Loading branch information
cimourdain committed Nov 13, 2020
1 parent da0d818 commit afddc12
Show file tree
Hide file tree
Showing 172 changed files with 11,226 additions and 5,716 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
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
prune tests
prune docs
prune samples
prune samples
prune scripts
prune assets
89 changes: 71 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,87 @@
PYVERSION ?= py36
PROJECT_NAME = estrade
PYVERSION ?= 3.6.10
POETRY_VERSION ?= 1.0.9
TRAVIS_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BRANCH_NAME = $(TRAVIS_BRANCH)

DOCKER_CONTAINER_NAME = $(APP_NAME)-$(PYVERSION)
DOCKER_CMD_ENV_VARS = PROJECT_NAME=$(PROJECT_NAME) PYVERSION=$(PYVERSION) BRANCH_NAME=$(BRANCH_NAME)
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"


init-local:
poetry install
pre-commit:
$(DOCKER_RUN) bash -c "poetry run python scripts/pre-commit.py render-readme"
$(DOCKER_RUN) bash -c "poetry run python scripts/pre-commit.py docs-requirements"

test-local: init-local
poetry run pytest --cov=estrade/ tests/ -x
pre-commit-check:
$(DOCKER_RUN) bash -c "poetry run python scripts/pre-commit.py render-readme --check-only=1"
$(DOCKER_RUN) bash -c "poetry run python scripts/pre-commit.py docs-requirements --check-only=1"

lint-local: init-local
poetry run flake8 estrade
poetry run black estrade -S --check --diff
ci: style test docs pre-commit-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 pre-commit pre-commit-check shell style test-unit test-integration test-unit test test-report
70 changes: 48 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,63 @@
# 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)
[![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)

# Estrade: Trading bot manager

Estrade is a python library that allows you to easily backtest and run stock trading strategies.
<h1 align="center">
<a href="https://github.com/cimourdain/estrade"><img src="https://github.com/cimourdain/estrade/blob/master/assets/logo.png" alt="Estrade" width="399"/></a><br>
<a href="https://github.com/cimourdain/estrade">Estrade</a>
</h1>


<div align="center">
<a href="https://travis-ci.com/cimourdain/estrade">
<img src="https://travis-ci.com/cimourdain/estrade.svg?branch=master" alt="Build Status" />
</a>
<a href='https://estrade.readthedocs.io/en/latest'>
<img src='https://readthedocs.org/projects/estrade/badge/?version=latest' alt='Documentation Status' />
</a>
<img src="https://badgen.net/badge/python/3.6,3.7,3.8?list=|" alt="python version" />
<img src="https://badgen.net/badge/version/0.2a2" alt="current app version" />
<a href="https://pypi.org/project/estrade/">
<img src="https://badgen.net/pypi/v/estrade" alt="PyPi version" />
</a>
<img src="https://badgen.net/badge/coverage/96%25" alt="Coverage" />
<img src="https://badgen.net/badge/complexity/A%20%281.9210526315789473%29" alt="Complexity" />
<a href="https://gitlab.com/pycqa/flake8">
<img src="https://badgen.net/badge/lint/flake8/purple" alt="Lint" />
</a>
<a href="https://github.com/ambv/black">
<img src="https://badgen.net/badge/code%20style/black/000" alt="Code format" />
</a>
<a href="https://github.com/python/mypy">
<img src="https://badgen.net/badge/static%20typing/mypy/pink" alt="Typing" />
</a>
<img src="https://badgen.net/badge/licence/GNU-GPL3" alt="Licence" />
</div>


# Backtest and run your trading strategies

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

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 based on market events (new tick received, new candle created)
- 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
Estrade provides a **market environnement**, so you do not have to worry about
- Trades result calculation
- Indicators building & calculation (candle sets, graph indicators etc.)

Estrade is build to be extended so you can define your own:
- Strategies
- Tick provider (to feed your backtests and/or live trading)
- Indicators
- 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.
- **Strategies**: Although some very basic (and useless) strategies are provided as examples in samples, Estrade does not provide any financially relevant strategy.

## Documentation

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

## Documentation

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

0 comments on commit afddc12

Please sign in to comment.