investpy.crypto
ΒΆ
-
investpy.crypto.
get_crypto_historical_data
(crypto, from_date, to_date, as_json=False, order='ascending', interval='Daily')ΒΆ This function retrieves historical data from the introduced crypto from Investing.com. So on, the historical data of the introduced crypto will be retrieved and returned as a
pandas.DataFrame
if the parameters are valid and the request to Investing.com succeeds. Note that additionally some optional parameters can be specified: as_json and order, which let the user decide if the data is going to be returned as ajson
or not, and if the historical data is going to be ordered ascending or descending (where the index is the date), respectively.- Parameters
crypto (
str
) β name of the crypto currency to retrieve data from.from_date (
str
) β date formatted as dd/mm/yyyy, since when data is going to be retrieved.to_date (
str
) β date formatted as dd/mm/yyyy, until when data is going to be retrieved.as_json (
bool
, optional) β to determine the format of the output data, either apandas.DataFrame
if False and ajson
if True.order (
str
, optional) β to define the order of the retrieved data which can either be ascending or descending.interval (
str
, optional) β value to define the historical data interval to retrieve, by default Daily, but it can also be Weekly or Monthly.
- Returns
The function can return either a
pandas.DataFrame
or ajson
object, containing the retrieved historical data of the specified crypto currency. So on, the resulting dataframe contains the open, high, low, close and volume values for the selected crypto on market days and the currency in which those values are presented.The returned data is case we use default arguments will look like:
Date || Open | High | Low | Close | Volume | Currency -----||------|------|-----|-------|--------|---------- xxxx || xxxx | xxxx | xxx | xxxxx | xxxxxx | xxxxxxxx
but if we define as_json=True, then the output will be:
{ name: name, historical: [ { date: 'dd/mm/yyyy', open: x, high: x, low: x, close: x, volume: x, currency: x }, ... ] }
- Return type
pandas.DataFrame
orjson
- Raises
ValueError β raised whenever any of the introduced arguments is not valid or errored.
IOError β raised if cryptos object/file was not found or unable to retrieve.
RuntimeError β raised if the introduced crypto currency name was not found or did not match any of the existing ones.
ConnectionError β raised if connection to Investing.com could not be established.
IndexError β raised if crypto historical data was unavailable or not found in Investing.com.
Examples
>>> data = investpy.get_crypto_historical_data(crypto='bitcoin', from_date='01/01/2018', to_date='01/01/2019') >>> data.head() Open High Low Close Volume Currency Date 2018-01-01 13850.5 13921.5 12877.7 13444.9 78425 USD 2018-01-02 13444.9 15306.1 12934.2 14754.1 137732 USD 2018-01-03 14754.1 15435.0 14579.7 15156.6 106543 USD 2018-01-04 15156.5 15408.7 14244.7 15180.1 110969 USD 2018-01-05 15180.1 17126.9 14832.4 16954.8 141960 USD
-
investpy.crypto.
get_crypto_information
(crypto, as_json=False)ΒΆ This function retrieves fundamental financial information from the specified crypto currency. The retrieved information from the crypto currency can be valuable as it is additional information that can be used combined with OHLC values, so to determine financial insights from the company which holds the specified crypto currency.
- Parameters
currency_cross (
str
) β name of the currency_cross to retrieve recent historical data from.as_json (
bool
, optional) β optional argument to determine the format of the output data (dict
orjson
).
- Returns
The resulting
pandas.DataFrame
contains the information fields retrieved from Investing.com from the specified crypto currency; it can also be returned as adict
, if argument as_json=True.If any of the information fields could not be retrieved, that field/s will be filled with None values. If the retrieval process succeeded, the resulting
dict
will look like:crypto_information = { 'Chg (7D)': '-4.63%', 'Circulating Supply': ' BTC18.10M', 'Crypto Currency': 'Bitcoin', 'Currency': 'USD', 'Market Cap': '$129.01B', 'Max Supply': 'BTC21.00M', 'Todays Range': '7,057.8 - 7,153.1', 'Vol (24H)': '$17.57B' }
- Return type
pandas.DataFrame
ordict
- crypto_information- Raises
ValueError β raised if any of the introduced arguments is not valid or errored.
FileNotFoundError β raised if cryptos.csv file was not found or errored.
IOError β raised if cryptos.csv file is empty or errored.
RuntimeError β raised if scraping process failed while running.
ConnectionError β raised if the connection to Investing.com errored (did not return HTTP 200)
-
investpy.crypto.
get_crypto_recent_data
(crypto, as_json=False, order='ascending', interval='Daily')ΒΆ This function retrieves recent historical data from the introduced crypto from Investing.com. So on, the recent data of the introduced crypto will be retrieved and returned as a
pandas.DataFrame
if the parameters are valid and the request to Investing.com succeeds. Note that additionally some optional parameters can be specified: as_json and order, which let the user decide if the data is going to be returned as ajson
or not, and if the historical data is going to be ordered ascending or descending (where the index is the date), respectively.- Parameters
crypto (
str
) β name of the crypto currency to retrieve data from.as_json (
bool
, optional) β to determine the format of the output data, either apandas.DataFrame
if False and ajson
if True.order (
str
, optional) β to define the order of the retrieved data which can either be ascending or descending.interval (
str
, optional) β value to define the historical data interval to retrieve, by default Daily, but it can also be Weekly or Monthly.
- Returns
The function can return either a
pandas.DataFrame
or ajson
object, containing the retrieved recent data of the specified crypto currency. So on, the resulting dataframe contains the open, high, low, close and volume values for the selected crypto on market days and the currency in which those values are presented.The resulting recent data, in case that the default parameters were applied, will look like:
Date || Open | High | Low | Close | Volume | Currency -----||------|------|-----|-------|--------|---------- xxxx || xxxx | xxxx | xxx | xxxxx | xxxxxx | xxxxxxxx
but in case that as_json parameter was defined as True, then the output will be:
{ name: name, recent: [ { date: 'dd/mm/yyyy', open: x, high: x, low: x, close: x, volume: x, currency: x }, ... ] }
- Return type
pandas.DataFrame
orjson
- Raises
ValueError β raised whenever any of the introduced arguments is not valid or errored.
IOError β raised if cryptos object/file was not found or unable to retrieve.
RuntimeError β raised if the introduced crypto name was not found or did not match any of the existing ones.
ConnectionError β raised if connection to Investing.com could not be established.
IndexError β raised if crypto recent data was unavailable or not found in Investing.com.
Examples
>>> data = investpy.get_crypto_recent_data(crypto='bitcoin') >>> data.head() Open High Low Close Volume Currency Date 2019-10-25 7422.8 8697.7 7404.9 8658.3 1177632 USD 2019-10-26 8658.4 10540.0 8061.8 9230.6 1784005 USD 2019-10-27 9230.6 9773.2 9081.0 9529.6 1155038 USD 2019-10-28 9530.1 9866.9 9202.5 9207.2 1039295 USD 2019-10-29 9206.5 9531.3 9125.3 9411.3 918477 USD
-
investpy.crypto.
get_cryptos
()ΒΆ This function retrieves all the crypto data stored in cryptos.csv file, which previously was retrieved from Investing.com. Since the resulting object is a matrix of data, the crypto data is properly structured in rows and columns, where columns are the crypto data attribute names.
Note that just some cryptos are available for retrieval, since Investing.com does not provide information from all the available ones, just the main ones.
- Returns
The resulting
pandas.DataFrame
contains all the crypto data from every available crypto coin as indexed in Investing.com from the information previously retrieved by investpy and stored on a csv file.So on, the resulting
pandas.DataFrame
will look like:name | symbol | currency -----|--------|---------- xxxx | xxxxxx | xxxxxxxx
- Return type
pandas.DataFrame
- cryptos_df- Raises
FileNotFoundError β raised if cryptos.csv file was not found.
IOError β raised when cryptos.csv file is missing or empty.
-
investpy.crypto.
get_cryptos_dict
(columns=None, as_json=False)ΒΆ This function retrieves all the crypto information stored in the cryptos.csv file and formats it as a Python dictionary which contains the same information as the file, but every row is a
dict
and all of them are contained in alist
. Note that the dictionary structure is the same one as the JSON structure. Some optional paramaters can be specified such as the columns or as_json, which are the column names that want to be retrieved in case of needing just some columns to avoid unnecessary information load, and whether the information wants to be returned as a JSON object or as a dictionary; respectively.Note that just some cryptos are available for retrieval, since Investing.com does not provide information from all the available ones, just the main ones.
- Parameters
columns (
list
, optional) β column names of the crypto data to retrieve, can be: <name, currency, symbol>as_json (
bool
, optional) β if True the returned data will be ajson
object, if False, alist
ofdict
.
- Returns
The resulting
list
ofdict
contains the retrieved data from every crypto coin as indexed in Investing.com from the information previously retrieved by investpy and stored on a csv file.In case the information was successfully retrieved, the
list
ofdict
will look like:cryptos_dict = { 'name': name, 'currency': currency, 'symbol': symbol, }
- Return type
list
ofdict
ORjson
- cryptos_dict- Raises
ValueError β raised whenever any of the introduced arguments is not valid.
FileNotFoundError β raised if cryptos.csv file was not found.
IOError β raised when cryptos.csv file is missing or empty.
-
investpy.crypto.
get_cryptos_list
()ΒΆ This function retrieves all the crypto coin names stored in cryptos.csv file, which contains all the data from the crypto coins as previously retrieved from Investing.com. So on, this function will just return the crypto coin names which will be the main input parameters when it comes to crypto data retrieval functions from investpy.
Note that just some cryptos are available for retrieval, since Investing.com does not provide information from all the available ones, just the main ones.
- Returns
The resulting
list
contains the all the available crypto coin names as indexed in Investing.com from the information previously retrieved by investpy and stored on a csv file.In case the information was successfully retrieved, the
list
of crypto coin names will look like:cryptos_list = ['Bitcoin', 'Ethereum', 'XRP', 'Bitcoin Cash', 'Tether', 'Litecoin', ...]
- Return type
list
- cryptos_list- Raises
FileNotFoundError β raised if cryptos.csv file was not found.
IOError β raised when cryptos.csv file is missing or empty.
-
investpy.crypto.
get_cryptos_overview
(as_json=False, n_results=100)ΒΆ This function retrieves an overview containing all the real time data available for the main crypto currencies, such as the names, symbols, current value, etc. as indexed in Investing.com. So on, the main usage of this function is to get an overview on the main crypto currencies, so to get a general view. Note that since this function is retrieving a lot of information at once, by default just the overview of the Top 100 crypto currencies is being retrieved, but an additional parameter called n_results can be specified so to retrieve N results.
- Parameters
as_json (
bool
, optional) β optional argument to determine the format of the output data (pandas.DataFrame
orjson
).n_results (
int
, optional) β number of results to be displayed on the overview table (0-all_cryptos), where all crypto currencies will be retrieved if n_results=None.
Note
The amount of indexed crypto currencies may vary, so if n_results is set to None, all the available crypto currencies in Investing.com while retrieving the overview, will be retrieved and returned.
- Returns
The resulting
pandas.DataFrame
contains all the data available in Investing.com of the main crypto currencies in order to get an overview of it.If the retrieval process succeeded, the resulting
pandas.DataFrame
should look like:name | symbol | price | market_cap | volume24h | total_volume | change24h | change7d | currency -----|--------|-------|------------|-----------|--------------|-----------|----------|---------- xxxx | xxxxxx | xxxxx | xxxxxxxxxx | xxxxxxxxx | xxxxxxxxxxxx | xxxxxxxxx | xxxxxxxx | xxxxxxxx
- Return type
pandas.DataFrame
- cryptos_overview- Raises
ValueError β raised if any of the introduced arguments is not valid or errored.
IOError β raised if data could not be retrieved due to file error.
RuntimeError β raised it no overview results could be retrieved from Investing.com.
ConnectionError β raised if GET requests does not return 200 status code.
-
investpy.crypto.
search_cryptos
(by, value)ΒΆ This function searches cryptos by the introduced value for the specified field. This means that this function is going to search if there is a value that matches the introduced one for the specified field which is the cryptos.csv column name to search in. Available fields to search cryptos are βnameβ and βsymbolβ.
- Parameters
by (
str
) β name of the field to search for, which is the column name which can be: βnameβ or βsymbolβ.value (
str
) β value of the field to search for, which is the value that is going to be searched.
- Returns
The resulting
pandas.DataFrame
contains the search results from the given query, which is any match of the specified value in the specified field. If there are no results for the given query, an error will be raised, but otherwise the resultingpandas.DataFrame
will contain all the available cryptos that match the introduced query.- Return type
pandas.DataFrame
- search_result- Raises
ValueError β raised if any of the introduced parameters is not valid or errored.
FileNotFoundError β raised if cryptos.csv file is missing.
IOError β raised if data could not be retrieved due to file error.
RuntimeError β raised if no results were found for the introduced value in the introduced field.