For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
0 0 1 2

Error 500 just started no longer retrieving Market FX data

We use API/Python the retrieve Market data for various funds, it was working perfectly fine yesterday.

is there any server issues?

eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikon
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
6.7k 8 6 7

@peter.akester What API call are you using - please post the code. Is it intermittent or continuous fail. Is your code in a try catch block etc. Thanks.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
0 0 1 2

Eikon API


def find_unique_currencies(sec_report_df, funds_df):
    """Find the unique currencies from the Funds and Portfolio Excels

    :param sec_report_df: (pandas dataframe) of the security report
    excel sheet in Portfolio data Excel file
    :return: (list of strings) containing unique currencies
    """
    security_currencies = (
        sec_report_df["II_Security_Currency"].dropna().unique().tolist()
    )
    # check currencies in Fund information, in case Portfolio file doesn't capture them
    funds_currencies = funds_df["FI_Share_Class_Currency"].dropna().unique().tolist()
    currency_list = list(set(security_currencies + funds_currencies))
    return currency_list


def retrieve_RIC_Currencies(list_of_currencies):
    """Convert list of currencies into list of RICs (Reuters Instrument Codes)

    :param list_of_currencies: (list of strings) containing unique
    currencies
    :return: (list of tuples) with each tuple containing a currency and RIC string
    """
    # Convert the currencies into a list
    RIC_Currencies = []
    for currency in list_of_currencies:
        if currency == "USD":
            RIC_Currencies.append((currency, "GBP="))
        elif currency == "GBP":
            pass
        else:
            RIC_Currencies.append((currency, "GBP" + currency + "=R"))
    return RIC_Currencies  # return a list of tuples with currency and RIC code


def process_single_currency(start_date, end_date, RIC_Currencies_value):
    """Retrieve market data for an individual currency from the Reuters Eikon API

    :param start_date: (datetime or date object) from which the fund
    begins, from the submitted file
    :param end_date: (datetime or date object) at which the fund ends,
    from the submitted file
    :param RIC_Currencies_value: (tuple) containing currency string
    and RIC string
    :return: (pandas dataframe) containing market data information
    for a single currency
    """
    currency, RIC = RIC_Currencies_value  # unpack the tuple
    # get currency market values by each individual
    # currency to reduce the chance of timeout
    print("Processing currency: ", currency)
    single_currency_df = ek.get_timeseries(
        RIC,
        fields=["CLOSE"],
        start_date=str(start_date),  # +'T00:00:00', #start_date as datetime
        end_date=str(end_date),  # +'T00:00:00', #end_date as datetime
        interval="daily",
        calendar="calendardays",
    )
    # append base and local currency columns
    single_currency_df["XM_Base_Currency"] = pd.Series(
        "GBP", index=single_currency_df.index
    )
    single_currency_df["XM_Local_Currency"] = pd.Series(
        currency, index=single_currency_df.index
    )
    return single_currency_df


# Function to clean up dataframe columns
def clean_df_columns(currency_dataframe):
    """Clean currency dataframe into structure required for Halo

    :param currency_dataframe: (pandas dataframe) returned from the
    process_single_currency function
    :return: (pandas dataframe) cleaned for the final Halo output
    """
    currency_dataframe = (
        currency_dataframe.reset_index()
    )  # Remove date from the index so that date is also a column
    datetime_series = currency_dataframe["Date"].apply(
        cf.convert_date_short
    )  # Convert date to Halo appropriate format
    currency_dataframe[
        "XM_FX_Date"
    ] = datetime_series  # Append the new date column to the dataframe
    currency_dataframe.set_index(
        "XM_FX_Date", inplace=True
    )  # Set the new date column to be the index
    currency_dataframe = currency_dataframe.drop(columns="Date").rename(
        columns={"CLOSE": "XM_FX_Rate_Mkt"}
    )  # Drop the old date column, rename columns to proper values
    currency_dataframe = currency_dataframe.reset_index()
    if currency_dataframe.empty:
        raise Exception("Error: no currency data pulled")
    return currency_dataframe


def create_GBP_dataframe(start_date, end_date):
    """Create a currency dataframe for GBP
        GBP is not generated as a RIC code due to the process of funds
        so we must create it manually

    :param start_date: (datetime or date object) from which the fund
    begins, from the submitted file
    :param end_date: (datetime or date object) at which the fund ends,
    from the submitted file
    :return: (pandas dataframe) containing market data information for GBP
    """
    # generate a single currency dataframe as if we were using USD,
    # so that we get the correct dates
    temp_df = process_single_currency(start_date, end_date, ("GBP", "GBP="))
    temp_df["CLOSE"] = 1.0
    temp_df["XM_Local_Currency"] = "GBP"
    return temp_df


def process_all_currencies(start_date, end_date, RIC_Currency_list):
    """Retrieve the market data for all currencies

    :param start_date: (datetime or date object) from which the fund begins,
    from the submitted file
    :param end_date: (datetime or date object) at which the fund ends,
    from the submitted file
    :param RIC_Currency_list: (list of tuples) with each tuple containing
    currency string and RIC string
    :return: (pandas dataframe) containing market data information for GBP
    """
    all_currencies_df = pd.DataFrame()
    for RIC_currency in RIC_Currency_list:
        temp_df = process_single_currency(
            start_date, end_date, RIC_currency
        )  # retrieve dataframe for each currency
        all_currencies_df = pd.concat(
            [all_currencies_df, temp_df]
        )  # aggregate all individual currency dataframes
        time.sleep(2)
    all_currencies_df = pd.concat(
        [all_currencies_df, create_GBP_dataframe(start_date, end_date)]
    )  # add GBP data to the dataframe
    return all_currencies_df


def main(sec_report_df, fund_info_df, start_date, end_date):
    """Return market data for currencies

    :param path: (string) consisting of the path to the fund folder
    :param start_date: (datetime or date object) from which the fund
    begins, from the submitted file
    :param end_date: (datetime or date object) at which the fund ends,
    from the submitted file
    """
    print("Pulling Exchange Rate data from Reuters...")
    try:
        currencies = find_unique_currencies(sec_report_df, fund_info_df)
        RIC_Currencies_ = retrieve_RIC_Currencies(currencies)
        data_df = process_all_currencies(start_date, end_date, RIC_Currencies_)
        data_df = clean_df_columns(data_df)
        print("Finished running Exchange Rate data\n")
        return data_df
    except Exception as e:
        print(
            "Error encountered in retrieving FX data\nNo FX data pulled: "
            + str(e)
            + "\n"
        )
        return pd.DataFrame()
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
38.1k 71 35 53

@peter.akester

From the code, you are using Eikon Data API (ek.get_timeseries). If the problem still occurs, please enable logging in the Eikon DATA API by using the following code.

ek.set_log_level(1)
ek.set_app_key('<app key>')

Please share the API log if the problem occurs again.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea