Make plot_dataframe able to show trades stored in database. (#692)
* Show trades stored in db on the graph
This commit is contained in:
parent
1cc132afe2
commit
0c051b1b7a
@ -43,6 +43,10 @@ python scripts/plot_dataframe.py -p BTC_ETH --timerange=100-200
|
|||||||
```
|
```
|
||||||
Timerange doesn't work with live data.
|
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
|
## Plot profit
|
||||||
|
|
||||||
|
@ -260,6 +260,13 @@ class Arguments(object):
|
|||||||
default=None
|
default=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.parser.add_argument(
|
||||||
|
'-db', '--db-url',
|
||||||
|
help='Show trades stored in database.',
|
||||||
|
dest='db_url',
|
||||||
|
default=None
|
||||||
|
)
|
||||||
|
|
||||||
def testdata_dl_options(self) -> None:
|
def testdata_dl_options(self) -> None:
|
||||||
"""
|
"""
|
||||||
Parses given arguments for testdata download
|
Parses given arguments for testdata download
|
||||||
|
@ -10,6 +10,7 @@ Optional Cli parameters
|
|||||||
-d / --datadir: path to pair backtest data
|
-d / --datadir: path to pair backtest data
|
||||||
--timerange: specify what timerange of data to use.
|
--timerange: specify what timerange of data to use.
|
||||||
-l / --live: Live, to download the latest ticker for the pair
|
-l / --live: Live, to download the latest ticker for the pair
|
||||||
|
-db / --db-url: Show trades stored in database
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
@ -21,13 +22,18 @@ from plotly import tools
|
|||||||
from plotly.offline import plot
|
from plotly.offline import plot
|
||||||
import plotly.graph_objs as go
|
import plotly.graph_objs as go
|
||||||
|
|
||||||
|
from typing import Dict, List, Any
|
||||||
|
from sqlalchemy import create_engine
|
||||||
|
|
||||||
from freqtrade.arguments import Arguments
|
from freqtrade.arguments import Arguments
|
||||||
from freqtrade.analyze import Analyze
|
from freqtrade.analyze import Analyze
|
||||||
from freqtrade import exchange
|
from freqtrade import exchange
|
||||||
import freqtrade.optimize as optimize
|
import freqtrade.optimize as optimize
|
||||||
|
from freqtrade import persistence
|
||||||
|
from freqtrade.persistence import Trade
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
_CONF: Dict[str, Any] = {}
|
||||||
|
|
||||||
def plot_analyzed_dataframe(args: Namespace) -> None:
|
def plot_analyzed_dataframe(args: Namespace) -> None:
|
||||||
"""
|
"""
|
||||||
@ -68,6 +74,12 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
|
|||||||
dataframe = analyze.populate_buy_trend(dataframe)
|
dataframe = analyze.populate_buy_trend(dataframe)
|
||||||
dataframe = analyze.populate_sell_trend(dataframe)
|
dataframe = analyze.populate_sell_trend(dataframe)
|
||||||
|
|
||||||
|
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:
|
if len(dataframe.index) > 750:
|
||||||
logger.warning('Ticker contained more than 750 candles, clipping.')
|
logger.warning('Ticker contained more than 750 candles, clipping.')
|
||||||
data = dataframe.tail(750)
|
data = dataframe.tail(750)
|
||||||
@ -108,6 +120,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(
|
bb_lower = go.Scatter(
|
||||||
x=data.date,
|
x=data.date,
|
||||||
y=data.bb_lowerband,
|
y=data.bb_lowerband,
|
||||||
@ -142,6 +179,8 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
|
|||||||
fig.append_trace(volume, 2, 1)
|
fig.append_trace(volume, 2, 1)
|
||||||
fig.append_trace(macd, 3, 1)
|
fig.append_trace(macd, 3, 1)
|
||||||
fig.append_trace(macdsignal, 3, 1)
|
fig.append_trace(macdsignal, 3, 1)
|
||||||
|
fig.append_trace(trade_buys, 1, 1)
|
||||||
|
fig.append_trace(trade_sells, 1, 1)
|
||||||
|
|
||||||
fig['layout'].update(title=args.pair)
|
fig['layout'].update(title=args.pair)
|
||||||
fig['layout']['yaxis1'].update(title='Price')
|
fig['layout']['yaxis1'].update(title='Price')
|
||||||
|
Loading…
Reference in New Issue
Block a user