Skip to content

Commit

Permalink
feat(import): imported base code
Browse files Browse the repository at this point in the history
  • Loading branch information
Lluis Santos committed Nov 5, 2020
0 parents commit 34723ed
Show file tree
Hide file tree
Showing 945 changed files with 351,580 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# IDE
.idea

# Python
**/venv
**.egg-info
**.pyc
.coverage

# github
.github
27 changes: 27 additions & 0 deletions .github/workflows/coverage-80.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Coverage > 80%

on:
push:
pull_request:


jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Obtaining the code
uses: actions/checkout@v1

- name: Build dev
run: make dev

- name: Check coverage
env:
MIN_COV: 80
run: |
cov=$(make coverage | grep ^TOTAL | sed -E 's/.* ([0-9]+)%$/\1/')
echo "Overall coverage: $cov%"
if (( $cov < $MIN_COV )); then
echo "FAIL - Minimum coverage $MIN_COV% not reached"
exit 1
fi
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# IDE
.idea

# Python
venv
**.egg-info
**.pyc
.coverage
115 changes: 115 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.1.0](https://github.com/QbitArtifacts/backtestex/compare/v1.0.0...v1.1.0) (2020-06-03)


### Bug Fixes

* **bitmex_backtest:** implemented compatibility with no funding feeder fixes [#66](https://github.com/QbitArtifacts/backtestex/issues/66) ([c60f3bf](https://github.com/QbitArtifacts/backtestex/commit/c60f3bf))
* **bitmex_feeder:** added reconnect when websocket throws timeout ([6dedb78](https://github.com/QbitArtifacts/backtestex/commit/6dedb78))
* **bitmex_testex:** update avg_order_price ([c4db4d0](https://github.com/QbitArtifacts/backtestex/commit/c4db4d0))
* **bridge_exchange:** removed comments ([3b7ad25](https://github.com/QbitArtifacts/backtestex/commit/3b7ad25))
* **dependencies:** added websocket dependency and updated the rest of ones ([f9d0d1a](https://github.com/QbitArtifacts/backtestex/commit/f9d0d1a))
* **plot_server:** delete comments ([cf26b48](https://github.com/QbitArtifacts/backtestex/commit/cf26b48))
* **plot_server:** minor renames ([de5eb21](https://github.com/QbitArtifacts/backtestex/commit/de5eb21))
* **runner:** fixed bug with prod configuration ([6c3d1dc](https://github.com/QbitArtifacts/backtestex/commit/6c3d1dc))
* **testex:** add symbol on Book events (ccxt compatibility) ([19d4c7f](https://github.com/QbitArtifacts/backtestex/commit/19d4c7f))
* **testing:** checked market order against status filled instead of status closed ([5f297e4](https://github.com/QbitArtifacts/backtestex/commit/5f297e4))
* dummy ([55e8abc](https://github.com/QbitArtifacts/backtestex/commit/55e8abc))
* makefike ([5902788](https://github.com/QbitArtifacts/backtestex/commit/5902788))
* separated build and coverage ([6822a96](https://github.com/QbitArtifacts/backtestex/commit/6822a96))
* tests ([652310a](https://github.com/QbitArtifacts/backtestex/commit/652310a))
* updated ci ([b94563a](https://github.com/QbitArtifacts/backtestex/commit/b94563a))
* updated ci ([ab315ca](https://github.com/QbitArtifacts/backtestex/commit/ab315ca))
* updated gh wf ([17b3567](https://github.com/QbitArtifacts/backtestex/commit/17b3567))
* updated makefile ([0f62d36](https://github.com/QbitArtifacts/backtestex/commit/0f62d36))
* updated makefile ([a883924](https://github.com/QbitArtifacts/backtestex/commit/a883924))
* updated reqs ([5ac7746](https://github.com/QbitArtifacts/backtestex/commit/5ac7746))
* **bitmex_backtest:** fix liquidation price formula ([fad7e19](https://github.com/QbitArtifacts/backtestex/commit/fad7e19))
* **bridge:** fixed sent information to plotter from bridge ([114adb7](https://github.com/QbitArtifacts/backtestex/commit/114adb7))
* **feeder:** fixed bug when period starts and ends at the same month ([0b4afdb](https://github.com/QbitArtifacts/backtestex/commit/0b4afdb))
* **funding:** renamed event funding_rate to funding ([379ff8a](https://github.com/QbitArtifacts/backtestex/commit/379ff8a))
* **gitignore:** ignored python cache files (*.pyc) ([0b69c30](https://github.com/QbitArtifacts/backtestex/commit/0b69c30))
* **PR:** fix for PR comments ([ecb3e37](https://github.com/QbitArtifacts/backtestex/commit/ecb3e37))
* **testex:** execute market orders match in time ([152bc88](https://github.com/QbitArtifacts/backtestex/commit/152bc88))
* **testex:** fixed tooltip info sent to plotter from testex ([1301d7e](https://github.com/QbitArtifacts/backtestex/commit/1301d7e))


### Features

* **bitmex_backtest:** implemented liquidation price ([9e579f6](https://github.com/QbitArtifacts/backtestex/commit/9e579f6))
* **BitmexBacktest:** implemented founding fees ([f6ce2fe](https://github.com/QbitArtifacts/backtestex/commit/f6ce2fe))
* **BitmexBacktest:** implemented markPrice fixes [#59](https://github.com/QbitArtifacts/backtestex/issues/59) ([d7419a9](https://github.com/QbitArtifacts/backtestex/commit/d7419a9))
* **ci:** added test and code coverage execution and github actions ([ccc3f13](https://github.com/QbitArtifacts/backtestex/commit/ccc3f13))
* **config:** added funding information to testex and bitmex_backtest ([d97dfe8](https://github.com/QbitArtifacts/backtestex/commit/d97dfe8))
* **config:** implemented outlier filter and added default values for fees ([20ada36](https://github.com/QbitArtifacts/backtestex/commit/20ada36))
* **founding_backtest_feeder:** implemented founding_backtest_feeder to send founding_rate events each time the founding_rate changes ([9bd0565](https://github.com/QbitArtifacts/backtestex/commit/9bd0565))
* **index:** added 5 min zoom, select zoom from-to(days), manual zoom and resize on charts division ([4061cb6](https://github.com/QbitArtifacts/backtestex/commit/4061cb6))
* **injector:** implemented default values ([1205e4c](https://github.com/QbitArtifacts/backtestex/commit/1205e4c)), closes [#51](https://github.com/QbitArtifacts/backtestex/issues/51)
* **kraken_feeder:** create kraken feeder class ([02f0f2a](https://github.com/QbitArtifacts/backtestex/commit/02f0f2a))
* **kraken_feeder:** filter orders by execution time (10 seg): ([95f158d](https://github.com/QbitArtifacts/backtestex/commit/95f158d))
* **kraken_feeder:** implemented events: ([703eefc](https://github.com/QbitArtifacts/backtestex/commit/703eefc))
* **kraken_feeder:** minor changes ([8745615](https://github.com/QbitArtifacts/backtestex/commit/8745615))
* **live_balance:** implemented filtered live chart (Real time balance) closes [#68](https://github.com/QbitArtifacts/backtestex/issues/68) ([25f8410](https://github.com/QbitArtifacts/backtestex/commit/25f8410))
* **live_plot:** run PlotServer in highstock_plotter.py on other process and added --live_plot option in CLI. fixes [#72](https://github.com/QbitArtifacts/backtestex/issues/72) ([1395f87](https://github.com/QbitArtifacts/backtestex/commit/1395f87))
* **plot_server:** created PlotServer class ([6aa9c63](https://github.com/QbitArtifacts/backtestex/commit/6aa9c63))
* **plot_server:** implementer websocket server to serve plot data to browser on real time ([cc6ca8b](https://github.com/QbitArtifacts/backtestex/commit/cc6ca8b))
* **plotter:** fixed imports in plotly plotter ([e692a80](https://github.com/QbitArtifacts/backtestex/commit/e692a80))
* **tests:** added balance and fees tests ([d14bca0](https://github.com/QbitArtifacts/backtestex/commit/d14bca0))
* **tests:** implemented first tests on tradingkit ([d4dbf08](https://github.com/QbitArtifacts/backtestex/commit/d4dbf08))



## 1.0.0 (2020-05-09)


### Bug Fixes

* **bitmex_feeder:** fixed order status, it must be lowercase ([e96f24b](https://github.com/QbitArtifacts/backtestex/commit/e96f24b))
* **bridge:** implemented is_inverse method to see if market liquidations are inversed (liquidates in base asset instead of quote asset) ([89b5688](https://github.com/QbitArtifacts/backtestex/commit/89b5688))
* **bridge:** removed error hidings in bridge exchange ([bf94db5](https://github.com/QbitArtifacts/backtestex/commit/bf94db5))
* **ccxt:** fixed bad secret name ([99a8951](https://github.com/QbitArtifacts/backtestex/commit/99a8951))
* **cli:** cli bugfix ([6b3bb63](https://github.com/QbitArtifacts/backtestex/commit/6b3bb63))
* **env:** fixed bug with loading environment ([8e2d207](https://github.com/QbitArtifacts/backtestex/commit/8e2d207))
* **fetcher:** fixed unchecked array access ([3f7e38f](https://github.com/QbitArtifacts/backtestex/commit/3f7e38f))
* **martingale:** fixed more bugs ([f9a0b9d](https://github.com/QbitArtifacts/backtestex/commit/f9a0b9d))
* **orders:** fixes [#9](https://github.com/QbitArtifacts/backtestex/issues/9) ([437d6ca](https://github.com/QbitArtifacts/backtestex/commit/437d6ca))
* **plotter:** changed order date parsing mode to iso ([a24fa92](https://github.com/QbitArtifacts/backtestex/commit/a24fa92))
* **plotter:** fixed automatic open browser when plot ([4bc4d7b](https://github.com/QbitArtifacts/backtestex/commit/4bc4d7b))
* **refactor:** finished refactor for martingale and fixed bug in injector with cache ([8b560ff](https://github.com/QbitArtifacts/backtestex/commit/8b560ff))
* **testex:** instant closed order when creating market orders ([524028d](https://github.com/QbitArtifacts/backtestex/commit/524028d)), closes [#45](https://github.com/QbitArtifacts/backtestex/issues/45)
* **websocket:** added monkey patch to throw exceptions when happens ([2f365af](https://github.com/QbitArtifacts/backtestex/commit/2f365af))
* changed feeder_listeners to feeder_adapters ([6717550](https://github.com/QbitArtifacts/backtestex/commit/6717550))


### Features

* **bridge:** added method to know which is the asset amount to create orders for an specific symbol ([cb32763](https://github.com/QbitArtifacts/backtestex/commit/cb32763))
* **cli:** added log verbosity control to cli ([b8cd933](https://github.com/QbitArtifacts/backtestex/commit/b8cd933))
* **cli:** implemented cli ([fe9c94c](https://github.com/QbitArtifacts/backtestex/commit/fe9c94c)), closes [#16](https://github.com/QbitArtifacts/backtestex/issues/16)
* **cli:** refactored feeders and fetchers ([a1269f0](https://github.com/QbitArtifacts/backtestex/commit/a1269f0))
* **config:** allowed calls in config definition ([f08cb55](https://github.com/QbitArtifacts/backtestex/commit/f08cb55))
* **config:** changed config to strategies and updated cli ([120efaa](https://github.com/QbitArtifacts/backtestex/commit/120efaa)), closes [#41](https://github.com/QbitArtifacts/backtestex/issues/41)
* **config:** implemented adapters to allow adapte trades ([334fe96](https://github.com/QbitArtifacts/backtestex/commit/334fe96))
* **config:** loading environment env files ([639d4aa](https://github.com/QbitArtifacts/backtestex/commit/639d4aa))
* **dep.injection:** implemented injector to load from config.json easier ([d0b572b](https://github.com/QbitArtifacts/backtestex/commit/d0b572b))
* **env:** fixes [#38](https://github.com/QbitArtifacts/backtestex/issues/38) ([b6f0821](https://github.com/QbitArtifacts/backtestex/commit/b6f0821))
* **gitignore:** added var/cache to gitignore ([fc3cc24](https://github.com/QbitArtifacts/backtestex/commit/fc3cc24))
* **importer:** added importer to cli and refactor ([4d32e3a](https://github.com/QbitArtifacts/backtestex/commit/4d32e3a))
* **injector:** new config injector operative ([674058a](https://github.com/QbitArtifacts/backtestex/commit/674058a))
* **installer:** implemented installer ([98204f3](https://github.com/QbitArtifacts/backtestex/commit/98204f3)), closes [#3](https://github.com/QbitArtifacts/backtestex/issues/3)
* **logs:** added deep level to martingale strategy warnings ([cd93942](https://github.com/QbitArtifacts/backtestex/commit/cd93942))
* **martingale:** fixed bugs in martingale with risk checks enabled ([f7bebc4](https://github.com/QbitArtifacts/backtestex/commit/f7bebc4))
* **martingale:** refactored and improved martingale ([f9f2623](https://github.com/QbitArtifacts/backtestex/commit/f9f2623))
* **martingale:** tunning parameters ([8ce66b3](https://github.com/QbitArtifacts/backtestex/commit/8ce66b3))
* **plotter:** stopping server after 3 seconds of serve ([ee60016](https://github.com/QbitArtifacts/backtestex/commit/ee60016))
* **plotting:** plotted equity ([9c7b119](https://github.com/QbitArtifacts/backtestex/commit/9c7b119))
* **refactor:** added super-package btx ([8682a91](https://github.com/QbitArtifacts/backtestex/commit/8682a91))
* **refactor:** another big refactor in cli and all package imports ([3d9a21a](https://github.com/QbitArtifacts/backtestex/commit/3d9a21a))
* **refactor:** implemented auto test and refactored loaders ([0dd3240](https://github.com/QbitArtifacts/backtestex/commit/0dd3240))
* (double martingale) changed logging to debug ([6af2fd4](https://github.com/QbitArtifacts/backtestex/commit/6af2fd4))
* **refactor:** refactored plotters ([cbb6335](https://github.com/QbitArtifacts/backtestex/commit/cbb6335))
* **refactor:** refactored plotters ([2f38acb](https://github.com/QbitArtifacts/backtestex/commit/2f38acb))
* big refactor to allow strategies work with both backtest and real envs ([cae5a48](https://github.com/QbitArtifacts/backtestex/commit/cae5a48))
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 LogicTraders

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

all: build test coverage

version:
docker run --rm -it -v $(PWD):/app detouched/standard-version
build:
docker build . -f docker/prod/Dockerfile -t qbitartifacts/tradingkit

run:
docker run -v $(PWD):/strategy qbitartifacts/tradingkit run /strategy

dev:
docker build . -f docker/dev/Dockerfile -t qbitartifacts/tradingkit:dev

shell: dev
docker run -it -v $(PWD):/tradingkit qbitartifacts/tradingkit:dev bash

test: dev
docker run -v $(PWD):/tradingkit qbitartifacts/tradingkit:dev python3 -m unittest

coverage: dev
docker run -v $(PWD):/tradingkit qbitartifacts/tradingkit:dev bash -c "coverage3 run --source=src -m unittest && coverage3 report"
137 changes: 137 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# TradingKit
This file shows the basic usage for TradingKit, for more docs, please see the [Wiki](https://github.com/QbitArtifacts/tradingkit/wiki)

![stable](https://img.shields.io/badge/stable-1.1.0-blue)
![coverage](https://img.shields.io/badge/coverage-37%25-orange)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)

## Requirements
- python 3.7+
- python virtual environment (venv)
- pip

## Installation
the recommended (and unique supported way) to install TradingKit si via **pip**.

### Instructions for unix
```bash
# clone repo
git clone git@github.com:qbitartifacts/tradingkit.git
cd tradingkit

# create and activate virtual environment (venv)
python -m venv venv
source venv/bin/activate

# install the package for development
pip install -e .
```

### Instructions for windows
```bash
# TODO...
```

## Creating strategies
In order to create new strategies you need **5 steps**
### Create separate project
Create new python3.7+ project, no need to do anymore in this step.

### Install virtualenv and dependencies
To do this step need to install previously TradingKit with the installation steps described above.
```bash
cd my_project
python -m venv venv
source venv/bin/activate
pip install ccxt
pip install -e ../tradingkit
```

### Creating strategy class
create a class extending from `tradingkit.strategy.strategy.Strategy`
```python
# File my_project/my_strategy.py
import logging
import ccxt.Exchange

from tradingkit.pubsub.event.trade import Trade
from tradingkit.pubsub.event.book import Book
from tradingkit.pubsub.event.order import Order
from tradingkit.pubsub.core.event import Event
from tradingkit.strategy.strategy import Strategy


class MyStrategy(Strategy):

def __init__(self, exchange: Exchange, config):
super().__init__(exchange, config)
# do whatever initializations you need

def on_event(self, event: Event):
if isinstance(event, Trade):
logging.info("Order event happened!")
# do whatever you need with the exchange
self.exchange.create_order(...)
if isinstance(event, Book):
logging.info("Book event happened!")
# do whatever you need with the exchange
self.exchange.create_order(...)
if isinstance(event, Order):
logging.info("Order event happened!")
# do whatever you need with the exchange
self.exchange.create_order(...)
```
### Create main config file
create `system/config.json` file
```json
{
"strategy": {
"class": "my_strategy.MyStrategy",
"arguments": ["@bridge", "@config"]
},
"config": {
"symbol": "%env(SYMBOL)%"
}
}
```
create `.env` file to add some env vars
```bash
# File .env
SYMBOL=BTC/EUR
```


### Configure dev environment
create `system/config.dev.json` file
```json
{
"exchange": "@testex",
"feeder": "@backtest_feeder"
}
```

### Configure live environment
create `system/config.live.json` file
```json
{
"exchange": "@kraken",
"feeder": "@kraken_feeder"
}
```
create `.env.live.local` file to add your bitmex credentials credentials
```bash
# File .env.live.local
KRAKEN_KEY=xxxxxxxxxxxxxxxxxxx
KRAKEN_SECRET=yyyyyyyyyyyyyyyyyyyy
```


### Run dev (backtest)
```
tk run -e dev -y 2020 -m 1 --plot
```

### Run live
```
tk run -e live --plot
```
18 changes: 18 additions & 0 deletions docker/dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM debian:buster
ENV DEBIAN_FRONTEND noninteractive
RUN apt update && apt install -y \
python3 \
python3-pip \
python3-venv \
wget

RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz -O - | tar xz
WORKDIR /ta-lib
RUN ./configure --prefix=/usr && make && make install

VOLUME /venv

WORKDIR /tradingkit

ENTRYPOINT ["docker/dev/docker-entrypoint.sh"]
CMD ["tk", "--help"]
13 changes: 13 additions & 0 deletions docker/dev/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e

if ! test -f /venv/bin/python;then
python3 -m venv /venv
source /venv/bin/activate
pip install -e .
else
source /venv/bin/activate
fi

exec "$@"

Loading

0 comments on commit 34723ed

Please sign in to comment.