Beispiel #1
0
    def _rpc_status_table(self, stake_currency,
                          fiat_display_currency: str) -> Tuple[List, List]:
        trades = Trade.get_open_trades()
        if not trades:
            raise RPCException('no active order')
        else:
            trades_list = []
            for trade in trades:
                # calculate profit and send message to user
                try:
                    current_rate = self._freqtrade.get_sell_rate(
                        trade.pair, False)
                except DependencyException:
                    current_rate = NAN
                trade_perc = (100 * trade.calc_profit_percent(current_rate))
                trade_profit = trade.calc_profit(current_rate)
                profit_str = f'{trade_perc:.2f}%'
                if self._fiat_converter:
                    fiat_profit = self._fiat_converter.convert_amount(
                        trade_profit, stake_currency, fiat_display_currency)
                    if fiat_profit and not isnan(fiat_profit):
                        profit_str += f" ({fiat_profit:.2f})"
                trades_list.append([
                    trade.id, trade.pair,
                    shorten_date(
                        arrow.get(
                            trade.open_date).humanize(only_distance=True)),
                    profit_str
                ])
            profitcol = "Profit"
            if self._fiat_converter:
                profitcol += " (" + fiat_display_currency + ")"

            columns = ['ID', 'Pair', 'Since', profitcol]
            return trades_list, columns
Beispiel #2
0
    def _rpc_status_table(self) -> DataFrame:
        trades = Trade.get_open_trades()
        if not trades:
            raise RPCException('no active order')
        else:
            trades_list = []
            for trade in trades:
                # calculate profit and send message to user
                try:
                    current_rate = self._freqtrade.get_sell_rate(
                        trade.pair, False)
                except DependencyException:
                    current_rate = NAN
                trade_perc = (100 * trade.calc_profit_percent(current_rate))
                trades_list.append([
                    trade.id, trade.pair,
                    shorten_date(
                        arrow.get(
                            trade.open_date).humanize(only_distance=True)),
                    f'{trade_perc:.2f}%'
                ])

            columns = ['ID', 'Pair', 'Since', 'Profit']
            df_statuses = DataFrame.from_records(trades_list, columns=columns)
            df_statuses = df_statuses.set_index(columns[0])
            return df_statuses
Beispiel #3
0
    def rpc_status_table(self) -> Tuple[bool, Any]:
        trades = Trade.query.filter(Trade.is_open.is_(True)).all()
        if self.freqtrade.state != State.RUNNING:
            return True, '*Status:* `trader is not running`'
        elif not trades:
            return True, '*Status:* `no active order`'
        else:
            trades_list = []
            for trade in trades:
                # calculate profit and send message to user
                current_rate = exchange.get_ticker(trade.pair, False)['bid']
                trades_list.append([
                    trade.id, trade.pair,
                    shorten_date(
                        arrow.get(
                            trade.open_date).humanize(only_distance=True)),
                    '{:.2f}%'.format(100 *
                                     trade.calc_profit_percent(current_rate))
                ])

            columns = ['ID', 'Pair', 'Since', 'Profit']
            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
            # consisting of (error_occured?, result)
            # Another approach would be to just return the
            # result, or raise error
            return False, df_statuses
Beispiel #4
0
    def _rpc_status_table(self) -> DataFrame:
        trades = Trade.query.filter(Trade.is_open.is_(True)).all()
        if self._freqtrade.state != State.RUNNING:
            raise RPCException('trader is not running')
        elif not trades:
            raise RPCException('no active order')
        else:
            trades_list = []
            for trade in trades:
                # calculate profit and send message to user
                current_rate = self._freqtrade.exchange.get_ticker(
                    trade.pair, False)['bid']
                trade_perc = (100 * trade.calc_profit_percent(current_rate))
                trades_list.append([
                    trade.id, trade.pair,
                    shorten_date(
                        arrow.get(
                            trade.open_date).humanize(only_distance=True)),
                    f'{trade_perc:.2f}%'
                ])

            columns = ['ID', 'Pair', 'Since', 'Profit']
            df_statuses = DataFrame.from_records(trades_list, columns=columns)
            df_statuses = df_statuses.set_index(columns[0])
            return df_statuses
Beispiel #5
0
def test_shorten_date() -> None:
    """
    Test shorten_date() function
    :return: None
    """
    str_data = '1 day, 2 hours, 3 minutes, 4 seconds ago'
    str_shorten_data = '1 d, 2 h, 3 min, 4 sec ago'
    assert shorten_date(str_data) == str_shorten_data
