investpy.currency_crosses

investpy.currency_crosses.get_available_currencies()

This function retrieves a listing with all the available currencies with indexed currency crosses in order to get to know which are the available currencies. The currencies listed in this function, so on, can be used to search currency crosses and used the retrieved data to get historical data of those currency crosses, so to determine which is the value of one base currency in the second currency.

Returns

The resulting list contains all the available currencies with currency crosses being either the base or the second value of the cross, as listed in Investing.com.

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

available_currencies = [
    'AED', 'AFN', 'ALL', 'AMD', 'ANG', ...
]

Return type

list - available_currencies

Raises
  • FileNotFoundError – raised if currency_crosses.csv file was not found.

  • IOError – raised if currency crosses retrieval failed, both for missing file or empty file.

investpy.currency_crosses.get_currency_cross_historical_data(currency_cross, from_date, to_date, as_json=False, order='ascending', interval='Daily')

This function retrieves recent historical data from the introduced currency_cross from Investing via Web Scraping. The resulting data can it either be stored in a pandas.DataFrame or in a json file, with ascending or descending order.

Parameters
  • currency_cross (str) – name of the currency cross to retrieve recent historical data from.

  • from_date (str) – date as str formatted as dd/mm/yyyy, from where data is going to be retrieved.

  • to_date (str) – date as str formatted as dd/mm/yyyy, until where data is going to be retrieved.

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

  • order (str, optional) – optional argument to define the order of the retrieved data (ascending, asc or descending, desc).

  • 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 a either a pandas.DataFrame or a json file containing the retrieved recent data from the specified currency_cross via argument. The dataset contains the open, high, low, close and volume values for the selected currency_cross on market days.

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

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

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

{
    name: name,
    historical: [
        dd/mm/yyyy: {
            'open': x,
            'high': x,
            'low': x,
            'close': x,
            'currency' : x
        },
        ...
    ]
}

Return type

pandas.DataFrame or json

Raises
  • ValueError – argument error.

  • IOError – stocks object/file not found or unable to retrieve.

  • RuntimeError – introduced currency_cross does not match any of the indexed ones.

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

  • IndexError – if currency_cross information was unavailable or not found.

Examples

>>> data = investpy.get_currency_cross_historical_data(currency_cross='EUR/USD', from_date='01/01/2018', to_date='01/01/2019')
>>> data.head()
              Open    High     Low   Close Currency
Date
2018-01-01  1.2003  1.2014  1.1995  1.2010      USD
2018-01-02  1.2013  1.2084  1.2003  1.2059      USD
2018-01-03  1.2058  1.2070  1.2001  1.2014      USD
2018-01-04  1.2015  1.2090  1.2004  1.2068      USD
2018-01-05  1.2068  1.2085  1.2021  1.2030      USD
investpy.currency_crosses.get_currency_cross_information(currency_cross, as_json=False)

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

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 or json).

Returns

The resulting pandas.DataFrame contains the information fields retrieved from Investing.com from the specified currency cross; 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:

currency_cross_information = {
    "1-Year Change": "- 1.61%",
    "52 wk Range": "1.0879 - 1.1572",
    "Ask": 1.1144,
    "Bid": 1.114,
    "Currency Cross": "EUR/USD",
    "Open": 1.1121,
    "Prev. Close": 1.1119,
    "Todays Range": "1.1123 - 1.1159"
}

Return type

pandas.DataFrame or dict- currency cross_information

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

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

  • IOError – raised if currency_crosses.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.currency_crosses.get_currency_cross_recent_data(currency_cross, as_json=False, order='ascending', interval='Daily')

This function retrieves recent historical data from the introduced currency_cross as indexed in Investing.com via Web Scraping. The resulting data can it either be stored in a pandas.DataFrame or in a json file, with ascending or descending order.

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 (pandas.DataFrame or json).

  • order (str, optional) – optional argument to define the order of the retrieved data (ascending, asc or descending, desc).

  • 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 a either a pandas.DataFrame or a json file containing the retrieved recent data from the specified currency_cross via argument. The dataset contains the open, high, low, close, volume and currency values for the selected currency_cross on market days.

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

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

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

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

Return type

pandas.DataFrame or json

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

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

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

  • ConnectionError – raised if GET request did not return 200 status code.

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

Examples

>>> data = investpy.get_currency_cross_recent_data(currency_cross='EUR/USD')
>>> data.head()
              Open    High     Low   Close Currency
Date
2019-08-27  1.1101  1.1116  1.1084  1.1091      USD
2019-08-28  1.1090  1.1099  1.1072  1.1078      USD
2019-08-29  1.1078  1.1093  1.1042  1.1057      USD
2019-08-30  1.1058  1.1062  1.0963  1.0991      USD
2019-09-02  1.0990  1.1000  1.0958  1.0968      USD
investpy.currency_crosses.get_currency_crosses(base=None, second=None)

This function retrieves all the available currency crosses from Investing.com and returns them as a pandas.DataFrame, which contains not just the currency crosses names, but all the fields contained on the currency_crosses file. Note that the filtering params are both base and second, which mean the base and the second currency of the currency cross, for example, in the currency cross EUR/USD the base currency is EUR and the second currency is USD. These are optional parameters, so specifying one of them means that all the currency crosses where the introduced currency is either base or second will be returned; if both are specified, just the introduced currency cross will be returned if it exists. All the available currency crosses can be found at: https://www.investing.com/currencies/

