investpy.certificatesΒΆ

investpy.certificates.get_certificate_countries()ΒΆ

This function retrieves all the available countries to retrieve certificates from, as the listed countries are the ones indexed on Investing.com. The purpose of this function is to list the countries which have available certificates according to Investing.com data, since the country parameter is needed when retrieving data from any certificate available.

Returns

The resulting list contains all the countries listed on Investing.com with available certificates to retrieve data from.

In the case that the file reading of certificate_countries.csv which contains the names of the available countries with certificates was successfully completed, the resulting list will look like:

countries = ['france', 'germany', 'italy', 'netherlands', 'sweden']

Return type

list - countries

Raises

FileNotFoundError – raised when certificate_countries.csv file was not found.

investpy.certificates.get_certificate_historical_data(certificate, country, from_date, to_date, as_json=False, order='ascending', interval='Daily')ΒΆ

This function retrieves historical data from the introduced certificate from Investing.com. So on, the historical data of the introduced certificate from the specified country in the specified date range 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 a json or not, and if the historical data is going to be ordered ascending or descending (where the index is the date), respectively.

Parameters
  • certificate (str) – name of the certificate to retrieve historical data from.

  • country (str) – name of the country from where the certificate is.

  • 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 a pandas.DataFrame if False and a json 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 a json object, containing the retrieved historical data of the specified certificate from the specified country. So on, the resulting dataframe contains the OHLC values for the selected certificate on market days.

The returned data is case we use default arguments will look like:

Date || Open | High | Low | Close
-----||------|------|-----|-------
xxxx || xxxx | xxxx | xxx | xxxxx

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
        },
        ...
    ]
}

Return type

pandas.DataFrame or json

Raises
  • ValueError – raised whenever any of the introduced arguments is not valid or errored.

  • IOError – raised if certificates object/file was not found or unable to retrieve.

  • RuntimeError – raised if the introduced certificate/country 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 certificate historical data was unavailable or not found in Investing.com.

Examples

>>> data = investpy.get_certificate_historical_data(certificate='BNP Gold 31Dec99', country='france', from_date='01/01/2010', to_date='01/01/2019')
>>> data.head()
             Open   High    Low  Close
Date
2010-01-04  77.15  77.15  77.15  77.15
2010-01-05  77.40  77.45  77.15  77.45
2010-01-06  78.40  78.40  78.40  78.40
2010-01-07  78.40  78.45  78.35  78.35
2010-01-08  77.95  78.10  77.95  78.10
investpy.certificates.get_certificate_information(certificate, country, as_json=False)ΒΆ

This function retrieves fundamental financial information from the specified certificate. The retrieved information from the certificate 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 certificate.

Parameters
  • certificate (str) – name of the certificate to retrieve information from

  • country (country) – name of the country from where the certificate is from.

  • as_json (bool, optional) – optional argument to determine the format of the output data (dict or json).

Returns

The resulting pandas.DataFrame contains the information fields retrieved from Investing.com from the specified certificate; it can also be returned as a dict, 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:

certificate_information = {
    "Certificate Name": "XXXX",
    "Certificate Country": "XXXX",
    "Prev. Close": X.Y,
    "Todays Range": "X.Y - X.Y",
    "Leverage": "X:Y",
    "Open": X.Y,
    "52 wk Range": "X.Y - X.Y",
    "Strike Price": "XXXX",
    "Volume": X.Y,
    "Issue Date": "XXXX",
    "Issue Amount": "XXXX",
    "Average Vol. (3m)": X.Y,
    "Maturity Date": "dd/mm/yyyy",
    "1-Year Change": "X.Y%",
    "Asset Class": "XXXX"
}

Return type

pandas.DataFrame or dict- certificate_information

investpy.certificates.get_certificate_recent_data(certificate, country, as_json=False, order='ascending', interval='Daily')ΒΆ

This function retrieves recent historical data from the introduced certificate from Investing.com. So on, the recent data of the introduced certificate from the specified country 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 a json or not, and if the historical data is going to be ordered ascending or descending (where the index is the date), respectively.

Parameters
  • certificate (str) – name of the certificate to retrieve recent data from.

  • country (str) – name of the country from where the certificate is.

  • as_json (bool, optional) – to determine the format of the output data, either a pandas.DataFrame if False and a json 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 returns either a pandas.DataFrame or a json file containing the retrieved recent data from the specified certificate via argument. The dataset contains the OHLC values of the certificate.

The returned data is case we use default arguments will look like:

Date || Open | High | Low | Close
-----||------|------|-----|-------
xxxx || xxxx | xxxx | xxx | xxxxx

but if we define as_json=True, then the output will be:

{
    name: name,
    recent: [
        {
            date: dd/mm/yyyy,
            open: x,
            high: x,
            low: x,
            close: x
        },
        ...
    ]
}

Return type

pandas.DataFrame or json

Raises
  • ValueError – raised if there was an argument error.

  • IOError – raised if certificates object/file was not found or unable to retrieve.

  • RuntimeError – raised if the introduced certificate does not match any of the indexed ones.

  • ConnectionError – raised if GET requests does not return 200 status code.

  • IndexError – raised if certificate information was unavailable or not found.

Examples

>>> data = investpy.get_certificate_recent_data(certificate='BNP Gold 31Dec99', country='france')
>>> data.head()
             Open   High     Low   Close
Date
2020-07-09  146.4  146.8  145.95  145.95
2020-07-10  146.2  146.2  145.55  145.55
2020-07-13  145.6  145.6  145.45  145.45
2020-07-14  145.4  145.4  145.25  145.25
2020-07-15  144.9  145.1  144.70  144.95
investpy.certificates.get_certificates(country=None)ΒΆ

