Allow to change the number of currencies used by dynamic-whitelist

This commit is contained in:
Gerald Lonlas 2017-12-10 23:56:03 -08:00
parent 82bf0be3e2
commit ef7646417b
4 changed files with 54 additions and 14 deletions

View File

@ -146,19 +146,40 @@ Simple High Frequency Trading Bot for crypto currencies
positional arguments:
{backtesting}
backtesting backtesting module
backtesting backtesting module
optional arguments:
-h, --help show this help message and exit
-h, --help show this help message and exit
-c PATH, --config PATH
specify configuration file (default: config.json)
-v, --verbose be verbose
--version show program's version number and exit
--dynamic-whitelist dynamically generate and update whitelist based on 24h
BaseVolume
specify configuration file (default: config.json)
-v, --verbose be verbose
--version show program's version number and exit
--dynamic-whitelist INT dynamically generate and update whitelist based on 24h
BaseVolume (Default 20 currencies)
```
#### Dynamic whitelist example
Per default `--dynamic-whitelist` will retrieve the 20 currencies based
on BaseVolume. This value can be changed when you run the script.
**By Default**
Get the 20 currencies based on BaseVolume.
```bash
freqtrade --dynamic-whitelist
```
**Customize the number of currencies to retrieve**
Get the 30 currencies based on BaseVolume.
```bash
freqtrade --dynamic-whitelist 30
```
**Exception**
`--dynamic-whitelist` must be greater than 0. If you enter 0 or a
negative value (e.g -2), `--dynamic-whitelist` will use the default
value (20).
### Backtesting
Backtesting also uses the config specified via `-c/--config`.

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python3
import argparse
import copy
import json
import logging
@ -49,7 +50,7 @@ def refresh_whitelist(whitelist: Optional[List[str]] = None) -> None:
_CONF['exchange']['pair_whitelist'] = sanitized_whitelist
def _process(dynamic_whitelist: Optional[bool] = False) -> bool:
def _process(dynamic_whitelist: Optional[int] = 0) -> bool:
"""
Queries the persistence layer for open trades and handles them,
otherwise a new trade is created.
@ -60,7 +61,7 @@ def _process(dynamic_whitelist: Optional[bool] = False) -> bool:
try:
# Refresh whitelist based on wallet maintenance
refresh_whitelist(
gen_pair_whitelist(_CONF['stake_currency']) if dynamic_whitelist else None
gen_pair_whitelist(_CONF['stake_currency'], topn = dynamic_whitelist) if dynamic_whitelist else None
)
# Query trades from persistence layer
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
@ -266,7 +267,7 @@ def gen_pair_whitelist(base_currency: str, topn: int = 20, key: str = 'BaseVolum
"""
Updates the whitelist with with a dynamically generated list
:param base_currency: base currency as str
:param topn: maximum number of returned results
:param topn: maximum number of returned results, must be greater than 0
:param key: sort key (defaults to 'BaseVolume')
:return: List of pairs
"""
@ -275,6 +276,11 @@ def gen_pair_whitelist(base_currency: str, topn: int = 20, key: str = 'BaseVolum
key=lambda s: s.get(key) or 0.0,
reverse=True
)
# topn must be greater than 0
if not topn > 0:
topn = 20
return [s['MarketName'].replace('-', '_') for s in summaries[:topn]]

View File

@ -112,8 +112,12 @@ def parse_args(args: List[str]):
)
parser.add_argument(
'--dynamic-whitelist',
help='dynamically generate and update whitelist based on 24h BaseVolume',
action='store_true',
help='dynamically generate and update whitelist based on 24h BaseVolume (Default 20 currencies)',
dest='dynamic_whitelist',
const=20,
type=int,
metavar='INT',
nargs='?',
)
build_subcommands(parser)
parsed_args = parser.parse_args(args)

View File

@ -30,7 +30,7 @@ def test_parse_args_defaults():
args = parse_args([])
assert args is not None
assert args.config == 'config.json'
assert args.dynamic_whitelist is False
assert args.dynamic_whitelist is None
assert args.loglevel == 20
@ -58,7 +58,16 @@ def test_parse_args_verbose():
def test_parse_args_dynamic_whitelist():
args = parse_args(['--dynamic-whitelist'])
assert args is not None
assert args.dynamic_whitelist is True
assert args.dynamic_whitelist is 20
def test_parse_args_dynamic_whitelist_10():
args = parse_args(['--dynamic-whitelist', '10'])
assert args is not None
assert args.dynamic_whitelist is 10
def test_parse_args_dynamic_whitelist_invalid_values():
with pytest.raises(SystemExit, match=r'2'):
parse_args(['--dynamic-whitelist', 'abc'])
def test_parse_args_backtesting(mocker):