Ejemplo n.º 1
0
    def get_prices_by_date(self, coins, dates, **kwargs):
        """
        :param coins: [] of str
            List of coins
        :param dates: [] of datetime
            Dates and times to get price
        :param kwargs: **
            Extra args
        :return: [] of {}
            Price of coins at specified date and time
        """

        start_time = time.time()
        dates = list(dates)
        prices = []
        for i, date in enumerate(dates):
            try:
                new_prices = self.get_price(coins, date, **kwargs)
                new_prices[DATE_TIME_KEY] = datetime_to_str(date)
                prices.append(new_prices)

                self.log("got price up to", date)
                print_time_eta(get_time_eta(i + 1, len(dates), start_time))
            except:
                print("Failed getting price for", date)
        return prices
Ejemplo n.º 2
0
    def save_time_update(self):
        """
        :return: void
            Saves last time of update to config file
        """

        self.last_update = datetime.now()
        self.data["last_update"] = datetime_to_str(self.last_update)
        self.save()
Ejemplo n.º 3
0
    def get_market_cap(self, since, until):
        """
        :param since: datetime
            Get data since this date
        :param until: datetime
            Get data until this date
        :return: {} <datetime -> float>
            Each dict key is date and its value is the market cap at the date
        """

        raw_data = self.download(self._create_url("marketcap", since, until))
        data = raw_data["market_cap_by_available_supply"]
        data = [{
            DATE_TIME_KEY:
            datetime_to_str(unix_timestamp_ms_to_datetime(item[0])),
            VALUE_KEY:
            float(item[1])
        } for item in data]
        return data
Ejemplo n.º 4
0
    def run(self):
        """
        :return: void
            Updates each client and saves data
        """

        interval = self.manager.update_interval().total_seconds()
        threading.Timer(interval, self.run).start()

        if self.verbose:
            print("Updating local data...")

        for updater in self.api_updaters:
            try:
                updater.update(self.verbose)
            except:
                print("Cannot update", get_actual_class_name(updater))

        self.manager.save_time_update()
        print("Next update:", datetime_to_str(self.manager.time_next_update()))
Ejemplo n.º 5
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)