def call_load(self, other_args): """Process load command""" try: self.current_coin, self.source = load(coin=self.current_coin, other_args=other_args) except TypeError: print("Couldn't load data\n")
def get_bitcoin(mock_load): # pylint: disable=unused-argument print(os.getcwd()) with open("tests/data/btc_usd_test_data.json", encoding="utf8") as f: sample_return = json.load(f) mock_load.return_value = sample_return coin, _ = load(coin="bitcoin", source="cg") return coin
def call_load(self, other_args): """Process load command""" try: parser = argparse.ArgumentParser( add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="load", description="Load crypto currency to perform analysis on. " "Available data sources are CoinGecko, CoinPaprika, Binance, Coinbase" "By default main source used for analysis is CoinGecko (cg). To change it use --source flag", ) parser.add_argument( "-c", "--coin", help="Coin to get", dest="coin", type=str, required="-h" not in other_args, ) parser.add_argument( "-s", "--source", help="Source of data", dest="source", choices=("cp", "cg", "bin", "cb"), default="cg", required=False, ) try: if other_args: if not other_args[0][0] == "-": other_args.insert(0, "-c") ns_parser = parse_known_args_and_warn(parser, other_args) if not ns_parser: self.current_coin, self.source = self.current_coin, None return source = ns_parser.source for arg in ["--source", source]: if arg in other_args: other_args.remove(arg) self.current_coin, self.source = load(coin=ns_parser.coin, source=ns_parser.source) except Exception as e: print(e, "\n") self.current_coin, self.source = self.current_coin, None except TypeError: print("Couldn't load data\n")
def get_bitcoin(mock_load): # pylint: disable=unused-argument print(os.getcwd()) with open( "tests/gamestonk_terminal/cryptocurrency/due_diligence/json/test_pycoingecko_view/btc_usd_test_data.json", encoding="utf8", ) as f: sample_return = json.load(f) mock_load.return_value = sample_return coin, _, symbol, _, _, _ = load(coin="bitcoin", source="cg") return coin, symbol
def call_load(self, other_args: List[str]): """Process load command""" parser = argparse.ArgumentParser( add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="load", description="Load crypto currency to perform analysis on. " "Available data sources are CoinGecko, CoinPaprika, Binance, Coinbase" "By default main source used for analysis is CoinGecko (cg). To change it use --source flag", ) parser.add_argument( "-c", "--coin", help="Coin to get", dest="coin", type=str, required="-h" not in other_args, ) parser.add_argument( "-s", "--source", help="Source of data", dest="source", choices=CRYPTO_SOURCES.keys(), default="cg", required=False, ) if other_args and not other_args[0][0] == "-": other_args.insert(0, "-c") ns_parser = parse_known_args_and_warn(parser, other_args) if ns_parser: source = ns_parser.source for arg in ["--source", source]: if arg in other_args: other_args.remove(arg) self.current_coin, self.source, self.symbol, self.coin_map_df, _, _ = load( coin=ns_parser.coin, source=ns_parser.source) if self.symbol: console.print( f"\nLoaded {self.current_coin} from source {self.source}\n" )
def call_load(self, other_args: List[str]): """Process load command""" parser = argparse.ArgumentParser( add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="load", description="Load crypto currency to perform analysis on." "Available data sources are CoinGecko, CoinPaprika, Binance, Coinbase" "By default main source used for analysis is CoinGecko (cg). To change it use --source flag", ) parser.add_argument( "-c", "--coin", help="Coin to get", dest="coin", type=str, required="-h" not in other_args, ) parser.add_argument( "--source", help="Source of data", dest="source", choices=("cp", "cg", "bin", "cb"), default="cg", required=False, ) parser.add_argument( "-s", "--start", type=valid_date_in_past, default=(datetime.now() - timedelta(days=366)).strftime("%Y-%m-%d"), dest="start", help="The starting date (format YYYY-MM-DD) of the crypto", ) parser.add_argument( "--vs", help="Quote currency (what to view coin vs)", dest="vs", default="usd", type=str, ) parser.add_argument( "-r", "--resolution", default="1D", type=str, dest="resolution", help="How often to resample data.", choices=c_help.INTERVALS, ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-c") ns_parser = parse_known_args_and_warn(parser, other_args) delta = (datetime.now() - ns_parser.start).days if ns_parser: source = ns_parser.source for arg in ["--source", source]: if arg in other_args: other_args.remove(arg) # self.data = c_help.load_cg_coin_data( # ns_parser.coin, ns_parser.currency, ns_parser.days, ns_parser.resolution # ) res = ns_parser.resolution if delta < 90 else "1D" self.resolution = res ( self.coin, self.source, self.symbol, self.coin_map_df, self.data, self.current_currency, ) = c_help.load( coin=ns_parser.coin, source=ns_parser.source, should_load_ta_data=True, days=delta, interval="1day", vs=ns_parser.vs, ) console.print( f"{delta} Days of {self.coin} vs {self.current_currency} loaded with {res} resolution.\n" )
def call_load(self, other_args): """Process load command""" parser = argparse.ArgumentParser( add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="load", description="Load crypto currency to perform analysis on." "Available data sources are CoinGecko, CoinPaprika, Binance, Coinbase" "By default main source used for analysis is CoinGecko (cg). To change it use --source flag", ) parser.add_argument( "-c", "--coin", help="Coin to get", dest="coin", type=str, required="-h" not in other_args, ) parser.add_argument( "--source", help="Source of data", dest="source", choices=("cp", "cg", "bin", "cb"), default="cg", required=False, ) parser.add_argument( "-s", "--start", type=valid_date_in_past, default=(datetime.now() - timedelta(days=366)).strftime("%Y-%m-%d"), dest="start", help="The starting date (format YYYY-MM-DD) of the crypto", ) parser.add_argument( "--vs", help="Quote currency (what to view coin vs)", dest="vs", default="usd", type=str, ) parser.add_argument( "-i", "--interval", help="Interval to get data (Only available on binance/coinbase)", dest="interval", default="1day", type=str, ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-c") ns_parser = parse_known_args_and_warn(parser, other_args) delta = (datetime.now() - ns_parser.start).days if ns_parser: source = ns_parser.source for arg in ["--source", source]: if arg in other_args: other_args.remove(arg) res = ns_parser.resolution if delta < 90 else "1D" self.resolution = res # TODO: protections in case None is returned ( self.coin, self.source, self.symbol, self.coin_map_df, self.current_df, self.current_currency, ) = cryptocurrency_helpers.load( coin=ns_parser.coin, source=ns_parser.source, should_load_ta_data=True, days=delta, interval=ns_parser.interval, vs=ns_parser.vs, ) if self.symbol: self.current_interval = ns_parser.interval first_price = self.current_df["Close"].iloc[0] last_price = self.current_df["Close"].iloc[-1] second_last_price = self.current_df["Close"].iloc[-2] interval_change = calc_change(last_price, second_last_price) since_start_change = calc_change(last_price, first_price) if isinstance(self.current_currency, str) and self.PATH == "/crypto/": col = "green" if interval_change > 0 else "red" self.price_str = f"""Current Price: {round(last_price,2)} {self.current_currency.upper()} Performance in interval ({self.current_interval}): [{col}]{round(interval_change,2)}%[/{col}] Performance since {ns_parser.start.strftime('%Y-%m-%d')}: [{col}]{round(since_start_change,2)}%[/{col}]""" # noqa console.print(f""" Loaded {self.coin} against {self.current_currency} from {CRYPTO_SOURCES[self.source]} source {self.price_str} """) # noqa else: console.print( f"{delta} Days of {self.coin} vs {self.current_currency} loaded with {res} resolution.\n" )
def call_load(self, other_args): """Process load command""" parser = argparse.ArgumentParser( add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="load", description="Load crypto currency to perform analysis on." "Available data sources are CoinGecko, CoinPaprika, Binance, Coinbase" "By default main source used for analysis is CoinGecko (cg). To change it use --source flag", ) parser.add_argument( "-c", "--coin", help="Coin to get", dest="coin", type=str, required="-h" not in other_args, ) parser.add_argument( "--source", help="Source of data", dest="source", choices=("cp", "cg", "bin", "cb"), default="cg", required=False, ) parser.add_argument( "-s", "--start", type=valid_date_in_past, default=(datetime.now() - timedelta(days=366)).strftime("%Y-%m-%d"), dest="start", help="The starting date (format YYYY-MM-DD) of the crypto", ) parser.add_argument( "--vs", help="Quote currency (what to view coin vs)", dest="vs", default="usd", type=str, ) parser.add_argument( "-i", "--interval", help="Interval to get data (Only available on binance/coinbase)", dest="interval", default="1day", type=str, ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-c") ns_parser = parse_known_args_and_warn(parser, other_args) delta = (datetime.now() - ns_parser.start).days if ns_parser: source = ns_parser.source for arg in ["--source", source]: if arg in other_args: other_args.remove(arg) # TODO: protections in case None is returned (self.ticker, _, _, _, self.stock, self.currency) = load( coin=ns_parser.coin, source=ns_parser.source, should_load_ta_data=True, days=delta, interval=ns_parser.interval, vs=ns_parser.vs, ) console.print(f"{delta} Days of {self.ticker} vs {self.currency} loaded\n")