question

Upvotes
Accepted
22 0 2 4

Can't use ISIN to retreive datapoints

I'm currently building a program in Pycharm and want to use the Eikon API to retreive 2 fields: CF_Last and TR.priceclose (SDate=-1M). However, when i give up ISIN codes as instrument names, i get an error, while RICs do seem to work. Is there any way to do this based on ISIN?

import tkinter as tk
from tkinter import filedialog
import pandas as pd
import eikon as ek

# API Key
ek.set_app_key('')

# Define the list of instrument codes and fields to retrieve
instrument_codes = ['BE0974293251', 'NL0010273215']
fields = ['CF_LAST', 'TR.PriceClose(SDate=-1M)']

# Retrieve the data using the Eikon API
data, err = ek.get_data(instrument_codes, fields)

# Check for errors
if err:
    raise ValueError(err)

# Print the resulting DataFrame
print(data)
eikon-data-api#productricsisin
icon clock
10 |1500

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

Upvotes
Accepted
22 0 2 4

Meanwhile, i've solved the issue and it turns out you can use ISIN to retreive datapoints. Snippet below works just fine.


# API Key
ek.set_app_key('api key')

# Define base dataframe
client_df = pd.DataFrame()

# get the current working directory
current_directory = os.getcwd()

# set the path to the database file
database_file_path = r'C:\Users\List.xlsx'


# Define function to retrieve stock data from Eikon API
def get_stock_data(isin_list):
    # Define the fields to request from the Eikon API
    fields = ['TR.Isin', 'TR.PriceClose(SDate=0;Curn=EUR)', 'TR.PriceClose(SDate=-30D;Curn=EUR)']

    # Request the data from the Eikon API
    data, err = ek.get_data(isin_list, fields)

    # If there was an error, raise an exception
    if err:
        raise Exception(f"Error getting data: {err}")

    # If the data is empty, raise an exception
    if data.empty:
        raise Exception("No data available")

    # Rename the columns to be more descriptive
    data.columns = ['Stock', 'Isin', 'Price', 'Price -1 mth']

    # Round the Price column down to 2 decimal places
    data['Price'] = data['Price'].astype(float).round(2)
    data['Price -1 mth'] = data['Price -1 mth'].astype(float).round(2)

    # Return only the Price and 1 month price change columns
    return data[['Price', 'Price -1 mth']]

icon clock
10 |1500

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

Upvotes
7.2k 18 2 8

Hi @christophe01 ,


Than you for your question, unfortunately you can't use ISIN directly in ek.get_data, however you may convert ISINs to RIC via ek.get_symbology function and use the RICs for the ek.get_data. Please see below:

ek.get_symbology(
    ['BE0974293251', 'NL0010273215'], 
    from_symbol_type='ISIN', 
    to_symbol_type='RIC')

screenshot-2023-02-24-at-164438.png

Hope this helps!


Best regards,

Haykaz


icon clock
10 |1500

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

Hi @christophe01 , thank you for coming back to us and posting your solution. Apparently, you can get TR fields with ISIN, however you will not be able to get fields such as CF_LAST with ISIN.

screenshot-2023-03-07-at-154407.png


Best regards,

Haykaz

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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