Update docs, fix stake currency exchange config and more generic backtest tests

This commit is contained in:
Ramon Bastiaans 2018-02-02 00:20:35 +01:00
parent f371fba04b
commit 15b31794ce
5 changed files with 41 additions and 27 deletions

View File

@ -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. | `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. | `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. | `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.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.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. | `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, "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 ```json
"exchange": { "exchange": {
"name": "bittrex", "name": "bittrex",
@ -120,7 +120,7 @@ you run it in production mode.
"dry_run": false, "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 ```json
"exchange": { "exchange": {
"name": "bittrex", "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). [see our tutorial](https://github.com/gcarq/freqtrade/blob/develop/docs/pre-requisite.md).

View File

@ -1,15 +1,23 @@
# Pre-requisite # Pre-requisite
Before running your bot in production you will need to setup few 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). credentials and a Telegram bot (optional but recommended).
## Table of Contents ## 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) - [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.* *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 ## Setup your Telegram bot
The only things you need is a working Telegram bot and its API token. 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 Below we explain how to create your Telegram Bot, and how to get your

View File

@ -56,6 +56,7 @@ def init(config: dict) -> None:
except KeyError: except KeyError:
raise OperationalException('Exchange {} is not supported'.format(name)) raise OperationalException('Exchange {} is not supported'.format(name))
exchange_config['stake_currency'] = config['stake_currency']
_API = exchange_class(exchange_config) _API = exchange_class(exchange_config)
# Check if all pairs are available # Check if all pairs are available

View File

@ -107,13 +107,14 @@ def backtest(args) -> DataFrame:
sell_profit_only: sell if profit only sell_profit_only: sell if profit only
use_sell_signal: act on sell-signal use_sell_signal: act on sell-signal
stoploss: use stoploss stoploss: use stoploss
exchange_name: which exchange to use
:return: DataFrame :return: DataFrame
""" """
processed = args['processed'] processed = args['processed']
max_open_trades = args.get('max_open_trades', 0) max_open_trades = args.get('max_open_trades', 0)
realistic = args.get('realistic', True) realistic = args.get('realistic', True)
record = args.get('record', None) record = args.get('record', None)
exchange_name = args.get('exchange_name', 'bittrex') exchange_name = args.get('exchange_name', None)
records = [] records = []
trades = [] trades = []
trade_count_lock: dict = {} trade_count_lock: dict = {}

View File

@ -5,7 +5,6 @@ import math
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pandas as pd import pandas as pd
from freqtrade import exchange, optimize from freqtrade import exchange, optimize
from freqtrade.exchange import Bittrex
from freqtrade.optimize import preprocess from freqtrade.optimize import preprocess
from freqtrade.optimize.backtesting import backtest, generate_text_table, get_timeframe from freqtrade.optimize.backtesting import backtest, generate_text_table, get_timeframe
import freqtrade.optimize.backtesting as backtesting import freqtrade.optimize.backtesting as backtesting
@ -47,29 +46,31 @@ def test_get_timeframe(default_strategy):
def test_backtest(default_strategy, default_conf, mocker): def test_backtest(default_strategy, default_conf, mocker):
mocker.patch.dict('freqtrade.main._CONF', default_conf) 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 = optimize.load_data(None, ticker_interval=5, pairs=['BTC_ETH'])
data = trim_dictlist(data, -200) data = trim_dictlist(data, -200)
results = backtest({'stake_amount': default_conf['stake_amount'], for exch in exchange.Exchanges.__members__.keys():
'processed': optimize.preprocess(data), results = backtest({'stake_amount': default_conf['stake_amount'],
'max_open_trades': 10, 'processed': optimize.preprocess(data),
'realistic': True}) 'max_open_trades': 10,
assert not results.empty 'realistic': True,
'exchange_name': exch.lower()})
assert not results.empty
def test_backtest_1min_ticker_interval(default_strategy, default_conf, mocker): def test_backtest_1min_ticker_interval(default_strategy, default_conf, mocker):
mocker.patch.dict('freqtrade.main._CONF', default_conf) mocker.patch.dict('freqtrade.main._CONF', default_conf)
exchange._API = Bittrex({'key': '', 'secret': ''})
# Run a backtesting for an exiting 5min ticker_interval # Run a backtesting for an exiting 5min ticker_interval
data = optimize.load_data(None, ticker_interval=1, pairs=['BTC_UNITEST']) data = optimize.load_data(None, ticker_interval=1, pairs=['BTC_UNITEST'])
data = trim_dictlist(data, -200) data = trim_dictlist(data, -200)
results = backtest({'stake_amount': default_conf['stake_amount'], for exch in exchange.Exchanges.__members__.keys():
'processed': optimize.preprocess(data), results = backtest({'stake_amount': default_conf['stake_amount'],
'max_open_trades': 1, 'processed': optimize.preprocess(data),
'realistic': True}) 'max_open_trades': 1,
assert not results.empty 'realistic': True,
'exchange_name': exch.lower()})
assert not results.empty
def load_data_test(what): def load_data_test(what):
@ -122,7 +123,8 @@ def simple_backtest(config, contour, num_results):
results = backtest({'stake_amount': config['stake_amount'], results = backtest({'stake_amount': config['stake_amount'],
'processed': processed, 'processed': processed,
'max_open_trades': 1, 'max_open_trades': 1,
'realistic': True}) 'realistic': True,
'exchange_name': config['exchange']['name']})
# results :: <class 'pandas.core.frame.DataFrame'> # results :: <class 'pandas.core.frame.DataFrame'>
assert len(results) == num_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) mocker.patch.dict('freqtrade.main._CONF', default_conf)
data = optimize.load_data(None, ticker_interval=5, pairs=['BTC_ETH']) data = optimize.load_data(None, ticker_interval=5, pairs=['BTC_ETH'])
data = trim_dictlist(data, -200) data = trim_dictlist(data, -200)
results = backtest({'stake_amount': default_conf['stake_amount'], for exch in exchange.Exchanges.__members__.keys():
'processed': optimize.preprocess(data), results = backtest({'stake_amount': default_conf['stake_amount'],
'max_open_trades': 10, 'processed': optimize.preprocess(data),
'realistic': True}) 'max_open_trades': 10,
assert not results.empty 'realistic': True,
'exchange_name': exch.lower()})
assert not results.empty
def test_processed(default_conf, mocker, default_strategy): def test_processed(default_conf, mocker, default_strategy):