This commit is contained in:
Janne Sinivirta 2018-01-09 12:59:06 +02:00
parent 7cdbd550c8
commit 1b6b0ad9d2
8 changed files with 115 additions and 115 deletions

View File

@ -197,11 +197,11 @@ def execute_sell(trade: Trade, limit: float) -> None:
profit_trade = trade.calc_profit(rate=limit) profit_trade = trade.calc_profit(rate=limit)
message = '*{exchange}:* Selling [{pair}]({pair_url}) with limit `{limit:.8f}`'.format( message = '*{exchange}:* Selling [{pair}]({pair_url}) with limit `{limit:.8f}`'.format(
exchange=trade.exchange, exchange=trade.exchange,
pair=trade.pair.replace('_', '/'), pair=trade.pair.replace('_', '/'),
pair_url=exchange.get_pair_detail_url(trade.pair), pair_url=exchange.get_pair_detail_url(trade.pair),
limit=limit limit=limit
) )
# For regular case, when the configuration exists # For regular case, when the configuration exists
if 'stake_currency' in _CONF and 'fiat_display_currency' in _CONF: if 'stake_currency' in _CONF and 'fiat_display_currency' in _CONF:
@ -213,12 +213,12 @@ def execute_sell(trade: Trade, limit: float) -> None:
) )
message += '` ({gain}: {profit_percent:.2f}%, {profit_coin:.8f} {coin}`' \ message += '` ({gain}: {profit_percent:.2f}%, {profit_coin:.8f} {coin}`' \
'` / {profit_fiat:.3f} {fiat})`'.format( '` / {profit_fiat:.3f} {fiat})`'.format(
gain="profit" if fmt_exp_profit > 0 else "loss", gain="profit" if fmt_exp_profit > 0 else "loss",
profit_percent=fmt_exp_profit, profit_percent=fmt_exp_profit,
profit_coin=profit_trade, profit_coin=profit_trade,
coin=_CONF['stake_currency'], coin=_CONF['stake_currency'],
profit_fiat=profit_fiat, profit_fiat=profit_fiat,
fiat=_CONF['fiat_display_currency'], fiat=_CONF['fiat_display_currency'],
) )
# Because telegram._forcesell does not have the configuration # Because telegram._forcesell does not have the configuration
# Ignore the FIAT value and does not show the stake_currency as well # Ignore the FIAT value and does not show the stake_currency as well

View File

@ -122,20 +122,20 @@ def backtest(stake_amount: float, processed: Dict[str, DataFrame],
if min_roi_reached(trade, row2.close, row2.date) or \ if min_roi_reached(trade, row2.close, row2.date) or \
(row2.sell == 1 and use_sell_signal) or \ (row2.sell == 1 and use_sell_signal) or \
current_profit_percent <= stoploss: current_profit_percent <= stoploss:
current_profit_btc = trade.calc_profit(rate=row2.close) current_profit_btc = trade.calc_profit(rate=row2.close)
lock_pair_until = row2.Index lock_pair_until = row2.Index
trades.append( trades.append(
( (
pair, pair,
current_profit_percent, current_profit_percent,
current_profit_btc, current_profit_btc,
row2.Index - row.Index, row2.Index - row.Index,
current_profit_btc > 0, current_profit_btc > 0,
current_profit_btc < 0 current_profit_btc < 0
)
) )
break )
break
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration', 'profit', 'loss'] labels = ['currency', 'profit_percent', 'profit_BTC', 'duration', 'profit', 'loss']
return DataFrame.from_records(trades, columns=labels) return DataFrame.from_records(trades, columns=labels)
@ -193,6 +193,6 @@ def start(args):
use_sell_signal=config.get('experimental', {}).get('use_sell_signal', False) use_sell_signal=config.get('experimental', {}).get('use_sell_signal', False)
) )
logger.info( logger.info(
'\n==================================== BACKTESTING REPORT ====================================\n%s', # noqa '\n==================================== BACKTESTING REPORT ====================================\n%s', # noqa
generate_text_table(data, results, config['stake_currency'], args.ticker_interval) generate_text_table(data, results, config['stake_currency'], args.ticker_interval)
) )

View File

