Ejemplo n.º 1
0
    def get_statistics(self):
        """
        Returns current bot statistics in a dictionary.
        :return: Current statistics in a dictionary.
        """
        trader: SimulationTrader = self.trader
        net = trader.get_net()
        profit = trader.get_profit()

        self.percentage = trader.get_profit_percentage(trader.startingBalance, net)
        self.elapsed = helpers.get_elapsed_time(self.startingTime)
        self.set_daily_percentages(trader=trader, net=net)

        groupedDict = trader.get_grouped_statistics()
        groupedDict['general']['net'] = f'${round(net, 2)}'
        groupedDict['general']['profit'] = f'${round(profit, 2)}'
        groupedDict['general']['elapsed'] = self.elapsed
        groupedDict['general']['totalPercentage'] = f'{round(self.percentage, 2)}%'
        groupedDict['general']['dailyPercentage'] = f'{round(self.dailyPercentage, 2)}%'
        groupedDict['general']['lowerTrend'] = self.lowerTrend

        valueDict = {
            'profitLossLabel': trader.get_profit_or_loss_string(profit=profit),
            'profitLossValue': f'${abs(round(profit, 2))}',
            'percentageValue': f'{round(self.percentage, 2)}%',
            'netValue': f'${round(net, 2)}',
            'tickerValue': f'${trader.currentPrice}',
            'tickerLabel': trader.symbol,
            'currentPositionValue': trader.get_position_string(),
            'net': net,
            'price': trader.currentPrice,
        }

        return valueDict, groupedDict
Ejemplo n.º 2
0
def test_get_elapsed_time(elapsed, expected):
    assert get_elapsed_time(
        elapsed) in expected, f"Expected elapsed time to be in: {expected}."