Beispiel #6
0
    def _rpc_status_table(self, stake_currency: str,
                          fiat_display_currency: str) -> Tuple[List, List, float]:
        trades: List[Trade] = Trade.get_open_trades()
        nonspot = self._config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT
        if not trades:
            raise RPCException('no active trade')
        else:
            trades_list = []
            fiat_profit_sum = NAN
            for trade in trades:
                # calculate profit and send message to user
                try:
                    current_rate = self._freqtrade.exchange.get_rate(
                        trade.pair, side='exit', is_short=trade.is_short, refresh=False)
                except (PricingError, ExchangeError):
                    current_rate = NAN
                trade_profit = trade.calc_profit(current_rate)
                profit_str = f'{trade.calc_profit_ratio(current_rate):.2%}'
                direction_str = ('S' if trade.is_short else 'L') if nonspot else ''
                if self._fiat_converter:
                    fiat_profit = self._fiat_converter.convert_amount(
                        trade_profit,
                        stake_currency,
                        fiat_display_currency
                    )
                    if fiat_profit and not isnan(fiat_profit):
                        profit_str += f" ({fiat_profit:.2f})"
                        fiat_profit_sum = fiat_profit if isnan(fiat_profit_sum) \
                            else fiat_profit_sum + fiat_profit
                detail_trade = [
                    f'{trade.id} {direction_str}',
                    trade.pair + ('*' if (trade.open_order_id is not None
                                          and trade.close_rate_requested is None) else '')
                    + ('**' if (trade.close_rate_requested is not None) else ''),
                    shorten_date(arrow.get(trade.open_date).humanize(only_distance=True)),
                    profit_str
                ]
                if self._config.get('position_adjustment_enable', False):
                    max_entry_str = ''
                    if self._config.get('max_entry_position_adjustment', -1) > 0:
                        max_entry_str = f"/{self._config['max_entry_position_adjustment'] + 1}"
                    filled_entries = trade.nr_of_successful_entries
                    detail_trade.append(f"{filled_entries}{max_entry_str}")
                trades_list.append(detail_trade)
            profitcol = "Profit"
            if self._fiat_converter:
                profitcol += " (" + fiat_display_currency + ")"

            columns = [
                'ID L/S' if nonspot else 'ID',
                'Pair',
                'Since',
                profitcol]
            if self._config.get('position_adjustment_enable', False):
                columns.append('# Entries')
            return trades_list, columns, fiat_profit_sum
Beispiel #7
0
    def _rpc_status_table(self, stake_currency: str,
                          fiat_display_currency: str) -> Tuple[List, List, float]:
        trades = Trade.get_open_trades()
        if not trades:
            raise RPCException('no active trade')
        else:
            trades_list = []
            fiat_profit_sum = NAN
            for trade in trades:
                # calculate profit and send message to user
                try:
                    current_rate = self._freqtrade.exchange.get_rate(
                        trade.pair, refresh=False, side="sell")
                except (PricingError, ExchangeError):
                    current_rate = NAN
                trade_profit = trade.calc_profit(current_rate)
                profit_str = f'{trade.calc_profit_ratio(current_rate):.2%}'
                if self._fiat_converter:
                    fiat_profit = self._fiat_converter.convert_amount(
                        trade_profit,
                        stake_currency,
                        fiat_display_currency
                    )
                    if fiat_profit and not isnan(fiat_profit):
                        profit_str += f" ({fiat_profit:.2f})"
                        fiat_profit_sum = fiat_profit if isnan(fiat_profit_sum) \
                            else fiat_profit_sum + fiat_profit
                detail_trade = [
                    trade.id,
                    trade.pair + ('*' if (trade.open_order_id is not None
                                          and trade.close_rate_requested is None) else '')
                    + ('**' if (trade.close_rate_requested is not None) else ''),
                    shorten_date(arrow.get(trade.open_date).humanize(only_distance=True)),
                    profit_str
                ]
                if self._config.get('position_adjustment_enable', False):
                    filled_buys = trade.select_filled_orders('buy')
                    detail_trade.append(str(len(filled_buys)))
                trades_list.append(detail_trade)
            profitcol = "Profit"
            if self._fiat_converter:
                profitcol += " (" + fiat_display_currency + ")"

            if self._config.get('position_adjustment_enable', False):
                columns = ['ID', 'Pair', 'Since', profitcol, '# Buys']
            else:
                columns = ['ID', 'Pair', 'Since', profitcol]
            return trades_list, columns, fiat_profit_sum
Beispiel #8
0
    def _rpc_status_table(
            self, stake_currency: str,
            fiat_display_currency: str) -> Tuple[List, List, float]:
        trades = Trade.get_open_trades()
        if not trades:
            raise RPCException('no active trade')
        else:
            trades_list = []
            fiat_profit_sum = NAN
            for trade in trades:
                # calculate profit and send message to user
                try:
                    current_rate = self._freqtrade.exchange.get_sell_rate(
                        trade.pair, False)
                except (PricingError, ExchangeError):
                    current_rate = NAN
                trade_percent = (100 * trade.calc_profit_ratio(current_rate))
                trade_profit = trade.calc_profit(current_rate)
                profit_str = f'{trade_percent:.2f}%'
                if self._fiat_converter:
                    fiat_profit = self._fiat_converter.convert_amount(
                        trade_profit, stake_currency, fiat_display_currency)
                    if fiat_profit and not isnan(fiat_profit):
                        profit_str += f" ({fiat_profit:.2f})"
                        fiat_profit_sum = fiat_profit if isnan(fiat_profit_sum) \
                            else fiat_profit_sum + fiat_profit
                trades_list.append([
                    trade.id, trade.pair +
                    ('*' if (trade.open_order_id is not None
                             and trade.close_rate_requested is None) else '') +
                    ('**' if (trade.close_rate_requested is not None) else ''),
                    shorten_date(
                        arrow.get(
                            trade.open_date).humanize(only_distance=True)),
                    profit_str
                ])
            profitcol = "Profit"
            if self._fiat_converter:
                profitcol += " (" + fiat_display_currency + ")"

            columns = ['ID', 'Pair', 'Since', profitcol]
            return trades_list, columns, fiat_profit_sum
Beispiel #9
0
def test_shorten_date() -> None:
    str_data = '1 day, 2 hours, 3 minutes, 4 seconds ago'
    str_shorten_data = '1 d, 2 h, 3 min, 4 sec ago'
    assert shorten_date(str_data) == str_shorten_data