Merge pull request #2989 from hroff-1902/no-percent-1

No "percent" where "ratio" is to be used
This commit is contained in:
Matthias 2020-03-05 16:20:13 +01:00 committed by GitHub
commit 459f1aa130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 48 additions and 47 deletions

View File

@ -23,12 +23,12 @@ Sample configuration (tested using IFTTT).
"webhooksell": {
"value1": "Selling {pair}",
"value2": "limit {limit:8f}",
"value3": "profit: {profit_amount:8f} {stake_currency}"
"value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})"
},
"webhooksellcancel": {
"value1": "Cancelling Open Sell Order for {pair}",
"value2": "limit {limit:8f}",
"value3": "profit: {profit_amount:8f} {stake_currency}"
"value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})"
},
"webhookstatus": {
"value1": "Status: {status}",
@ -87,7 +87,7 @@ Possible parameters are:
* `open_rate`
* `current_rate`
* `profit_amount`
* `profit_percent`
* `profit_ratio`
* `stake_currency`
* `fiat_currency`
* `sell_reason`
@ -108,7 +108,7 @@ Possible parameters are:
* `open_rate`
* `current_rate`
* `profit_amount`
* `profit_percent`
* `profit_ratio`
* `stake_currency`
* `fiat_currency`
* `sell_reason`

View File

@ -246,7 +246,8 @@ class Edge:
# we set stake amount to an arbitrary amount.
# as it doesn't change the calculation.
# all returned values are relative. they are percentages.
# all returned values are relative.
# they are defined as ratios.
stake = 0.015
fee = self.fee
open_fee = fee / 2
@ -269,8 +270,8 @@ class Edge:
result['sell_fee'] = result['sell_sum'] * close_fee
result['sell_take'] = result['sell_sum'] - result['sell_fee']
# profit_percent
result['profit_percent'] = (result['sell_take'] - result['buy_spend']) / result['buy_spend']
# profit_ratio
result['profit_ratio'] = (result['sell_take'] - result['buy_spend']) / result['buy_spend']
# Absolute profit
result['profit_abs'] = result['sell_take'] - result['buy_spend']
@ -399,9 +400,8 @@ class Edge:
# trade opens in reality on the next candle
open_trade_index += 1
stop_price_percentage = stoploss + 1
open_price = ohlc_columns[open_trade_index, 0]
stop_price = (open_price * stop_price_percentage)
stop_price = (open_price * (stoploss + 1))
# Searching for the index where stoploss is hit
stop_index = utf1st.find_1st(
@ -441,7 +441,7 @@ class Edge:
trade = {'pair': pair,
'stoploss': stoploss,
'profit_percent': '',
'profit_ratio': '',
'profit_abs': '',
'open_time': date_column[open_trade_index],
'close_time': date_column[exit_index],

View File

@ -1043,8 +1043,8 @@ class FreqtradeBot:
profit_trade = trade.calc_profit(rate=profit_rate)
# Use cached ticker here - it was updated seconds ago.
current_rate = self.get_sell_rate(trade.pair, False)
profit_percent = trade.calc_profit_ratio(profit_rate)
gain = "profit" if profit_percent > 0 else "loss"
profit_ratio = trade.calc_profit_ratio(profit_rate)
gain = "profit" if profit_ratio > 0 else "loss"
msg = {
'type': RPCMessageType.SELL_NOTIFICATION,
@ -1057,7 +1057,7 @@ class FreqtradeBot:
'open_rate': trade.open_rate,
'current_rate': current_rate,
'profit_amount': profit_trade,
'profit_percent': profit_percent,
'profit_ratio': profit_ratio,
'sell_reason': trade.sell_reason,
'open_date': trade.open_date,
'close_date': trade.close_date or datetime.utcnow(),
@ -1080,8 +1080,8 @@ class FreqtradeBot:
profit_rate = trade.close_rate if trade.close_rate else trade.close_rate_requested
profit_trade = trade.calc_profit(rate=profit_rate)
current_rate = self.get_sell_rate(trade.pair, False)
profit_percent = trade.calc_profit_ratio(profit_rate)
gain = "profit" if profit_percent > 0 else "loss"
profit_ratio = trade.calc_profit_ratio(profit_rate)
gain = "profit" if profit_ratio > 0 else "loss"
msg = {
'type': RPCMessageType.SELL_CANCEL_NOTIFICATION,
@ -1094,7 +1094,7 @@ class FreqtradeBot:
'open_rate': trade.open_rate,
'current_rate': current_rate,
'profit_amount': profit_trade,
'profit_percent': profit_percent,
'profit_ratio': profit_ratio,
'sell_reason': trade.sell_reason,
'open_date': trade.open_date,
'close_date': trade.close_date,

View File

@ -405,8 +405,8 @@ class Trade(_DECL_BASE):
rate=(rate or self.close_rate),
fee=(fee or self.fee_close)
)
profit_percent = (close_trade_price / self.open_trade_price) - 1
return float(f"{profit_percent:.8f}")
profit_ratio = (close_trade_price / self.open_trade_price) - 1
return float(f"{profit_ratio:.8f}")
@staticmethod
def get_trades(trade_filter=None) -> Query:

View File

@ -155,9 +155,9 @@ class RPC:
current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
except DependencyException:
current_rate = NAN
trade_perc = (100 * trade.calc_profit_ratio(current_rate))
trade_percent = (100 * trade.calc_profit_ratio(current_rate))
trade_profit = trade.calc_profit(current_rate)
profit_str = f'{trade_perc:.2f}%'
profit_str = f'{trade_percent:.2f}%'
if self._fiat_converter:
fiat_profit = self._fiat_converter.convert_amount(
trade_profit,
@ -232,9 +232,9 @@ class RPC:
trades = Trade.get_trades().order_by(Trade.id).all()
profit_all_coin = []
profit_all_perc = []
profit_all_ratio = []
profit_closed_coin = []
profit_closed_perc = []
profit_closed_ratio = []
durations = []
for trade in trades:
@ -246,21 +246,21 @@ class RPC:
durations.append((trade.close_date - trade.open_date).total_seconds())
if not trade.is_open:
profit_percent = trade.calc_profit_ratio()
profit_ratio = trade.calc_profit_ratio()
profit_closed_coin.append(trade.calc_profit())
profit_closed_perc.append(profit_percent)
profit_closed_ratio.append(profit_ratio)
else:
# Get current rate
try:
current_rate = self._freqtrade.get_sell_rate(trade.pair, False)
except DependencyException:
current_rate = NAN
profit_percent = trade.calc_profit_ratio(rate=current_rate)
profit_ratio = trade.calc_profit_ratio(rate=current_rate)
profit_all_coin.append(
trade.calc_profit(rate=trade.close_rate or current_rate)
)
profit_all_perc.append(profit_percent)
profit_all_ratio.append(profit_ratio)
best_pair = Trade.get_best_pair()
@ -271,7 +271,7 @@ class RPC:
# Prepare data to display
profit_closed_coin_sum = round(sum(profit_closed_coin), 8)
profit_closed_percent = (round(mean(profit_closed_perc) * 100, 2) if profit_closed_perc
profit_closed_percent = (round(mean(profit_closed_ratio) * 100, 2) if profit_closed_ratio
else 0.0)
profit_closed_fiat = self._fiat_converter.convert_amount(
profit_closed_coin_sum,
@ -280,7 +280,7 @@ class RPC:
) if self._fiat_converter else 0
profit_all_coin_sum = round(sum(profit_all_coin), 8)
profit_all_percent = round(mean(profit_all_perc) * 100, 2) if profit_all_perc else 0.0
profit_all_percent = round(mean(profit_all_ratio) * 100, 2) if profit_all_ratio else 0.0
profit_all_fiat = self._fiat_converter.convert_amount(
profit_all_coin_sum,
stake_currency,

View File

@ -148,7 +148,7 @@ class Telegram(RPC):
elif msg['type'] == RPCMessageType.SELL_NOTIFICATION:
msg['amount'] = round(msg['amount'], 8)
msg['profit_percent'] = round(msg['profit_percent'] * 100, 2)
msg['profit_percent'] = round(msg['profit_ratio'] * 100, 2)
msg['duration'] = msg['close_date'].replace(
microsecond=0) - msg['open_date'].replace(microsecond=0)
msg['duration_min'] = msg['duration'].total_seconds() / 60

View File

@ -364,7 +364,7 @@ class IStrategy(ABC):
"""
Based on current profit of the trade and configured (trailing) stoploss,
decides to sell or not
:param current_profit: current profit in percent
:param current_profit: current profit as ratio
"""
stop_loss_value = force_stoploss if force_stoploss else self.stoploss
@ -427,8 +427,9 @@ class IStrategy(ABC):
def min_roi_reached(self, trade: Trade, current_profit: float, current_time: datetime) -> bool:
"""
Based on trade duration, current price and ROI configuration, decides whether bot should
sell. Requires current_profit to be in percent!!
Based on trade duration, current profit of the trade and ROI configuration,
decides whether bot should sell.
:param current_profit: current profit as ratio
:return: True if bot should sell at current rate
"""
# Check if time matches and current rate is above threshold

View File

@ -158,7 +158,7 @@ def test_edge_results(edge_conf, mocker, caplog, data) -> None:
assert len(trades) == len(data.trades)
if not results.empty:
assert round(results["profit_percent"].sum(), 3) == round(data.profit_perc, 3)
assert round(results["profit_ratio"].sum(), 3) == round(data.profit_perc, 3)
for c, trade in enumerate(data.trades):
res = results.iloc[c]

View File

@ -726,7 +726,7 @@ def test_forcesell_handle(default_conf, update, ticker, fee,
'open_rate': 1.098e-05,
'current_rate': 1.173e-05,
'profit_amount': 6.314e-05,
'profit_percent': 0.0629778,
'profit_ratio': 0.0629778,
'stake_currency': 'BTC',
'fiat_currency': 'USD',
'sell_reason': SellType.FORCE_SELL.value,
@ -785,7 +785,7 @@ def test_forcesell_down_handle(default_conf, update, ticker, fee,
'open_rate': 1.098e-05,
'current_rate': 1.043e-05,
'profit_amount': -5.497e-05,
'profit_percent': -0.05482878,
'profit_ratio': -0.05482878,
'stake_currency': 'BTC',
'fiat_currency': 'USD',
'sell_reason': SellType.FORCE_SELL.value,
@ -833,7 +833,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, mocker) -> None
'open_rate': 1.098e-05,
'current_rate': 1.099e-05,
'profit_amount': -4.09e-06,
'profit_percent': -0.00408133,
'profit_ratio': -0.00408133,
'stake_currency': 'BTC',
'fiat_currency': 'USD',
'sell_reason': SellType.FORCE_SELL.value,
@ -1253,7 +1253,7 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
'open_rate': 7.5e-05,
'current_rate': 3.201e-05,
'profit_amount': -0.05746268,
'profit_percent': -0.57405275,
'profit_ratio': -0.57405275,
'stake_currency': 'ETH',
'fiat_currency': 'USD',
'sell_reason': SellType.STOP_LOSS.value,
@ -1282,7 +1282,7 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
'open_rate': 7.5e-05,
'current_rate': 3.201e-05,
'profit_amount': -0.05746268,
'profit_percent': -0.57405275,
'profit_ratio': -0.57405275,
'stake_currency': 'ETH',
'sell_reason': SellType.STOP_LOSS.value,
'open_date': arrow.utcnow().shift(days=-1, hours=-2, minutes=-30),
@ -1448,7 +1448,7 @@ def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None:
'open_rate': 7.5e-05,
'current_rate': 3.201e-05,
'profit_amount': -0.05746268,
'profit_percent': -0.57405275,
'profit_ratio': -0.57405275,
'stake_currency': 'ETH',
'fiat_currency': 'USD',
'sell_reason': SellType.STOP_LOSS.value,

View File

@ -28,12 +28,12 @@ def get_webhook_dict() -> dict:
"webhooksell": {
"value1": "Selling {pair}",
"value2": "limit {limit:8f}",
"value3": "profit: {profit_amount:8f} {stake_currency}"
"value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})"
},
"webhooksellcancel": {
"value1": "Cancelling Open Sell Order for {pair}",
"value2": "limit {limit:8f}",
"value3": "profit: {profit_amount:8f} {stake_currency}"
"value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})"
},
"webhookstatus": {
"value1": "Status: {status}",
@ -110,7 +110,7 @@ def test_send_msg(default_conf, mocker):
'open_rate': 0.004,
'current_rate': 0.005,
'profit_amount': 0.001,
'profit_percent': 0.20,
'profit_ratio': 0.20,
'stake_currency': 'BTC',
'sell_reason': SellType.STOP_LOSS.value
}
@ -136,7 +136,7 @@ def test_send_msg(default_conf, mocker):
'open_rate': 0.004,
'current_rate': 0.005,
'profit_amount': 0.001,
'profit_percent': 0.20,
'profit_ratio': 0.20,
'stake_currency': 'BTC',
'sell_reason': SellType.STOP_LOSS.value
}

View File

@ -2314,7 +2314,7 @@ def test_execute_sell_up(default_conf, ticker, fee, ticker_sell_up, mocker) -> N
'open_rate': 1.098e-05,
'current_rate': 1.173e-05,
'profit_amount': 6.223e-05,
'profit_percent': 0.0620716,
'profit_ratio': 0.0620716,
'stake_currency': 'BTC',
'fiat_currency': 'USD',
'sell_reason': SellType.ROI.value,
@ -2363,7 +2363,7 @@ def test_execute_sell_down(default_conf, ticker, fee, ticker_sell_down, mocker)
'open_rate': 1.098e-05,
'current_rate': 1.043e-05,
'profit_amount': -5.406e-05,
'profit_percent': -0.05392257,
'profit_ratio': -0.05392257,
'stake_currency': 'BTC',
'fiat_currency': 'USD',
'sell_reason': SellType.STOP_LOSS.value,
@ -2419,7 +2419,7 @@ def test_execute_sell_down_stoploss_on_exchange_dry_run(default_conf, ticker, fe
'open_rate': 1.098e-05,
'current_rate': 1.043e-05,
'profit_amount': -1.408e-05,
'profit_percent': -0.01404051,
'profit_ratio': -0.01404051,
'stake_currency': 'BTC',
'fiat_currency': 'USD',
'sell_reason': SellType.STOP_LOSS.value,
@ -2619,7 +2619,7 @@ def test_execute_sell_market_order(default_conf, ticker, fee,
'open_rate': 1.098e-05,
'current_rate': 1.173e-05,
'profit_amount': 6.223e-05,
'profit_percent': 0.0620716,
'profit_ratio': 0.0620716,
'stake_currency': 'BTC',
'fiat_currency': 'USD',
'sell_reason': SellType.ROI.value,