Parameters
  • base (str, optional) – symbol of the base currency of the currency cross, this will return a pandas.DataFrame containing all the currency crosses where the base currency matches the introduced one.

  • second (str) – symbol of the second currency of the currency cross, this will return a pandas.DataFrame containing all the currency crosses where the second currency matches the introduced one.

Returns

The resulting pandas.DataFrame contains all the currency crosses basic information retrieved from Investing.com.

In case the information was successfully retrieved, the resulting pandas.DataFrame will look like:

name | full_name | base | second | base_name | second_name
-----|-----------|------|--------|-----------|-------------
xxxx | xxxxxxxxx | xxxx | xxxxxx | xxxxxxxxx | xxxxxxxxxxx

Return type

pandas.DataFrame - currency_crosses_df

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

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

  • IOError – raised if currency crosses retrieval failed, both for missing file or empty file.

investpy.currency_crosses.get_currency_crosses_dict(base=None, second=None, columns=None, as_json=False)

This function retrieves all the available currency crosses from Investing.com and returns them as a dict, which contains not just the currency crosses names, but all the fields contained on the currency_crosses file is columns is None, otherwise, just the specified column values will be returned. Note that the filtering params are both base and second, which mean the base and the second currency of the currency cross, for example, in the currency cross EUR/USD the base currency is EUR and the second currency is USD. These are optional parameters, so specifying one of them means that all the currency crosses where the introduced currency is either base or second will be returned; if both are specified, just the introduced currency cross will be returned if it exists. All the available currency crosses can be found at: https://www.investing.com/currencies/

Parameters
  • base (str, optional) – symbol of the base currency of the currency cross, this will return a pandas.DataFrame containing all the currency crosses where the base currency matches the introduced one.

  • second (str) – symbol of the second currency of the currency cross, this will return a pandas.DataFrame containing all the currency crosses where the second currency matches the introduced one.

  • columns (list, optional) – names of the columns of the currency crosses data to retrieve <name, full_name, base, base_name, second, second_name>

  • 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:

{
    'name': name,
    'full_name': full_name,
    'base': base,
    'base_name': base_name,
    'second': second,
    'second_name': second_name
}

Return type

dict or json - currency_crosses_dict

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

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

  • IOError – raised if currency crosses retrieval failed, both for missing file or empty file.

investpy.currency_crosses.get_currency_crosses_list(base=None, second=None)

This function retrieves all the available currency crosses from Investing.com and returns them as a dict, which contains not just the currency crosses names, but all the fields contained on the currency_crosses file is columns is None, otherwise, just the specified column values will be returned. Note that the filtering params are both base and second, which mean the base and the second currency of the currency cross, for example, in the currency cross EUR/USD the base currency is EUR and the second currency is USD. These are optional parameters, so specifying one of them means that all the currency crosses where the introduced currency is either base or second will be returned; if both are specified, just the introduced currency cross will be returned if it exists. All the available currency crosses can be found at: https://www.investing.com/currencies/

Parameters
  • base (str, optional) – symbol of the base currency of the currency cross, this will return a pandas.DataFrame containing all the currency crosses where the base currency matches the introduced one.

  • second (str) – symbol of the second currency of the currency cross, this will return a pandas.DataFrame containing all the currency crosses where the second currency matches the introduced one.

Returns

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

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

currency_crosses_list = [
    'USD/BRLT', 'CAD/CHF', 'CHF/CAD', 'CAD/PLN', 'PLN/CAD', ...
]

Return type

list - currency_crosses_list

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

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

  • IOError – raised if currency crosses retrieval failed, both for missing file or empty file.

investpy.currency_crosses.get_currency_crosses_overview(currency, as_json=False, n_results=100)

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

Parameters
  • currency (str) – name of the currency to retrieve the currency crosses 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 currency crosses from a given currency in order to get an overview of them.

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

symbol | name | bid | ask | high | low | change | change_percentage
-------|------|-----|-----|------|-----|--------|-------------------
xxxxxx | xxxx | xxx | xxx | xxxx | xxx | xxxxxx | xxxxxxxxxxxxxxxxx

Return type

pandas.DataFrame - stocks_overview

Raises
  • ValueError – raised if any of the introduced arguments errored.

  • FileNotFoundError – raised if currencies.csv file is missing.

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

  • RuntimeError – raised either if the introduced currency 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.currency_crosses.search_currency_crosses(by, value)

This function searches currency crosses 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 value for the specified field which is the currency_crosses.csv column name to search in. Available fields to search indices are ‘name’, ‘full_name’, ‘base’, ‘second’, ‘base_name’ and ‘second_name’.

Parameters
  • by (str) – name of the field to search for, which is the column name (‘name’, ‘full_name’, ‘base’, ‘second’, ‘base_name’ or ‘second_name’).

  • value (str) – value of the field to search for, which is the str that is going to be searched.

Returns

The resulting pandas.DataFrame contains the search results from the given query (the specified value in the specified field). If there are no results and error will be raised, but otherwise this pandas.DataFrame will contain all the available field values that match the introduced query.

Return type

pandas.DataFrame - search_result

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

  • FileNotFoundError – raised if currency_crosses.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.