Skip to content

Commit

Permalink
Merge pull request #178 : New alpha release 0.0.12
Browse files Browse the repository at this point in the history
[Alpha version] Alpha version 0.0.12
  • Loading branch information
Herklos authored May 26, 2018
2 parents e297bf7 + 06ab618 commit 8688315
Show file tree
Hide file tree
Showing 161 changed files with 4,064 additions and 3,455 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ ENV/
# config
config/config.json

# modules
# evaluators
/.gitmodules
evaluator/.gitignore
**/Default/*.*
**/Advanced/*.*

# Specific config
Expand All @@ -118,3 +119,5 @@ config/evaluator_config.json
backtesting/collector/data/**

logs/matrix_history\.data

logs/CryptoBot\.log\.*
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ sudo: enabled
language: python
python:
- 3.6
notifications:
notifications:
slack: "cryptobotgroupe:vYDDCLRne52jPGVtN6cMiUkb"
email: false
install:
- ./docs/install/linux_installer.sh
- python -m pip install -r requirements.txt
- python -m pip install -r dev_requirements.txt
- sudo ./docs/install/linux_installer.sh
- pip3 install -r requirements.txt
- pip3 install -r dev_requirements.txt
- cp ./config/default_config.json ./config/config.json
- python3 start.py -p install all
script:
- pytest --cov-report term --cov=. tests/
- pytest --cov-report term --cov=. tests/unit_tests/


22 changes: 16 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
#Download base image ubuntu 16.04
FROM ubuntu:16.04
FROM python:3

# Update Ubuntu Software repository
# Update Software repository
RUN apt-get update
RUN apt install git -y

# Set up dev environment
RUN git clone https://github.com/Trading-Bot/CryptoBot
WORKDIR /bot
RUN git clone https://github.com/Trading-Bot/CryptoBot /bot/cryptobot
WORKDIR /bot/cryptobot
RUN git checkout dev

# install dependencies
RUN bash ./docs/install/linux_installer.sh

# configuration
RUN cp ./docs/install/config_test.json ./config/config.json
RUN cp ./config/default_config.json ./config/config.json
RUN cp ./config/default_evaluator_config.json ./config/evaluator_config.json

# python libs
RUN python3 -m pip install -r requirements.txt
RUN pip3 install -U setuptools
RUN pip3 install -r requirements.txt

# install evaluators
RUN python start.py -p install all

# entry point
ENTRYPOINT ["python"]
CMD ["start.py"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CryptoBot [![Codacy Badge](https://api.codacy.com/project/badge/Grade/c83a127c42ba4a389ca86a92fba7c53c)](https://www.codacy.com/app/paul.bouquet/CryptoBot?utm_source=github.com&utm_medium=referral&utm_content=Trading-Bot/CryptoBot&utm_campaign=Badge_Grade) [![Build Status](https://api.travis-ci.org/Trading-Bot/CryptoBot.svg?branch=dev)](https://travis-ci.org/Trading-Bot/CryptoBot) [![Coverage Status](https://coveralls.io/repos/github/Trading-Bot/CryptoBot/badge.svg?branch=dev)](https://coveralls.io/github/Trading-Bot/CryptoBot?branch=dev)
# CryptoBot [![Codacy Badge](https://api.codacy.com/project/badge/Grade/c83a127c42ba4a389ca86a92fba7c53c)](https://www.codacy.com/app/paul.bouquet/CryptoBot?utm_source=github.com&utm_medium=referral&utm_content=Trading-Bot/CryptoBot&utm_campaign=Badge_Grade) [![Build Status](https://api.travis-ci.org/Trading-Bot/CryptoBot.svg?branch=dev)](https://travis-ci.org/Trading-Bot/CryptoBot) [![Coverage Status](https://coveralls.io/repos/github/Trading-Bot/CryptoBot/badge.svg?branch=dev)](https://coveralls.io/github/Trading-Bot/CryptoBot?branch=dev) [![Code Factor](https://www.codefactor.io/repository/github/trading-bot/cryptobot/badge)](https://www.codefactor.io/repository/github/trading-bot/cryptobot/overview/dev) [![Build Status](https://semaphoreci.com/api/v1/herklos/cryptobot/branches/dev/shields_badge.svg)](https://semaphoreci.com/herklos/cryptobot) [![Codefresh build status]( https://g.codefresh.io/api/badges/build?repoOwner=Trading-Bot&repoName=CryptoBot&branch=dev&pipelineName=CryptoBot&accountName=herklos_marketplace&type=cf-1)]( https://g.codefresh.io/repositories/Trading-Bot/CryptoBot/builds?filter=trigger:build;branch:dev;service:5b06a377435197b088b1757a~CryptoBot)

#### Version 0.0.11-alpha ([changelog](https://github.com/Trading-Bot/CryptoBot/tree/alpha/docs/CHANGELOG.md))
#### Version 0.0.12-alpha ([changelog](https://github.com/Trading-Bot/CryptoBot/tree/dev/docs/CHANGELOG.md))

## Disclaimer
This software is for educational purposes only. Do not risk money which
Expand Down Expand Up @@ -51,11 +51,11 @@ python start.py --web --telegram
```bash
python start.py --data_collector
```
## Customize you CryptoBot !
## Customize your CryptoBot !
Information and examples on the [wiki](https://github.com/Trading-Bot/CryptoBot/wiki/Customize-your-CryptoBot)

## Screenshots
TODO
![Web Candles Screenshot](/docs/static/images/web_candle_screenshot.png)

## Testing
Use *pytest* command in the root folder :
Expand All @@ -64,7 +64,7 @@ pytest
```

## Changelog
See [changelog file](https://github.com/Trading-Bot/CryptoBot/tree/master/docs/CHANGELOG.md)
See [changelog file](https://github.com/Trading-Bot/CryptoBot/tree/alpha/docs/CHANGELOG.md)

## More
For more details see the [project wiki](https://github.com/Herklos-Bots/CryptoBot/wiki).
1 change: 0 additions & 1 deletion backtesting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ def __init__(bot):

def get_bot():
return bot_instance

3 changes: 2 additions & 1 deletion backtesting/backtesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from backtesting import get_bot
from config.cst import *
from tools.data_visualiser import DataVisualiser


class Backtesting:
Expand All @@ -15,6 +14,8 @@ def __init__(self, config, exchange_simulator):
self.logger = logging.getLogger(self.__class__.__name__)

def end(self):
self.logger.warning("Current backtesting version has a 2% precision error rate.")

for symbol in self.exchange_simulator.get_symbols():
self.report(symbol)

Expand Down
128 changes: 4 additions & 124 deletions backtesting/collector/data_collector.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import json
import logging
import os.path
import threading
import time

import ccxt

from backtesting.collector.exchange_collector import ExchangeDataCollector
from config.cst import *
from trading import Exchange
from trading.exchanges.exchange_manager import ExchangeManager


class DataCollector:
Expand All @@ -26,7 +23,8 @@ def create_exchange_data_collectors(self):
if exchange_class_string in available_exchanges:
exchange_type = getattr(ccxt, exchange_class_string)

exchange_inst = Exchange(self.config, exchange_type)
exchange_manager = ExchangeManager(self.config, exchange_type, is_simulated=False)
exchange_inst = exchange_manager.get_exchange()

exchange_data_collector = ExchangeDataCollector(self.config, exchange_inst)

Expand All @@ -46,121 +44,3 @@ def stop(self):
def join(self):
for data_collector in self.exchange_data_collectors_threads:
data_collector.join()


class DataCollectorParser:
@staticmethod
def parse(file):
if os.path.isfile(CONFIG_DATA_COLLECTOR_PATH + file):
with open(CONFIG_DATA_COLLECTOR_PATH + file) as file_to_parse:
file_content = json.loads(file_to_parse.read())
else:
with open(file) as file_to_parse:
file_content = json.loads(file_to_parse.read())
return file_content


class ExchangeDataCollector(threading.Thread):
Exchange_Data_Collector_File_Ext = ".data"

def __init__(self, config, exchange):
super().__init__()
self.config = config
self.exchange = exchange
self.symbols = self.exchange.get_traded_pairs()
self.keep_running = True
self.file = None
self._data_updated = False

self.file_names = {}
self.file_contents = {}
self.time_frame_update = {}

self.time_frames = []
for time_frame in TimeFrames:
if self.exchange.time_frame_exists(time_frame.value):
self.time_frames.append(time_frame)

self.logger = logging.getLogger(self.__class__.__name__)

def get_symbols(self):
return self.symbols

def get_time_frames(self):
return self.time_frames

def stop(self):
self.keep_running = False

def _set_file_name(self, symbol):
return "{0}_{1}_{2}{3}".format(self.exchange.get_name(),
symbol.replace("/", "_"),
time.strftime("%Y%m%d_%H%M%S"),
self.Exchange_Data_Collector_File_Ext)

@staticmethod
def get_file_name(file_name):
data = os.path.basename(file_name).split("_")
try:
exchange_name = data[0]
symbol = Exchange.merge_currencies(data[1], data[2])
timestamp = data[3] + data[4].replace(ExchangeDataCollector.Exchange_Data_Collector_File_Ext, "")
except KeyError:
exchange_name = None
symbol = None
timestamp = None

return exchange_name, symbol, timestamp

def _prepare_files(self):
for symbol in self.symbols:
self.file_contents[symbol] = {}
self.time_frame_update[symbol] = {}
self.file_names[symbol] = self._set_file_name(symbol)
for time_frame in self.time_frames:
self.file_contents[symbol][time_frame.value] = None

def _prepare(self):
self.logger.info("{0} prepare...".format(self.exchange.get_name()))
self._prepare_files()
for symbol in self.symbols:
for time_frame in self.time_frames:
# write all available data for this time frame
self.file_contents[symbol][time_frame.value] = self.exchange.get_symbol_prices(symbol,
time_frame,
limit=None,
data_frame=False)
self.time_frame_update[symbol][time_frame] = time.time()
self._update_file(symbol)

def _update_file(self, symbol):
with open(CONFIG_DATA_COLLECTOR_PATH + self.file_names[symbol], 'w') as json_file:
json.dump(self.file_contents[symbol], json_file)

def run(self):
self._prepare()
self.logger.info("{0} updating...".format(self.exchange.get_name()))
while self.keep_running:
now = time.time()

for symbol in self.symbols:
for time_frame in self.time_frames:
if now - self.time_frame_update[symbol][time_frame] >= TimeFramesMinutes[
time_frame] * MINUTE_TO_SECONDS:
result_df = self.exchange.get_symbol_prices(symbol,
time_frame,
limit=1,
data_frame=False)[0]

self.file_contents[symbol][time_frame.value].append(result_df)
self._data_updated = True
self.time_frame_update[symbol][time_frame] = now
self.logger.info(
"{0} ({2}) on {1} updated".format(symbol, self.exchange.get_name(), time_frame))

if self._data_updated:
self._update_file(symbol)
self._data_updated = False

final_sleep = DATA_COLLECTOR_REFRESHER_TIME - (time.time() - now)
time.sleep(final_sleep if final_sleep >= 0 else 0)
16 changes: 16 additions & 0 deletions backtesting/collector/data_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import json
import os

from config.cst import CONFIG_DATA_COLLECTOR_PATH


class DataCollectorParser:
@staticmethod
def parse(file):
if os.path.isfile(CONFIG_DATA_COLLECTOR_PATH + file):
with open(CONFIG_DATA_COLLECTOR_PATH + file) as file_to_parse:
file_content = json.loads(file_to_parse.read())
else:
with open(file) as file_to_parse:
file_content = json.loads(file_to_parse.read())
return file_content
Loading

0 comments on commit 8688315

Please sign in to comment.