Delayed prices using LSEG Workspace API

Gianni_D
Gianni_D Newcomer
edited March 13 in Eikon Data APIs

Hello,

I'm trying to collect bids for LCOc1 as soon as the bid change in realtime.

My main issue is that I have a 10 min delay.

_________________________________

import time
import pandas as pd
import eikon as ek
import os

# Set Eikon API Key for access to financial data
ek.set_app_key('API_KEY_HERE')

# Define the instrument symbols
instruments = ["LCOc1"]

# Define the directory and file path for storing the CSV file
csv_directory = r"C:\Users\YOUR_PATH\" # Use raw string to handle Windows paths
csv_file = os.path.join(csv_directory, "eikon_LCOc1_data.csv")

# Ensure the directory exists
os.makedirs(csv_directory, exist_ok=True)

# Define the DataFrame columns
columns = ["Timestamp", "LCOc1_BID", "LCOc1_Time"]

# Track the last recorded bid values to avoid duplicate logging
last_bids = {"LCOc1": None}

try:
# Infinite loop to continuously fetch data
while True:
# Fetch BID data for LCOc1 using Eikon API
df = ek.get_data(instruments, ["CF_BID", "CF_TIME"])[0] # Get the first item of the returned tuple

# Check if data was retrieved
if df is None or df.empty:
print("Error: No data retrieved. Retrying...")
time.sleep(1) # Wait before retrying
continue

# Extract the bid price and time for LCOc1
try:
lco_data = df.loc[df['Instrument'] == 'LCOc1', ['CF_BID', 'CF_TIME']].iloc[0]
lco_bid = lco_data['CF_BID']
lco_time = lco_data['CF_TIME']
except IndexError:
print("Error: Missing bid data for LCOc1.")
time.sleep(1)
continue

# Log only if there is a change in bid prices
if lco_bid != last_bids["LCOc1"]:
timestamp = pd.Timestamp.now().strftime("%Y-%m-%d %H:%M:%S.%f")
new_row = pd.DataFrame([[timestamp, lco_bid, lco_time]], columns=columns)

# Append data to the CSV file (create if it doesn't exist)
new_row.to_csv(csv_file, mode="a", index=False, header=not os.path.exists(csv_file))

# Log the update
print(f"New Data at {timestamp}: LCOc1 BID = {lco_bid}, Time = {lco_time}")

# Update last recorded bid values
last_bids["LCOc1"] = lco_bid

# Small delay to avoid excessive API calls
time.sleep(0.05) # Adjust as needed

except KeyboardInterrupt:
print("\nProcess interrupted. Data saved in:", csv_file)

_________________________________

The result looks like this :

Timestamp

LCOc1_BID

LCOc1_Time

2025-03-12 09:52:07.812040

69.96

08:42:04

2025-03-12 09:52:12.707826

69.95

08:42:08

2025-03-12 09:52:15.209595

69.94

08:42:12

So I have a 1 hour delay due to GMT (no problem) + 10 minutes that I don't know where it comes from.

On my Workspace, I have Realtime data going through Private network.

Thanks for your help in advance

G

Answers

  • Hello @Gianni_D

    You are trying to use the API in a manner that is likely to breach the data limits guidelines and hence subject to throttling!

    If the application needs streaming data, please look into using the LD Library for Python and using the pricing streaming example. This library works with Eikon/Workspace using a Desktop Session. The realtime streaming data may/may not be available, depending on your data license. You can check with your LSEG account manager to get these data permissions.

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Gianni_D

    You may access the delayed data. You can use the Quote app to verify the data.

    I also get the 10 min delayed data for LCOc1 when using the Quote App.

    image.png

    The 10 min delay could be the default delayed time for LCOc1