Ejemplo n.º 1
0
    def save(self):
        """
        :return: void
            Saves app data to local config file
        """

        write_dicts_to_json(self.data, self.config_file)
Ejemplo n.º 2
0
def download_prices(coins, since, until, where_to, verbose, currency="USD",
                    tor=False):
    """
    :param coins: [] of str
        List of coins to fetch
    :param since: datetime
            Get data since this date
    :param until: datetime
        Get data until this date
    :param where_to: str
        Save data here
    :param verbose: bool
        True iff you want verbose output
    :param currency: str
        Currency to get price on
    :param tor: str or None
        Connect to tor proxy with this password
    :return: void
        Downloads price and saves results
    """

    if verbose:
        print("Getting historical price for", len(coins), "coins")

    output_file = os.path.join(where_to, currency.lower() + ".json")
    dates = list(generate_dates(since, until, 24))
    data = get_price_on_dates(coins, currency, dates, tor)
    if data:
        write_dicts_to_json(data, output_file)

    if verbose:
        print("Saved historical price to", output_file)
Ejemplo n.º 3
0
    def save_data(self):
        """
        :return: void
            Saves transactions to file
        """

        if self.transactions:
            self.log("saving data")
            write_dicts_to_json(self.transactions, self.output_file)
Ejemplo n.º 4
0
    def create_config(self):
        """
        :return: void
            Creates config file
        """

        if os.path.exists(self.config_file):
            raise ValueError("Creating new config will erase previous data!")

        write_dicts_to_json({}, self.config_file)  # empty data
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)
Ejemplo n.º 6
0
def download_market_cap(since, until, where_to, verbose):
    """
    :param since: datetime
            Get data since this date
    :param until: datetime
        Get data until this date
    :param where_to: str
        Save data here
    :param verbose: bool
        True iff you want verbose output
    :return: void
        Downloads market cap data and saves results
    """

    if verbose:
        print("Getting market cap since", since, "until", until)

    output_file = os.path.join(where_to, "market_cap.json")
    data = get_market_cap(since, until)
    if data:
        write_dicts_to_json(data, output_file)

    if verbose:
        print("Saved market cap data to", output_file)