Merge remote-tracking branch 'origin/wohlgemuth' into aws

# Conflicts:
#	requirements.txt
#	scripts/plot_profit.py
This commit is contained in:
Gert 2018-05-23 18:56:27 -07:00
commit bab9a92ae1
46 changed files with 893 additions and 175 deletions

View File

@ -4,3 +4,12 @@ Dockerfile
.dockerignore
config.json*
*.sqlite
.coveragerc
.eggs
.github
.pylintrc
.travis.yml
CONTRIBUTING.md
MANIFEST.in
README.md
freqtrade.service

View File

@ -4,6 +4,15 @@
[![Coverage Status](https://coveralls.io/repos/github/gcarq/freqtrade/badge.svg?branch=develop&service=github)](https://coveralls.io/github/gcarq/freqtrade?branch=develop)
[![Maintainability](https://api.codeclimate.com/v1/badges/5737e6d668200b7518ff/maintainability)](https://codeclimate.com/github/gcarq/freqtrade/maintainability)
## First of all, this is a fork!
Basically I required a lot more features than the awesome default freqtrade version has to offer and since pull requests always take longer than exspected or the standard disagreements. I decided to maintain on main branch for my changes, called wohlgemuth, which is incidentally my last name and have a ton of little branches, with added features.
This basically allows people to use my version, or to easily merge changes into their forks or make PR's against the main repo, which is the best of both works.
This reminds of the Torvalds kernel vs the Cox kernel...
## Back to what this is actually about
Simple High frequency trading bot for crypto currencies designed to
support multi exchanges and be controlled via Telegram.
@ -44,11 +53,8 @@ hesitate to read the source code and understand the mechanism of this bot.
- [Software requirements](#software-requirements)
## Branches
The project is currently setup in two main branches:
- `develop` - This branch has often new features, but might also cause
breaking changes.
- `master` - This branch contains the latest stable release. The bot
'should' be stable on this branch, and is generally well tested.
if you like to use this fork, I highly recommend to utilize the 'wohlgemuth' branch, since this is the most stable. It will be synced against the original development branch and be enriched with all my changes.
## Features
- [x] **Based on Python 3.6+**: For botting on any operating system -
@ -70,6 +76,32 @@ want to avoid.
- [x] **Performance status report**: Provide a performance status of
your current trades.
### Additional features in this branch
#### Cloud:
- [x] aws lambda based backtesting
- [x] automatically evaluating all strategies from: https://github.com/berlinguyinca/freqtrade-trading-strategies on an hourly basis
- [x] persisting of backtesting results
#### Strategy:
- [x] loading strategies from Base64 encoded data in the config file
- [x] loading strategies from urls
- [x] trailing stop loss
#### Others:
- [x] more indicators
- [x] more telegram features
- [x] advanced plotting
### Drawbacks
- [x] not as good documentation
- [x] maybe a bug here or there I haven't fixed yet
### Exchange supported
- [x] Bittrex
- [ ] Binance

View File

@ -3,7 +3,11 @@
"stake_currency": "BTC",
"stake_amount": 0.05,
"fiat_display_currency": "USD",
"ticker_interval" : "5m",
"dry_run": false,
"trailing_stop": {
"positive" : 0.005
},
"unfilledtimeout": 600,
"bid_strategy": {
"ask_last_balance": 0.0

View File

@ -5,6 +5,7 @@
"fiat_display_currency": "USD",
"dry_run": false,
"ticker_interval": "5m",
"trailing_stop": true,
"minimal_roi": {
"40": 0.0,
"30": 0.01,

View File

@ -43,6 +43,10 @@ python scripts/plot_dataframe.py -p BTC_ETH --timerange=100-200
```
Timerange doesn't work with live data.
To plot trades stored in a database use `--db-url` argument:
```
python scripts/plot_dataframe.py --db-url tradesv3.dry_run.sqlite -p BTC_ETH
```
## Plot profit

View File

@ -32,9 +32,12 @@ CREATE TABLE trades (
exchange VARCHAR NOT NULL,
pair VARCHAR NOT NULL,
is_open BOOLEAN NOT NULL,
fee FLOAT NOT NULL,
fee_open FLOAT NOT NULL,
fee_close FLOAT NOT NULL,
open_rate FLOAT,
open_rate_requested FLOAT,
close_rate FLOAT,
close_rate_requested FLOAT,
close_profit FLOAT,
stake_amount FLOAT NOT NULL,
amount FLOAT,
@ -71,13 +74,13 @@ WHERE id=31;
```sql
INSERT
INTO trades (exchange, pair, is_open, fee, open_rate, stake_amount, amount, open_date)
VALUES ('BITTREX', 'BTC_<COIN>', 1, 0.0025, <open_rate>, <stake_amount>, <amount>, '<datetime>')
INTO trades (exchange, pair, is_open, fee_open, fee_close, open_rate, stake_amount, amount, open_date)
VALUES ('BITTREX', 'BTC_<COIN>', 1, 0.0025, 0.0025, <open_rate>, <stake_amount>, <amount>, '<datetime>')
```
**Example:**
```sql
INSERT INTO trades (exchange, pair, is_open, fee, open_rate, stake_amount, amount, open_date) VALUES ('BITTREX', 'BTC_ETC', 1, 0.0025, 0.00258580, 0.002, 0.7715262081, '2017-11-28 12:44:24.000000')
INSERT INTO trades (exchange, pair, is_open, fee_open, fee_close, open_rate, stake_amount, amount, open_date) VALUES ('BITTREX', 'BTC_ETC', 1, 0.0025, 0.0025, 0.00258580, 0.002, 0.7715262081, '2017-11-28 12:44:24.000000')
```
## Fix wrong fees in the table

View File

@ -129,12 +129,8 @@ Day Profit BTC Profit USD
> **Version:** `0.14.3`
### using proxy with telegram
in [freqtrade/freqtrade/rpc/telegram.py](https://github.com/gcarq/freqtrade/blob/develop/freqtrade/rpc/telegram.py) replace
```
self._updater = Updater(token=self._config['telegram']['token'], workers=0)
```
with
```
self._updater = Updater(token=self._config['telegram']['token'], request_kwargs={'proxy_url': 'socks5://127.0.0.1:1080/'}, workers=0)
$ export HTTP_PROXY="http://addr:port"
$ export HTTPS_PROXY="http://addr:port"
$ freqtrade
```

View File

@ -1,5 +1,5 @@
""" FreqTrade bot """
__version__ = '0.16.0'
__version__ = '0.17.0'
class DependencyException(BaseException):

View File

@ -14,7 +14,6 @@ from freqtrade.exchange import get_ticker_history
from freqtrade.persistence import Trade
from freqtrade.strategy.resolver import StrategyResolver
logger = logging.getLogger(__name__)
@ -31,6 +30,7 @@ class Analyze(object):
Analyze class contains everything the bot need to determine if the situation is good for
buying or selling.
"""
def __init__(self, config: dict) -> None:
"""
Init Analyze
@ -195,10 +195,41 @@ class Analyze(object):
:return True if bot should sell at current rate
"""
current_profit = trade.calc_profit_percent(current_rate)
if self.strategy.stoploss is not None and current_profit < self.strategy.stoploss:
if trade.stop_loss is None:
# initially adjust the stop loss to the base value
trade.adjust_stop_loss(trade.open_rate, self.strategy.stoploss)
# evaluate if the stoploss was hit
if self.strategy.stoploss is not None and trade.stop_loss >= current_rate:
if 'trailing_stop' in self.config and self.config['trailing_stop']:
logger.debug(
"HIT STOP: current price at {:.6f}, stop loss is {:.6f}, "
"initial stop loss was at {:.6f}, trade opened at {:.6f}".format(
current_rate, trade.stop_loss, trade.initial_stop_loss, trade.open_rate))
logger.debug("trailing stop saved us: {:.6f}"
.format(trade.stop_loss - trade.initial_stop_loss))
logger.debug('Stop loss hit.')
return True
# update the stop loss afterwards, after all by definition it's supposed to be hanging
if 'trailing_stop' in self.config and self.config['trailing_stop']:
# check if we have a special stop loss for positive condition
# and if profit is positive
stop_loss_value = self.strategy.stoploss
if isinstance(self.config['trailing_stop'], dict) and \
'positive' in self.config['trailing_stop'] and \
current_profit > 0:
logger.debug("using positive stop loss mode: {} since we have profit {}".format(
self.config['trailing_stop']['positive'], current_profit))
stop_loss_value = self.config['trailing_stop']['positive']
trade.adjust_stop_loss(current_rate, stop_loss_value)
# Check if time matches and current rate is above threshold
time_diff = (current_time.timestamp() - trade.open_date.timestamp()) / 60
for duration, threshold in self.strategy.minimal_roi.items():

View File

@ -288,6 +288,25 @@ class Arguments(object):
default=None
)
self.parser.add_argument(
'--plot-osc',
help='Renders a osc chart of the given osc dataframe name, for example --plot-osc osc',
dest='plotosc',
nargs='+',
default=None
)
self.parser.add_argument(
'--plot-cmf',
help='Renders a cmf chart of the given cmf dataframe name, for example --plot-cmf cmf',
dest='plotcmf',
nargs='+',
default=None
)
self.parser.add_argument(
'--plot-macd',
help='Renders a macd chart of the given '
@ -331,6 +350,13 @@ class Arguments(object):
)
self.parser.add_argument(
'-db', '--db-url',
help='Show trades stored in database.',
dest='db_url',
default=None
)
def testdata_dl_options(self) -> None:
"""
Parses given arguments for testdata download

View File

@ -297,9 +297,10 @@ def get_ticker_history(pair: str, tick_interval: str, since_ms: Optional[int] =
if not data_part:
break
logger.info('Downloaded data for time range [%s, %s]',
arrow.get(data_part[0][0] / 1000).format(),
arrow.get(data_part[-1][0] / 1000).format())
logger.debug('Downloaded data for %s time range [%s, %s]',
pair,
arrow.get(data_part[0][0] / 1000).format(),
arrow.get(data_part[-1][0] / 1000).format())
data.extend(data_part)
since_ms = data[-1][0] + 1

View File

@ -5,6 +5,7 @@ e.g BTC to USD
import logging
import time
from typing import Dict
from coinmarketcap import Market
@ -73,12 +74,7 @@ class CryptoToFiatConverter(object):
"RUB", "SEK", "SGD", "THB", "TRY", "TWD", "ZAR", "USD"
]
CRYPTOMAP = {
'BTC': 'bitcoin',
'ETH': 'ethereum',
'USDT': 'thether',
'BNB': 'binance-coin'
}
_cryptomap: Dict = {}
def __new__(cls):
if CryptoToFiatConverter.__instance is None:
@ -91,6 +87,15 @@ class CryptoToFiatConverter(object):
def __init__(self) -> None:
self._pairs = []
self._load_cryptomap()
def _load_cryptomap(self) -> None:
try:
coinlistings = self._coinmarketcap.listings()
self._cryptomap = dict(map(lambda coin: (coin["symbol"], str(coin["id"])),
coinlistings["data"]))
except ValueError:
logger.error("Could not load FIAT Cryptocurrency map")
def convert_amount(self, crypto_amount: float, crypto_symbol: str, fiat_symbol: str) -> float:
"""
@ -182,16 +187,17 @@ class CryptoToFiatConverter(object):
if not self._is_supported_fiat(fiat=fiat_symbol):
raise ValueError('The fiat {} is not supported.'.format(fiat_symbol))
if crypto_symbol not in self.CRYPTOMAP:
if crypto_symbol not in self._cryptomap:
# return 0 for unsupported stake currencies (fiat-convert should not break the bot)
logger.warning("unsupported crypto-symbol %s - returning 0.0", crypto_symbol)
return 0.0
try:
return float(
self._coinmarketcap.ticker(
currency=self.CRYPTOMAP[crypto_symbol],
currency=self._cryptomap[crypto_symbol],
convert=fiat_symbol
)[0]['price_' + fiat_symbol.lower()]
)['data']['quotes'][fiat_symbol.upper()]['price']
)
except BaseException:
except BaseException as ex:
logger.error("Error in _find_price: %s", ex)
return 0.0

View File

@ -330,6 +330,7 @@ class FreqtradeBot(object):
fee_open=fee,
fee_close=fee,
open_rate=buy_limit,
open_rate_requested=buy_limit,
open_date=datetime.utcnow(),
exchange=exchange.get_id(),
open_order_id=order_id
@ -396,7 +397,7 @@ class FreqtradeBot(object):
return order_amount
# use fee from order-dict if possible
if 'fee' in order and order['fee']:
if 'fee' in order and order['fee'] and (order['fee'].keys() >= {'currency', 'cost'}):
if trade.pair.startswith(order['fee']['currency']):
new_amount = order_amount - order['fee']['cost']
logger.info("Applying fee on amount for %s (from %s to %s) from Order",
@ -413,7 +414,7 @@ class FreqtradeBot(object):
fee_abs = 0
for exectrade in trades:
amount += exectrade['amount']
if "fee" in exectrade:
if "fee" in exectrade and (exectrade['fee'].keys() >= {'currency', 'cost'}):
# only applies if fee is in quote currency!
if trade.pair.startswith(exectrade['fee']['currency']):
fee_abs += exectrade['fee']['cost']
@ -538,6 +539,7 @@ class FreqtradeBot(object):
# Execute sell and update trade record
order_id = exchange.sell(str(trade.pair), limit, trade.amount)['id']
trade.open_order_id = order_id
trade.close_rate_requested = limit
fmt_exp_profit = round(trade.calc_profit_percent(rate=limit) * 100, 2)
profit_trade = trade.calc_profit(rate=limit)

View File

@ -15,6 +15,8 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.scoping import scoped_session
from sqlalchemy.orm.session import sessionmaker
from sqlalchemy.pool import StaticPool
from sqlalchemy import inspect
logger = logging.getLogger(__name__)
@ -50,12 +52,61 @@ def init(config: dict, engine: Optional[Engine] = None) -> None:
Trade.session = session()
Trade.query = session.query_property()
_DECL_BASE.metadata.create_all(engine)
check_migrate(engine)
# Clean dry_run DB
if _CONF.get('dry_run', False) and _CONF.get('dry_run_db', False):
clean_dry_run_db()
def has_column(columns, searchname: str) -> bool:
return len(list(filter(lambda x: x["name"] == searchname, columns))) == 1
def check_migrate(engine) -> None:
"""
Checks if migration is necessary and migrates if necessary
"""
inspector = inspect(engine)
cols = inspector.get_columns('trades')
if not has_column(cols, 'fee_open'):
# Schema migration necessary
engine.execute("alter table trades rename to trades_bak")
# let SQLAlchemy create the schema as required
_DECL_BASE.metadata.create_all(engine)
# Copy data back - following the correct schema
engine.execute("""insert into trades
(id, exchange, pair, is_open, fee_open, fee_close, open_rate,
open_rate_requested, close_rate, close_rate_requested, close_profit,
stake_amount, amount, open_date, close_date, open_order_id)
select id, lower(exchange),
case
when instr(pair, '_') != 0 then
substr(pair, instr(pair, '_') + 1) || '/' ||
substr(pair, 1, instr(pair, '_') - 1)
else pair
end
pair,
is_open, fee fee_open, fee fee_close,
open_rate, null open_rate_requested, close_rate,
null close_rate_requested, close_profit,
stake_amount, amount, open_date, close_date, open_order_id
from trades_bak
""")
# Reread columns - the above recreated the table!
inspector = inspect(engine)
cols = inspector.get_columns('trades')
if not has_column(cols, 'open_rate_requested'):
engine.execute("alter table trades add open_rate_requested float")
if not has_column(cols, 'close_rate_requested'):
engine.execute("alter table trades add close_rate_requested float")
def cleanup() -> None:
"""
Flushes all pending operations to disk.
@ -88,13 +139,21 @@ class Trade(_DECL_BASE):
fee_open = Column(Float, nullable=False, default=0.0)
fee_close = Column(Float, nullable=False, default=0.0)
open_rate = Column(Float)
open_rate_requested = Column(Float)
close_rate = Column(Float)
close_rate_requested = Column(Float)
close_profit = Column(Float)
stake_amount = Column(Float, nullable=False)
amount = Column(Float)
open_date = Column(DateTime, nullable=False, default=datetime.utcnow)
close_date = Column(DateTime)
open_order_id = Column(String)
# absolute value of the stop loss
stop_loss = Column(Float, nullable=False, default=0.0)
# absolute value of the initial stop loss
initial_stop_loss = Column(Float, nullable=False, default=0.0)
# absolute value of the highest reached price
max_rate = Column(Float, nullable=False, default=0.0)
def __repr__(self):
return 'Trade(id={}, pair={}, amount={:.8f}, open_rate={:.8f}, open_since={})'.format(
@ -105,6 +164,50 @@ class Trade(_DECL_BASE):
arrow.get(self.open_date).humanize() if self.is_open else 'closed'
)
def adjust_stop_loss(self, current_price, stoploss):
"""
this adjusts the stop loss to it's most recently observed
setting
:param current_price:
:param stoploss:
:return:
"""
new_loss = Decimal(current_price * (1 - abs(stoploss)))
# keeping track of the highest observed rate for this trade
if self.max_rate is None:
self.max_rate = current_price
else:
if current_price > self.max_rate:
self.max_rate = current_price
# no stop loss assigned yet
if self.stop_loss is None or self.stop_loss == 0:
logger.debug("assigning new stop loss")
self.stop_loss = new_loss
self.initial_stop_loss = new_loss
# evaluate if the stop loss needs to be updated
else:
if new_loss > self.stop_loss: # stop losses only walk up, never down!
self.stop_loss = new_loss
logger.debug("adjusted stop loss")
else:
logger.debug("keeping current stop loss")
logger.debug(
"{} - current price {:.8f}, bought at {:.8f} and calculated "
"stop loss is at: {:.8f} initial stop at {:.8f}. trailing stop loss saved us: {:.8f} "
"and max observed rate was {:.8f}".format(
self.pair, current_price, self.open_rate,
self.initial_stop_loss,
self.stop_loss, float(self.stop_loss) - float(self.initial_stop_loss),
self.max_rate
))
def update(self, order: Dict) -> None:
"""
Updates this entity with amount and actual open/close rates.

View File

@ -63,6 +63,7 @@ class RPC(object):
"*Close Rate:* `{close_rate}`\n" \
"*Current Rate:* `{current_rate:.8f}`\n" \
"*Close Profit:* `{close_profit}`\n" \
"*Stake Value:* `{stake_value}`\n" \
"*Current Profit:* `{current_profit:.2f}%`\n" \
"*Open Order:* `{open_order}`"\
.format(
@ -75,6 +76,7 @@ class RPC(object):
current_rate=current_rate,
amount=round(trade.amount, 8),
close_profit=fmt_close_profit,
stake_value=round(current_rate * trade.amount, 8),
current_profit=round(current_profit * 100, 2),
open_order='({} {} rem={:.8f})'.format(
order['type'], order['side'], order['remaining']
@ -98,10 +100,11 @@ class RPC(object):
trade.id,
trade.pair,
shorten_date(arrow.get(trade.open_date).humanize(only_distance=True)),
'{:.2f}%'.format(100 * trade.calc_profit_percent(current_rate))
'{:.2f}%'.format(100 * trade.calc_profit_percent(current_rate)),
'{:.8f}'.format(trade.amount * current_rate)
])
columns = ['ID', 'Pair', 'Since', 'Profit']
columns = ['ID', 'Pair', 'Since', 'Profit', 'Value']
df_statuses = DataFrame.from_records(trades_list, columns=columns)
df_statuses = df_statuses.set_index(columns[0])
# The style used throughout is to return a tuple
@ -245,35 +248,34 @@ class RPC(object):
"""
:return: current account balance per crypto
"""
balances = [
c for c in exchange.get_balances()
if c['Balance'] or c['Available'] or c['Pending']
]
if not balances:
return True, '`All balances are zero.`'
output = []
total = 0.0
for currency in balances:
coin = currency['Currency']
for coin, balance in exchange.get_balances().items():
if not balance['total']:
continue
rate = None
if coin == 'BTC':
currency["Rate"] = 1.0
rate = 1.0
else:
if coin == 'USDT':
currency["Rate"] = 1.0 / exchange.get_ticker('BTC/USDT', False)['bid']
rate = 1.0 / exchange.get_ticker('BTC/USDT', False)['bid']
else:
currency["Rate"] = exchange.get_ticker(coin + '/BTC', False)['bid']
currency['BTC'] = currency["Rate"] * currency["Balance"]
total = total + currency['BTC']
rate = exchange.get_ticker(coin + '/BTC', False)['bid']
est_btc: float = rate * balance['total']
total = total + est_btc
output.append(
{
'currency': currency['Currency'],
'available': currency['Available'],
'balance': currency['Balance'],
'pending': currency['Pending'],
'est_btc': currency['BTC']
'currency': coin,
'available': balance['free'],
'balance': balance['total'],
'pending': balance['used'],
'est_btc': est_btc
}
)
if total == 0.0:
return True, '`All balances are zero.`'
fiat = self.freqtrade.fiat_converter
symbol = fiat_display_currency
value = fiat.convert_amount(total, 'BTC', symbol)

View File

@ -264,17 +264,15 @@ class Telegram(RPC):
(currencys, total, symbol, value) = result
output = ''
for currency in currencys:
output += """*Currency*: {currency}
*Available*: {available}
*Balance*: {balance}
*Pending*: {pending}
*Est. BTC*: {est_btc: .8f}
""".format(**currency)
output += "*{currency}:*\n" \
"\t`Available: {available: .8f}`\n" \
"\t`Balance: {balance: .8f}`\n" \
"\t`Pending: {pending: .8f}`\n" \
"\t`Est. BTC: {est_btc: .8f}`\n".format(**currency)
output += """*Estimated Value*:
*BTC*: {0: .8f}
*{1}*: {2: .2f}
""".format(total, symbol, value)
output += "\n*Estimated Value*:\n" \
"\t`BTC: {0: .8f}`\n" \
"\t`{1}: {2: .2f}`\n".format(total, symbol, value)
self.send_msg(output)
@authorized_only

View File

@ -2,6 +2,7 @@
import json
import logging
from datetime import datetime
from typing import Dict, Optional
from functools import reduce
from unittest.mock import MagicMock
@ -38,7 +39,8 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
:param config: Config to pass to the bot
:return: None
"""
mocker.patch('freqtrade.fiat_convert.Market', {'price_usd': 12345.0})
# mocker.patch('freqtrade.fiat_convert.Market', {'price_usd': 12345.0})
patch_coinmarketcap(mocker, {'price_usd': 12345.0})
mocker.patch('freqtrade.freqtradebot.Analyze', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.persistence.init', MagicMock())
@ -50,6 +52,27 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
return FreqtradeBot(config, create_engine('sqlite://'))
def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> None:
"""
Mocker to coinmarketcap to speed up tests
:param mocker: mocker to patch coinmarketcap class
:return: None
"""
tickermock = MagicMock(return_value={'price_usd': 12345.0})
listmock = MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC',
'website_slug': 'bitcoin'},
{'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH',
'website_slug': 'ethereum'}
]})
mocker.patch.multiple(
'freqtrade.fiat_convert.Market',
ticker=tickermock,
listings=listmock,
)
@pytest.fixture(scope="function")
def default_conf():
""" Returns validated configuration suitable for most tests """

View File

@ -123,7 +123,7 @@ def test_loss_calculation_has_limited_profit(init_hyperopt) -> None:
assert under > correct
def test_log_results_if_loss_improves(capsys) -> None:
def test_log_results_if_loss_improves(init_hyperopt, capsys) -> None:
hyperopt = _HYPEROPT
hyperopt.current_best_loss = 2
hyperopt.log_results(

View File

@ -67,6 +67,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'*Close Rate:* `None`\n'
'*Current Rate:* `0.00001098`\n'
'*Close Profit:* `None`\n'
'*Stake Value:* `0.00099909`\n'
'*Current Profit:* `-0.59%`\n'
'*Open Order:* `(limit buy rem=0.00000000)`'
]
@ -106,6 +107,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
assert 'just now' in result['Since'].all()
assert 'ETH/BTC' in result['Pair'].all()
assert '-0.59%' in result['Profit'].all()
assert 'Value' in result
def test_rpc_daily_profit(default_conf, update, ticker, fee,
@ -288,22 +290,18 @@ def test_rpc_balance_handle(default_conf, mocker):
"""
Test rpc_balance() method
"""
mock_balance = [
{
'Currency': 'BTC',
'Balance': 10.0,
'Available': 12.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX',
mock_balance = {
'BTC': {
'free': 10.0,
'total': 12.0,
'used': 2.0,
},
{
'Currency': 'ETH',
'Balance': 0.0,
'Available': 0.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX',
'ETH': {
'free': 0.0,
'total': 0.0,
'used': 0.0,
}
]
}
patch_get_signal(mocker, (True, False))
mocker.patch.multiple(
@ -324,15 +322,15 @@ def test_rpc_balance_handle(default_conf, mocker):
(error, res) = rpc.rpc_balance(default_conf['fiat_display_currency'])
assert not error
(trade, x, y, z) = res
assert prec_satoshi(x, 10)
assert prec_satoshi(z, 150000)
assert prec_satoshi(x, 12)
assert prec_satoshi(z, 180000)
assert 'USD' in y
assert len(trade) == 1
assert 'BTC' in trade[0]['currency']
assert prec_satoshi(trade[0]['available'], 12)
assert prec_satoshi(trade[0]['balance'], 10)
assert prec_satoshi(trade[0]['pending'], 0)
assert prec_satoshi(trade[0]['est_btc'], 10)
assert prec_satoshi(trade[0]['available'], 10)
assert prec_satoshi(trade[0]['balance'], 12)
assert prec_satoshi(trade[0]['pending'], 2)
assert prec_satoshi(trade[0]['est_btc'], 12)
def test_rpc_start(mocker, default_conf) -> None:

View File

@ -554,36 +554,29 @@ def test_telegram_balance_handle(default_conf, update, mocker) -> None:
"""
Test _balance() method
"""
mock_balance = [
{
'Currency': 'BTC',
'Balance': 10.0,
'Available': 12.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX',
mock_balance = {
'BTC': {
'total': 12.0,
'free': 12.0,
'used': 0.0
},
{
'Currency': 'ETH',
'Balance': 0.0,
'Available': 0.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX',
'ETH': {
'total': 0.0,
'free': 0.0,
'used': 0.0
},
{
'Currency': 'USDT',
'Balance': 10000.0,
'Available': 0.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX',
'USDT': {
'total': 10000.0,
'free': 10000.0,
'used': 0.0
},
{
'Currency': 'LTC',
'Balance': 10.0,
'Available': 10.0,
'Pending': 0.0,
'CryptoAddress': 'XXXX',
'LTC': {
'total': 10.0,
'free': 10.0,
'used': 0.0
}
]
}
def mock_ticker(symbol, refresh):
"""
@ -621,12 +614,12 @@ def test_telegram_balance_handle(default_conf, update, mocker) -> None:
telegram._balance(bot=MagicMock(), update=update)
result = msg_mock.call_args_list[0][0][0]
assert msg_mock.call_count == 1
assert '*Currency*: BTC' in result
assert '*Currency*: ETH' not in result
assert '*Currency*: USDT' in result
assert 'Balance' in result
assert 'Est. BTC' in result
assert '*BTC*: 12.00000000' in result
assert '*BTC:*' in result
assert '*ETH:*' not in result
assert '*USDT:*' in result
assert 'Balance:' in result
assert 'Est. BTC:' in result
assert 'BTC: 14.00000000' in result
def test_zero_balance_handle(default_conf, update, mocker) -> None:
@ -636,7 +629,7 @@ def test_zero_balance_handle(default_conf, update, mocker) -> None:
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker, value={'price_usd': 15000.0})
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
mocker.patch('freqtrade.freqtradebot.exchange.get_balances', return_value=[])
mocker.patch('freqtrade.freqtradebot.exchange.get_balances', return_value={})
msg_mock = MagicMock()
mocker.patch.multiple(

View File

@ -38,10 +38,17 @@ def test_load_strategy_from_url(result):
def test_load_strategy_custom_directory(result):
resolver = StrategyResolver()
extra_dir = os.path.join('some', 'path')
with pytest.raises(
FileNotFoundError,
match=r".*No such file or directory: '{}'".format(extra_dir)):
resolver._load_strategy('TestStrategy', extra_dir)
if os.name == 'nt':
with pytest.raises(
FileNotFoundError,
match="FileNotFoundError: [WinError 3] The system cannot find the path specified: '{}'".format(extra_dir)):
resolver._load_strategy('TestStrategy', extra_dir)
else:
with pytest.raises(
FileNotFoundError,
match=r".*No such file or directory: '{}'".format(extra_dir)):
resolver._load_strategy('TestStrategy', extra_dir)
assert hasattr(resolver.strategy, 'populate_indicators')
assert 'adx' in resolver.strategy.populate_indicators(result)

View File

@ -7,6 +7,7 @@ from unittest.mock import MagicMock
import pytest
from freqtrade.fiat_convert import CryptoFiat, CryptoToFiatConverter
from freqtrade.tests.conftest import patch_coinmarketcap
def test_pair_convertion_object():
@ -123,12 +124,23 @@ def test_fiat_convert_get_price(mocker):
assert fiat_convert._pairs[0]._expiration is not expiration
def test_loadcryptomap(mocker):
patch_coinmarketcap(mocker)
fiat_convert = CryptoToFiatConverter()
assert len(fiat_convert._cryptomap) == 2
assert fiat_convert._cryptomap["BTC"] == "1"
def test_fiat_convert_without_network():
# Because CryptoToFiatConverter is a Singleton we reset the value of _coinmarketcap
fiat_convert = CryptoToFiatConverter()
cmc_temp = CryptoToFiatConverter._coinmarketcap
CryptoToFiatConverter._coinmarketcap = None
assert fiat_convert._coinmarketcap is None
assert fiat_convert._find_price(crypto_symbol='BTC', fiat_symbol='USD') == 0.0
CryptoToFiatConverter._coinmarketcap = cmc_temp

View File

@ -8,7 +8,6 @@ import logging
import re
import time
from copy import deepcopy
from typing import Dict, Optional
from unittest.mock import MagicMock
import arrow
@ -20,7 +19,7 @@ from freqtrade import DependencyException, OperationalException, TemporaryError
from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.persistence import Trade
from freqtrade.state import State
from freqtrade.tests.conftest import log_has
from freqtrade.tests.conftest import log_has, patch_coinmarketcap
# Functions for recurrent object patching
@ -64,20 +63,6 @@ def patch_RPCManager(mocker) -> MagicMock:
return rpc_mock
def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> None:
"""
Mocker to coinmarketcap to speed up tests
:param mocker: mocker to patch coinmarketcap class
:return: None
"""
mock = MagicMock()
if value:
mock.ticker = {'price_usd': 12345.0}
mocker.patch('freqtrade.fiat_convert.Market', mock)
# Unit tests
def test_freqtradebot_object() -> None:
"""
@ -1458,7 +1443,7 @@ def test_get_real_amount_fromorder(default_conf, trades_for_order, buy_order_fee
patch_RPCManager(mocker)
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.exchange.validate_pairs', MagicMock(return_value=True))
mocker.patch('freqtrade.exchange.get_trades_for_order', return_value=trades_for_order)
mocker.patch('freqtrade.exchange.get_trades_for_order', return_value=[trades_for_order])
amount = float(sum(x['amount'] for x in trades_for_order))
trade = Trade(
pair='LTC/ETH',
@ -1473,3 +1458,53 @@ def test_get_real_amount_fromorder(default_conf, trades_for_order, buy_order_fee
assert log_has('Applying fee on amount for Trade(id=None, pair=LTC/ETH, amount=8.00000000, '
'open_rate=0.24544100, open_since=closed) (from 8.0 to 7.996) from Order',
caplog.record_tuples)
def test_get_real_amount_invalid_order(default_conf, trades_for_order, buy_order_fee, mocker):
"""
Test get_real_amount with split trades (multiple trades for this order)
"""
limit_buy_order = deepcopy(buy_order_fee)
limit_buy_order['fee'] = {'cost': 0.004}
patch_get_signal(mocker)
patch_RPCManager(mocker)
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.exchange.validate_pairs', MagicMock(return_value=True))
mocker.patch('freqtrade.exchange.get_trades_for_order', return_value=[])
amount = float(sum(x['amount'] for x in trades_for_order))
trade = Trade(
pair='LTC/ETH',
amount=amount,
exchange='binance',
open_rate=0.245441,
open_order_id="123456"
)
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
# Amount does not change
assert freqtrade.get_real_amount(trade, limit_buy_order) == amount
def test_get_real_amount_invalid(default_conf, trades_for_order, buy_order_fee, mocker):
"""
Test get_real_amount - fees in Stake currency
"""
# Remove "Currency" from fee dict
trades_for_order[0]['fee'] = {'cost': 0.008}
patch_get_signal(mocker)
patch_RPCManager(mocker)
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.exchange.validate_pairs', MagicMock(return_value=True))
mocker.patch('freqtrade.exchange.get_trades_for_order', return_value=trades_for_order)
amount = sum(x['amount'] for x in trades_for_order)
trade = Trade(
pair='LTC/ETH',
amount=amount,
exchange='binance',
open_rate=0.245441,
open_order_id="123456"
)
freqtrade = FreqtradeBot(default_conf, create_engine('sqlite://'))
# Amount does not change
assert freqtrade.get_real_amount(trade, buy_order_fee) == amount

View File

@ -375,3 +375,105 @@ def test_clean_dry_run_db(default_conf, fee):
# We have now only the prod
assert len(Trade.query.filter(Trade.open_order_id.isnot(None)).all()) == 1
def test_migrate_old(default_conf, fee):
"""
Test Database migration(starting with old pairformat)
"""
amount = 103.223
create_table_old = """CREATE TABLE IF NOT EXISTS "trades" (
id INTEGER NOT NULL,
exchange VARCHAR NOT NULL,
pair VARCHAR NOT NULL,
is_open BOOLEAN NOT NULL,
fee FLOAT NOT NULL,
open_rate FLOAT,
close_rate FLOAT,
close_profit FLOAT,
stake_amount FLOAT NOT NULL,
amount FLOAT,
open_date DATETIME NOT NULL,
close_date DATETIME,
open_order_id VARCHAR,
PRIMARY KEY (id),
CHECK (is_open IN (0, 1))
);"""
insert_table_old = """INSERT INTO trades (exchange, pair, is_open, fee,
open_rate, stake_amount, amount, open_date)
VALUES ('BITTREX', 'BTC_ETC', 1, {fee},
0.00258580, {stake}, {amount},
'2017-11-28 12:44:24.000000')
""".format(fee=fee.return_value,
stake=default_conf.get("stake_amount"),
amount=amount
)
engine = create_engine('sqlite://')
# Create table using the old format
engine.execute(create_table_old)
engine.execute(insert_table_old)
# Run init to test migration
init(default_conf, engine)
assert len(Trade.query.filter(Trade.id == 1).all()) == 1
trade = Trade.query.filter(Trade.id == 1).first()
assert trade.fee_open == fee.return_value
assert trade.fee_close == fee.return_value
assert trade.open_rate_requested is None
assert trade.close_rate_requested is None
assert trade.is_open == 1
assert trade.amount == amount
assert trade.stake_amount == default_conf.get("stake_amount")
assert trade.pair == "ETC/BTC"
assert trade.exchange == "bittrex"
def test_migrate_new(default_conf, fee):
"""
Test Database migration (starting with new pairformat)
"""
amount = 103.223
create_table_old = """CREATE TABLE IF NOT EXISTS "trades" (
id INTEGER NOT NULL,
exchange VARCHAR NOT NULL,
pair VARCHAR NOT NULL,
is_open BOOLEAN NOT NULL,
fee FLOAT NOT NULL,
open_rate FLOAT,
close_rate FLOAT,
close_profit FLOAT,
stake_amount FLOAT NOT NULL,
amount FLOAT,
open_date DATETIME NOT NULL,
close_date DATETIME,
open_order_id VARCHAR,
PRIMARY KEY (id),
CHECK (is_open IN (0, 1))
);"""
insert_table_old = """INSERT INTO trades (exchange, pair, is_open, fee,
open_rate, stake_amount, amount, open_date)
VALUES ('binance', 'ETC/BTC', 1, {fee},
0.00258580, {stake}, {amount},
'2019-11-28 12:44:24.000000')
""".format(fee=fee.return_value,
stake=default_conf.get("stake_amount"),
amount=amount
)
engine = create_engine('sqlite://')
# Create table using the old format
engine.execute(create_table_old)
engine.execute(insert_table_old)
# Run init to test migration
init(default_conf, engine)
assert len(Trade.query.filter(Trade.id == 1).all()) == 1
trade = Trade.query.filter(Trade.id == 1).first()
assert trade.fee_open == fee.return_value
assert trade.fee_close == fee.return_value
assert trade.open_rate_requested is None
assert trade.close_rate_requested is None
assert trade.is_open == 1
assert trade.amount == amount
assert trade.stake_amount == default_conf.get("stake_amount")
assert trade.pair == "ETC/BTC"
assert trade.exchange == "binance"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,12 @@
ccxt==1.11.149
ccxt==1.14.24
SQLAlchemy==1.2.7
python-telegram-bot==10.1.0
arrow==0.12.1
cachetools==2.0.1
cachetools==2.1.0
requests==2.18.4
urllib3==1.22
wrapt==1.10.11
pandas==0.22.0
pandas==0.23.0
scikit-learn==0.19.1
scipy==1.1.0
jsonschema==2.6.0
@ -20,8 +20,9 @@ hyperopt==0.1
#networkx==1.11
git+git://github.com/berlinguyinca/networkx@v1.11
tabulate==0.8.2
coinmarketcap==4.2.1
simplejson
coinmarketcap==5.0.3
# Required for plotting data
#plotly==2.3.0

View File

@ -14,8 +14,131 @@ arguments = arguments.Arguments(sys.argv[1:], 'download utility')
arguments.testdata_dl_options()
args = arguments.parse_args()
TICKER_INTERVALS = ['1m', '5m']
PAIRS = []
TICKER_INTERVALS = ['1m', '5m', '1h', '4h']
PAIRS = [
"ETH/BTC",
"LTC/BTC",
"BNB/BTC",
"NEO/BTC",
"GAS/BTC",
"MCO/BTC",
"WTC/BTC",
"QTUM/BTC",
"OMG/BTC",
"ZRX/BTC",
"STRAT/BTC",
"SNGLS/BTC",
"BQX/BTC",
"KNC/BTC",
"FUN/BTC",
"SNM/BTC",
"LINK/BTC",
"XVG/BTC",
"SALT/BTC",
"IOTA/BTC",
"MDA/BTC",
"MTL/BTC",
"SUB/BTC",
"EOS/BTC",
"SNT/BTC",
"ETC/BTC",
"MTH/BTC",
"ENG/BTC",
"DNT/BTC",
"BNT/BTC",
"AST/BTC",
"DASH/BTC",
"ICN/BTC",
"OAX/BTC",
"BTG/BTC",
"EVX/BTC",
"REQ/BTC",
"LRC/BTC",
"VIB/BTC",
"HSR/BTC",
"TRX/BTC",
"POWR/BTC",
"ARK/BTC",
"XRP/BTC",
"MOD/BTC",
"ENJ/BTC",
"STORJ/BTC",
"VEN/BTC",
"KMD/BTC",
"RCN/BTC",
"NULS/BTC",
"RDN/BTC",
"XMR/BTC",
"DLT/BTC",
"AMB/BTC",
"BAT/BTC",
"ZEC/BTC",
"BCPT/BTC",
"ARN/BTC",
"GVT/BTC",
"CDT/BTC",
"GXS/BTC",
"POE/BTC",
"QSP/BTC",
"BTS/BTC",
"XZC/BTC",
"LSK/BTC",
"TNT/BTC",
"FUEL/BTC",
"MANA/BTC",
"BCD/BTC",
"DGD/BTC",
"ADX/BTC",
"ADA/BTC",
"PPT/BTC",
"CMT/BTC",
"XLM/BTC",
"CND/BTC",
"LEND/BTC",
"WABI/BTC",
"TNB/BTC",
"WAVES/BTC",
"ICX/BTC",
"GTO/BTC",
"OST/BTC",
"ELF/BTC",
"AION/BTC",
"NEBL/BTC",
"BRD/BTC",
"EDO/BTC",
"WINGS/BTC",
"NAV/BTC",
"LUN/BTC",
"TRIG/BTC",
"APPC/BTC",
"VIBE/BTC",
"RLC/BTC",
"INS/BTC",
"PIVX/BTC",
"IOST/BTC",
"CHAT/BTC",
"STEEM/BTC",
"VIA/BTC",
"BLZ/BTC",
"AE/BTC",
"RPX/BTC",
"NCASH/BTC",
"POA/BTC",
"ZIL/BTC",
"ONT/BTC",
"STORM/BTC",
"XEM/BTC",
"WAN/BTC",
"QLC/BTC",
"SYS/BTC",
"WPR/BTC",
"GRS/BTC",
"CLOAK/BTC",
"GNT/BTC",
"LOOM/BTC",
"BCN/BTC",
"REP/BTC"
]
if args.pairs_file:
with open(args.pairs_file) as file:
@ -30,7 +153,6 @@ since_time = None
if args.days:
since_time = arrow.utcnow().shift(days=-args.days).timestamp * 1000
print(f'About to download pairs: {PAIRS} to {dl_path}')
# Init exchange
@ -38,7 +160,6 @@ exchange._API = exchange.init_ccxt({'key': '',
'secret': '',
'name': args.exchange})
for pair in PAIRS:
for tick_interval in TICKER_INTERVALS:
print(f'downloading pair {pair}, interval {tick_interval}')

View File

@ -10,6 +10,23 @@ Optional Cli parameters
-d / --datadir: path to pair backtest data
--timerange: specify what timerange of data to use.
-l / --live: Live, to download the latest ticker for the pair
-db / --db-url: Show trades stored in database
--plot-max-ticks N: plot N data points and overwrite the internal 750 cut of
Plotting Subplots, require the name of the dataframe column.
Each plot will be displayed as usual on exchanges
--plot-rsi <RSI>
--plot-cci <CCI>
--plot-osc <CCI>
--plot-macd <MACD>
--plot-cmf <CMF>
--
"""
import datetime
import logging
@ -21,14 +38,26 @@ import plotly.graph_objs as go
from plotly import tools
from plotly.offline import plot
from typing import Dict, List, Any
from sqlalchemy import create_engine
import freqtrade.optimize as optimize
from freqtrade import exchange
from freqtrade.analyze import Analyze
from freqtrade.arguments import Arguments
from freqtrade.analyze import Analyze
from freqtrade import exchange
import freqtrade.optimize as optimize
from freqtrade import persistence
from freqtrade.persistence import Trade
from freqtrade.configuration import Configuration
from pandas import DataFrame
logger = logging.getLogger(__name__)
_CONF: Dict[str, Any] = {}
logger = logging.getLogger('freqtrade')
def plot_dataframes_markers(data, fig, args):
"""
plots additional dataframe markers in the main plot
@ -40,7 +69,7 @@ def plot_dataframes_markers(data, fig, args):
if args.plotdataframemarker:
for x in args.plotdataframemarker:
filter = data[(data[x] == 100 ) | (data[x] == -100) ]
filter = data[(data[x] == 100) | (data[x] == -100)]
marker = go.Scatter(
x=filter.date,
y=filter.low * 0.99,
@ -114,6 +143,103 @@ def plot_rsi_dataframe(data, fig, args, plotnumber):
rsi = go.Scattergl(x=data['date'], y=data[x], name=x)
fig.append_trace(rsi, plotnumber, 1)
fig['layout']['shapes'].append(
{
'yref': 'y' + str(plotnumber),
'fillcolor': 'red',
'opacity': 0.1,
'type': 'rect',
'x0': DataFrame.min(data['date']),
'x1': DataFrame.max(data['date']),
'y0': 70,
'y1': 100,
'line': {'color': 'gray'}
}
)
fig['layout']['shapes'].append(
{
'yref': 'y' + str(plotnumber),
'fillcolor': 'green',
'opacity': 0.1,
'type': 'rect',
'x0': DataFrame.min(data['date']),
'x1': DataFrame.max(data['date']),
'y0': 0,
'y1': 30,
'line': {'color': 'gray'}
}
)
def plot_osc_dataframe(data, fig, args, plotnumber):
"""
this function plots an additional cci chart under the exiting charts
:param data:
:param fig:
:param args:
:return:
"""
if args.plotosc:
for x in args.plotosc:
chart = go.Scattergl(x=data['date'], y=data[x], name=x)
fig.append_trace(chart, plotnumber, 1)
fig['layout']['shapes'].append(
{
'yref': 'y' + str(plotnumber),
'fillcolor': 'gray',
'opacity': 0.1,
'type': 'rect',
'x0': DataFrame.min(data['date']),
'x1': DataFrame.max(data['date']),
'y0': 0.3,
'y1': 0.7,
'line': {'color': 'gray'}
}
)
fig['layout']['shapes'].append(
{
'yref': 'y' + str(plotnumber),
'type': 'line',
'x0': DataFrame.min(data['date']),
'x1': DataFrame.max(data['date']),
'y0': 0.6,
'y1': 0.6,
'line': {'color': 'red','width': 1}
}
)
fig['layout']['shapes'].append(
{
'yref': 'y' + str(plotnumber),
'type': 'line',
'x0': DataFrame.min(data['date']),
'x1': DataFrame.max(data['date']),
'y0': 0.4,
'y1': 0.4,
'line': {'color': 'green','width':1}
}
)
def plot_cmf_dataframe(data, fig, args, plotnumber):
"""
this function plots an additional cci chart under the exiting charts
:param data:
:param fig:
:param args:
:return:
"""
minValue = 0;
maxValue = 0;
if args.plotcmf:
for x in args.plotcmf:
chart = go.Bar(x=data['date'], y=data[x], name=x)
fig.append_trace(chart, plotnumber, 1)
def plot_cci_dataframe(data, fig, args, plotnumber):
"""
@ -124,11 +250,45 @@ def plot_cci_dataframe(data, fig, args, plotnumber):
:param args:
:return:
"""
minValue = 0;
maxValue = 0;
if args.plotcci:
for x in args.plotcci:
if minValue > min(data[x]):
minValue = min(data[x])
if maxValue < max(data[x]):
maxValue = max(data[x])
chart = go.Scattergl(x=data['date'], y=data[x], name=x)
fig.append_trace(chart, plotnumber, 1)
fig['layout']['shapes'].append(
{
'yref': 'y' + str(plotnumber),
'fillcolor': 'red',
'opacity': 0.1,
'type': 'rect',
'x0': DataFrame.min(data['date']),
'x1': DataFrame.max(data['date']),
'y0': 100,
'y1': maxValue,
'line': {'color': 'gray'}
}
)
fig['layout']['shapes'].append(
{
'yref': 'y' + str(plotnumber),
'fillcolor': 'green',
'opacity': 0.1,
'type': 'rect',
'x0': DataFrame.min(data['date']),
'x1': DataFrame.max(data['date']),
'y0': -100,
'y1': minValue,
'line': {'color': 'gray'}
}
)
def plot_stop_loss_trade(df_sell, fig, analyze, args):
@ -271,6 +431,15 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
if len(dataframe.index) > args.plotticks:
logger.warning('Ticker contained more than {} candles, clipping.'.format(args.plotticks))
data = dataframe.tail(args.plotticks)
trades = []
if args.db_url:
engine = create_engine('sqlite:///' + args.db_url)
persistence.init(_CONF, engine)
trades = Trade.query.filter(Trade.pair.is_(pair)).all()
if len(dataframe.index) > 750:
logger.warning('Ticker contained more than 750 candles, clipping.')
data = dataframe.tail(750)
candles = go.Candlestick(
x=data.date,
@ -285,7 +454,7 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
buys = go.Scattergl(
x=df_buy.date,
y=df_buy.close * 0.995,
y=df_buy.close,
mode='markers',
name='buy',
marker=dict(
@ -299,7 +468,7 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
sells = go.Scatter(
x=df_sell.date,
y=df_sell.close * 1.01,
y=df_sell.close,
mode='markers+text',
name='sell',
text=df_sell.profit,
@ -313,6 +482,31 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
)
trade_buys = go.Scattergl(
x=[t.open_date.isoformat() for t in trades],
y=[t.open_rate for t in trades],
mode='markers',
name='trade_buy',
marker=dict(
symbol='square-open',
size=11,
line=dict(width=2),
color='green'
)
)
trade_sells = go.Scattergl(
x=[t.close_date.isoformat() for t in trades],
y=[t.close_rate for t in trades],
mode='markers',
name='trade_sell',
marker=dict(
symbol='square-open',
size=11,
line=dict(width=2),
color='red'
)
)
bb_lower = go.Scatter(
x=data.date,
y=data.bb_lowerband,
@ -346,6 +540,10 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
rowWidth.append(1)
if args.plotcci:
rowWidth.append(1)
if args.plotcmf:
rowWidth.append(1)
if args.plotosc:
rowWidth.append(1)
# standard layout signal + volume
fig = tools.make_subplots(
@ -397,6 +595,16 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
plot_cci_dataframe(data, fig, args, subplots)
fig['layout']['yaxis' + str(subplots)].update(title='CCI')
if args.plotosc:
subplots = subplots + 1
plot_osc_dataframe(data, fig, args, subplots)
fig['layout']['yaxis' + str(subplots)].update(title='OSC')
if args.plotcmf:
subplots = subplots + 1
plot_cmf_dataframe(data, fig, args, subplots)
fig['layout']['yaxis' + str(subplots)].update(title='CMF')
# updated all the
plot(fig, filename='freqtrade-plot.html')

View File

@ -26,18 +26,18 @@ from freqtrade.configuration import Configuration
from freqtrade.analyze import Analyze
from freqtrade import constants
import freqtrade.optimize as optimize
import freqtrade.misc as misc
logger = logging.getLogger(__name__)
# data:: [ pair, profit-%, enter, exit, time, duration]
# data:: ["ETH/BTC", 0.0023975, "1515598200", "1515602100", "2018-01-10 07:30:00+00:00", 65]
def make_profit_array(
data: List, px: int, min_date: int,
interval: int, filter_pairs: Optional[List] = None) -> np.ndarray:
def make_profit_array(data: List, px: int, min_date: int,
interval: int,
filter_pairs: Optional[List] = None) -> np.ndarray:
pg = np.zeros(px)
filter_pairs = filter_pairs or []
# Go through the trades