@ -194,7 +194,7 @@ def format_results(results: DataFrame):
results.profit_percent.mean() * 100.0, results.profit_percent.mean() * 100.0,
results.profit_BTC.sum(), results.profit_BTC.sum(),
results.duration.mean() * 5, results.duration.mean() * 5,
) )
def buy_strategy_generator(params): def buy_strategy_generator(params):

View File

@ -255,7 +255,7 @@ def _daily(bot: Bot, update: Update) -> None:
), ),
symbol=_CONF['fiat_display_currency'] symbol=_CONF['fiat_display_currency']
) )
] ]
for key, value in profit_days.items() for key, value in profit_days.items()
] ]
stats = tabulate(stats, stats = tabulate(stats,

View File

@ -6,7 +6,7 @@ from shutil import copyfile
from freqtrade import exchange, optimize from freqtrade import exchange, optimize
from freqtrade.exchange import Bittrex from freqtrade.exchange import Bittrex
from freqtrade.optimize.__init__ import make_testdata_path, download_pairs,\ from freqtrade.optimize.__init__ import make_testdata_path, download_pairs,\
download_backtesting_testdata, load_tickerdata_file download_backtesting_testdata, load_tickerdata_file
# Change this if modifying BTC_UNITEST testdatafile # Change this if modifying BTC_UNITEST testdatafile
_btc_unittest_length = 13681 _btc_unittest_length = 13681

View File

@ -25,51 +25,51 @@ def whitelist_conf():
def get_market_summaries(): def get_market_summaries():
return [{ return [{
"MarketName": "BTC-TKN", "MarketName": "BTC-TKN",
"High": 0.00000919, "High": 0.00000919,
"Low": 0.00000820, "Low": 0.00000820,
"Volume": 74339.61396015, "Volume": 74339.61396015,
"Last": 0.00000820, "Last": 0.00000820,
"BaseVolume": 1664, "BaseVolume": 1664,
"TimeStamp": "2014-07-09T07:19:30.15", "TimeStamp": "2014-07-09T07:19:30.15",
"Bid": 0.00000820, "Bid": 0.00000820,
"Ask": 0.00000831, "Ask": 0.00000831,
"OpenBuyOrders": 15, "OpenBuyOrders": 15,
"OpenSellOrders": 15, "OpenSellOrders": 15,
"PrevDay": 0.00000821, "PrevDay": 0.00000821,
"Created": "2014-03-20T06:00:00", "Created": "2014-03-20T06:00:00",
"DisplayMarketName": "" "DisplayMarketName": ""
}, { }, {
"MarketName": "BTC-ETH", "MarketName": "BTC-ETH",
"High": 0.00000072, "High": 0.00000072,
"Low": 0.00000001, "Low": 0.00000001,
"Volume": 166340678.42280999, "Volume": 166340678.42280999,
"Last": 0.00000005, "Last": 0.00000005,
"BaseVolume": 42, "BaseVolume": 42,
"TimeStamp": "2014-07-09T07:21:40.51", "TimeStamp": "2014-07-09T07:21:40.51",
"Bid": 0.00000004, "Bid": 0.00000004,
"Ask": 0.00000005, "Ask": 0.00000005,
"OpenBuyOrders": 18, "OpenBuyOrders": 18,
"OpenSellOrders": 18, "OpenSellOrders": 18,
"PrevDay": 0.00000002, "PrevDay": 0.00000002,
"Created": "2014-05-30T07:57:49.637", "Created": "2014-05-30T07:57:49.637",
"DisplayMarketName": "" "DisplayMarketName": ""
}, { }, {
"MarketName": "BTC-BLK", "MarketName": "BTC-BLK",
"High": 0.00000072, "High": 0.00000072,
"Low": 0.00000001, "Low": 0.00000001,
"Volume": 166340678.42280999, "Volume": 166340678.42280999,
"Last": 0.00000005, "Last": 0.00000005,
"BaseVolume": 3, "BaseVolume": 3,
"TimeStamp": "2014-07-09T07:21:40.51", "TimeStamp": "2014-07-09T07:21:40.51",
"Bid": 0.00000004, "Bid": 0.00000004,
"Ask": 0.00000005, "Ask": 0.00000005,
"OpenBuyOrders": 18, "OpenBuyOrders": 18,
"OpenSellOrders": 18, "OpenSellOrders": 18,
"PrevDay": 0.00000002, "PrevDay": 0.00000002,
"Created": "2014-05-30T07:57:49.637", "Created": "2014-05-30T07:57:49.637",
"DisplayMarketName": "" "DisplayMarketName": ""
} }
] ]

View File

@ -624,54 +624,54 @@ def test_sell_profit_only_disable_profit(default_conf, limit_buy_order, mocker):
def test_sell_profit_only_enable_loss(default_conf, limit_buy_order, mocker): def test_sell_profit_only_enable_loss(default_conf, limit_buy_order, mocker):
default_conf['experimental'] = { default_conf['experimental'] = {
'use_sell_signal': True, 'use_sell_signal': True,
'sell_profit_only': True, 'sell_profit_only': True,
} }
mocker.patch.dict('freqtrade.main._CONF', default_conf) mocker.patch.dict('freqtrade.main._CONF', default_conf)
mocker.patch('freqtrade.main.min_roi_reached', return_value=False) mocker.patch('freqtrade.main.min_roi_reached', return_value=False)
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s, t: True) mocker.patch('freqtrade.main.get_signal', side_effect=lambda s, t: True)
mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock()) mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
mocker.patch.multiple('freqtrade.main.exchange', mocker.patch.multiple('freqtrade.main.exchange',
validate_pairs=MagicMock(), validate_pairs=MagicMock(),
get_ticker=MagicMock(return_value={ get_ticker=MagicMock(return_value={
'bid': 0.00000172, 'bid': 0.00000172,
'ask': 0.00000173, 'ask': 0.00000173,
'last': 0.00000172 'last': 0.00000172
}), }),
buy=MagicMock(return_value='mocked_limit_buy')) buy=MagicMock(return_value='mocked_limit_buy'))
init(default_conf, create_engine('sqlite://')) init(default_conf, create_engine('sqlite://'))
create_trade(0.001) create_trade(0.001)
trade = Trade.query.first() trade = Trade.query.first()
trade.update(limit_buy_order) trade.update(limit_buy_order)
assert handle_trade(trade) is False assert handle_trade(trade) is False
def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, mocker): def test_sell_profit_only_disable_loss(default_conf, limit_buy_order, mocker):
default_conf['experimental'] = { default_conf['experimental'] = {
'use_sell_signal': True, 'use_sell_signal': True,
'sell_profit_only': False, 'sell_profit_only': False,
} }
mocker.patch.dict('freqtrade.main._CONF', default_conf) mocker.patch.dict('freqtrade.main._CONF', default_conf)
mocker.patch('freqtrade.main.min_roi_reached', return_value=False) mocker.patch('freqtrade.main.min_roi_reached', return_value=False)
mocker.patch('freqtrade.main.get_signal', side_effect=lambda s, t: True) mocker.patch('freqtrade.main.get_signal', side_effect=lambda s, t: True)
mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock()) mocker.patch.multiple('freqtrade.rpc', init=MagicMock(), send_msg=MagicMock())
mocker.patch.multiple('freqtrade.main.exchange', mocker.patch.multiple('freqtrade.main.exchange',
validate_pairs=MagicMock(), validate_pairs=MagicMock(),
get_ticker=MagicMock(return_value={ get_ticker=MagicMock(return_value={
'bid': 0.00000172, 'bid': 0.00000172,
'ask': 0.00000173, 'ask': 0.00000173,
'last': 0.00000172 'last': 0.00000172
}), }),
buy=MagicMock(return_value='mocked_limit_buy')) buy=MagicMock(return_value='mocked_limit_buy'))
init(default_conf, create_engine('sqlite://')) init(default_conf, create_engine('sqlite://'))
create_trade(0.001) create_trade(0.001)
trade = Trade.query.first() trade = Trade.query.first()
trade.update(limit_buy_order) trade.update(limit_buy_order)
assert handle_trade(trade) is True assert handle_trade(trade) is True

View File

@ -8,7 +8,7 @@ import pytest
from jsonschema import ValidationError from jsonschema import ValidationError
from freqtrade.misc import throttle, parse_args, load_config,\ from freqtrade.misc import throttle, parse_args, load_config,\
parse_args_common parse_args_common
def test_throttle(): def test_throttle():