Exemple #1
0
    def sum_total_balance(balances):
        """
        :param balances: [] of {}
            List of raw balances
        :return: float
            Total balance (without counting NaN values)
        """

        if isinstance(balances, dict):
            return Portfolio.sum_total_balance(balances.values())

        return sum([
            balance[VALUE_KEY] for balance in balances
            if isinstance(balance, dict) and not is_nan(balance[VALUE_KEY])
        ])
Exemple #2
0
    def get_balance_array_by_date(self, dates, currency=None):
        """
        :param dates: [] of datetime
            List of dates
        :param currency: str or None
            Currency to convert balances to
        :return: numpy array
            Balance value by date
        """

        balances = self.get_data_by_date("balance", dates, currency)
        lst = np.zeros(len(balances))
        for i, balance in enumerate(balances):
            if not is_nan(balance):
                lst[i] += balance
        return lst
Exemple #3
0
def save_balance(balances, output_file, timestamp=datetime.now()):
    """
    :param balances: [] of {}
        List of balanced for each wallet
    :param output_file: str
        Path to save data to
    :param timestamp: datetime
        Time of log
    :return: void
        Saves data to file
    """

    balances = [
        balance for balance in balances if not is_nan(balance[VALUE_KEY])
    ]  # do not save
    data = {}
    for balance in balances:  # lst -> dict
        data[balance["symbol"]] = balance
    data[DATE_TIME_KEY] = datetime_to_str(timestamp)
    write_dicts_to_json(data, output_file)