This function retrieves all the data stored in certificates.csv file, which previously was retrieved from Investing.com. Since the resulting object is a matrix of data, the certificate’s data is properly structured in rows and columns, where columns are the certificate data attribute names. Additionally, country filtering can be specified, which will make this function return not all the stored certificates, but just the data of the certificates from the introduced country.

Parameters

country (str, optional) – name of the country to retrieve all its available certificates from.

Returns

The resulting pandas.DataFrame contains all the certificate’s data from the introduced country if specified, or from every country if None was specified, 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:

country | name | full_name | symbol | issuer | isin | asset_class | underlying
--------|------|-----------|--------|--------|------|-------------|------------
xxxxxxx | xxxx | xxxxxxxxx | xxxxxx | xxxxxx | xxxx | xxxxxxxxxxx | xxxxxxxxxx

Return type

pandas.DataFrame - certificates_df

Raises
  • ValueError – raised whenever any of the introduced arguments is not valid.

  • FileNotFoundError – raised if certificates.csv file was not found.

  • IOError – raised when certificates.csv file is missing or empty.

investpy.certificates.get_certificates_dict(country=None, columns=None, as_json=False)ΒΆ

This function retrieves all the available certificates indexed on Investing.com, stored on certificates.csv. This function also allows the user to specify which country do they want to retrieve data from, or from every listed country; the columns which the user wants to be included on the resulting dict; and the output of the function will either be a dict or a json.

Parameters
  • country (str, optional) – name of the country to retrieve all its available certificates from.

  • columns (list, optional) – names of the columns of the certificate data to retrieve <country, name, full_name, symbol, issuer, isin, asset_class, underlying>

  • as_json (bool, optional) – value to determine the format of the output data which can either be a dict or a json.

Returns

The resulting dict contains the retrieved data if found, if not, the corresponding fields are filled with None values.

In case the information was successfully retrieved, the dict will look like:

certificates_dict = {
    "country": "france",
    "name": "SOCIETE GENERALE CAC 40 X10 31DEC99",
    "full_name": "SOCIETE GENERALE EFFEKTEN GMBH ZT CAC 40 X10 LEVERAGE 31DEC99",
    "symbol": "FR0011214527",
    "issuer": "Societe Generale Effekten GMBH",
    "isin": "FR0011214527",
    "asset_class": "index",
    "underlying": "CAC 40 Leverage x10 NR"
}

Return type

dict or json - certificates_dict

Raises
  • ValueError – raised whenever any of the introduced arguments is not valid.

  • FileNotFoundError – raised if certificates.csv file was not found.

  • IOError – raised when certificates.csv file is missing or empty.

investpy.certificates.get_certificates_list(country=None)ΒΆ

This function retrieves all the available certificates indexed on Investing.com, already stored on certificates.csv. This function also allows the users to specify which country do they want to retrieve data from or if they want to retrieve it from every listed country; so on, a listing of certificates will be returned. This function helps the user to get to know which certificates are available on Investing.com.

Parameters

country (str, optional) – name of the country to retrieve all its available certificates from.

Returns

The resulting list contains the retrieved data from the certificates.csv file, which is a listing of the names of the certificates listed on Investing.com, which is the input for data retrieval functions as the name of the certificate to retrieve data from needs to be specified.

In case the listing was successfully retrieved, the list will look like:

certificates_list = ['SOCIETE GENERALE CAC 40 X10 31DEC99', 'SG ZT CAC 40 x7 Short 31Dec99', ...]

Return type

list - certificates_list

Raises
  • ValueError – raised whenever any of the introduced arguments is not valid.

  • FileNotFoundError – raised if certificates.csv file was not found.

  • IOError – raised when certificates.csv file is missing or empty.

investpy.certificates.get_certificates_overview(country, as_json=False, n_results=100)ΒΆ

This function retrieves an overview containing all the real time data available for the main certificates from a country, 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 certificates from a country, 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 certificates is being retrieved, but an additional parameter called n_results can be specified so to retrieve N results.

Parameters
  • country (str) – name of the country to retrieve the certificates overview from.

  • as_json (bool, optional) – optional argument to determine the format of the output data (pandas.DataFrame or json).

  • n_results (int, optional) – number of results to be displayed on the overview table (0-1000).

Returns

The resulting pandas.DataFrame contains all the data available in Investing.com of the main certificates from a country in order to get an overview of it.

If the retrieval process succeeded, the resulting pandas.DataFrame should look like:

country | name | symbol | last | change_percentage | turnover
--------|------|--------|------|-------------------|----------
xxxxxxx | xxxx | xxxxxx | xxxx | xxxxxxxxxxxxxxxxx | xxxxxxxx

Return type

pandas.DataFrame - certificates_overview

Raises
  • ValueError – raised if any of the introduced arguments is not valid or errored.

  • FileNotFoundError – raised when certificates.csv file is missing.

  • IOError – raised if data could not be retrieved due to file error.

  • RuntimeError – raised either if the introduced country does not match any of the listed ones or if no overview results could be retrieved from Investing.com.

  • ConnectionError – raised if GET requests does not return 200 status code.

investpy.certificates.search_certificates(by, value)ΒΆ

This function searches certificates 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 certificates.csv column name to search in. Available fields to search certificates are country, name, full_name, symbol, issuer, isin, asset_class, underlying.

Parameters
  • by (str) – name of the field to search for, which is the column name which can be: country, name, full_name, symbol, issuer, isin, asset_class or underlying.

  • 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 resulting pandas.DataFrame will contain all the available certificates 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 certificates.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.