From 15b31794cefa58c388615a688521347ba45eee6e Mon Sep 17 00:00:00 2001 From: Ramon Bastiaans Date: Fri, 2 Feb 2018 00:20:35 +0100 Subject: [PATCH] Update docs, fix stake currency exchange config and more generic backtest tests --- docs/configuration.md | 8 ++-- docs/pre-requisite.md | 14 +++++-- freqtrade/exchange/__init__.py | 1 + freqtrade/optimize/backtesting.py | 3 +- freqtrade/tests/optimize/test_backtesting.py | 42 +++++++++++--------- 5 files changed, 41 insertions(+), 27 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 5e3b15925..66db68488 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -24,7 +24,7 @@ The table below will list all configuration parameters. | `stoploss` | -0.10 | No | Value of the stoploss in percent used by the bot. More information below. If set, this parameter will override `stoploss` from your strategy file. | `unfilledtimeout` | 0 | No | How long (in minutes) the bot will wait for an unfilled order to complete, after which the order will be cancelled. | `bid_strategy.ask_last_balance` | 0.0 | Yes | Set the bidding price. More information below. -| `exchange.name` | bittrex | Yes | Name of the exchange class to use. +| `exchange.name` | bittrex | Yes | Name of the exchange class to use. Valid values are: `bittrex` or `binance` | `exchange.key` | key | No | API key to use for the exchange. Only required when you are in production mode. | `exchange.secret` | secret | No | API secret to use for the exchange. Only required when you are in production mode. | `exchange.pair_whitelist` | [] | No | List of currency to use by the bot. Can be overrided with `--dynamic-whitelist` param. @@ -94,7 +94,7 @@ creating trades. "dry_run": true, ``` -3. Remove your Bittrex API key (change them by fake api credentials) +3. Remove your exchange API key (change them by fake api credentials) ```json "exchange": { "name": "bittrex", @@ -120,7 +120,7 @@ you run it in production mode. "dry_run": false, ``` -3. Insert your Bittrex API key (change them by fake api keys) +3. Insert your exchange API key (change them by fake api keys) ```json "exchange": { "name": "bittrex", @@ -129,7 +129,7 @@ you run it in production mode. ... } ``` -If you have not your Bittrex API key yet, +If you have not your exchange API key yet, [see our tutorial](https://github.com/gcarq/freqtrade/blob/develop/docs/pre-requisite.md). diff --git a/docs/pre-requisite.md b/docs/pre-requisite.md index 931d12d38..cdcbd8bee 100644 --- a/docs/pre-requisite.md +++ b/docs/pre-requisite.md @@ -1,15 +1,23 @@ # Pre-requisite Before running your bot in production you will need to setup few -external API. In production mode, the bot required valid Bittrex API +external API. In production mode, the bot requires valid exchange API credentials and a Telegram bot (optional but recommended). ## Table of Contents -- [Setup your Bittrex account](#setup-your-bittrex-account) +- [Setup your Exchange account](#setup-your-exchange-account) - [Backtesting commands](#setup-your-telegram-bot) -## Setup your Bittrex account +## Setup your exchange account + +### Bittrex *To be completed, please feel free to complete this section.* +### Binance +- Go to: https://www.binance.com/userCenter/createApi.html +- Enter API key label: "freqtrade bot" and click "Create New Key" +- Check the "Enable Trading" checkbox +- Write down the API key and secret to put in: config.json + ## Setup your Telegram bot The only things you need is a working Telegram bot and its API token. Below we explain how to create your Telegram Bot, and how to get your diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 8d36c51e3..75081c52c 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -56,6 +56,7 @@ def init(config: dict) -> None: except KeyError: raise OperationalException('Exchange {} is not supported'.format(name)) + exchange_config['stake_currency'] = config['stake_currency'] _API = exchange_class(exchange_config) # Check if all pairs are available diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index d4a28b85c..370ed0280 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -107,13 +107,14 @@ def backtest(args) -> DataFrame: sell_profit_only: sell if profit only use_sell_signal: act on sell-signal stoploss: use stoploss + exchange_name: which exchange to use :return: DataFrame """ processed = args['processed'] max_open_trades = args.get('max_open_trades', 0) realistic = args.get('realistic', True) record = args.get('record', None) - exchange_name = args.get('exchange_name', 'bittrex') + exchange_name = args.get('exchange_name', None) records = [] trades = [] trade_count_lock: dict = {} diff --git a/freqtrade/tests/optimize/test_backtesting.py b/freqtrade/tests/optimize/test_backtesting.py index 0dd4f777a..be0285e27 100644 --- a/freqtrade/tests/optimize/test_backtesting.py +++ b/freqtrade/tests/optimize/test_backtesting.py @@ -5,7 +5,6 @@ import math from unittest.mock import MagicMock import pandas as pd from freqtrade import exchange, optimize -from freqtrade.exchange import Bittrex from freqtrade.optimize import preprocess from freqtrade.optimize.backtesting import backtest, generate_text_table, get_timeframe import freqtrade.optimize.backtesting as backtesting @@ -47,29 +46,31 @@ def test_get_timeframe(default_strategy): def test_backtest(default_strategy, default_conf, mocker): mocker.patch.dict('freqtrade.main._CONF', default_conf) - exchange._API = Bittrex({'key': '', 'secret': ''}) data = optimize.load_data(None, ticker_interval=5, pairs=['BTC_ETH']) data = trim_dictlist(data, -200) - results = backtest({'stake_amount': default_conf['stake_amount'], - 'processed': optimize.preprocess(data), - 'max_open_trades': 10, - 'realistic': True}) - assert not results.empty + for exch in exchange.Exchanges.__members__.keys(): + results = backtest({'stake_amount': default_conf['stake_amount'], + 'processed': optimize.preprocess(data), + 'max_open_trades': 10, + 'realistic': True, + 'exchange_name': exch.lower()}) + assert not results.empty def test_backtest_1min_ticker_interval(default_strategy, default_conf, mocker): mocker.patch.dict('freqtrade.main._CONF', default_conf) - exchange._API = Bittrex({'key': '', 'secret': ''}) # Run a backtesting for an exiting 5min ticker_interval data = optimize.load_data(None, ticker_interval=1, pairs=['BTC_UNITEST']) data = trim_dictlist(data, -200) - results = backtest({'stake_amount': default_conf['stake_amount'], - 'processed': optimize.preprocess(data), - 'max_open_trades': 1, - 'realistic': True}) - assert not results.empty + for exch in exchange.Exchanges.__members__.keys(): + results = backtest({'stake_amount': default_conf['stake_amount'], + 'processed': optimize.preprocess(data), + 'max_open_trades': 1, + 'realistic': True, + 'exchange_name': exch.lower()}) + assert not results.empty def load_data_test(what): @@ -122,7 +123,8 @@ def simple_backtest(config, contour, num_results): results = backtest({'stake_amount': config['stake_amount'], 'processed': processed, 'max_open_trades': 1, - 'realistic': True}) + 'realistic': True, + 'exchange_name': config['exchange']['name']}) # results :: assert len(results) == num_results @@ -135,11 +137,13 @@ def test_backtest2(default_conf, mocker, default_strategy): mocker.patch.dict('freqtrade.main._CONF', default_conf) data = optimize.load_data(None, ticker_interval=5, pairs=['BTC_ETH']) data = trim_dictlist(data, -200) - results = backtest({'stake_amount': default_conf['stake_amount'], - 'processed': optimize.preprocess(data), - 'max_open_trades': 10, - 'realistic': True}) - assert not results.empty + for exch in exchange.Exchanges.__members__.keys(): + results = backtest({'stake_amount': default_conf['stake_amount'], + 'processed': optimize.preprocess(data), + 'max_open_trades': 10, + 'realistic': True, + 'exchange_name': exch.lower()}) + assert not results.empty def test_processed(default_conf, mocker, default_strategy):