The client wanted to get all historical data for RIC FCPOQ26-U26. I had provided him the below code:
import refinitiv.data as rd
rd.open_session()
df = rd.get_data(
universe = ['FCPOQ26-U26'],
fields = [
'TR.CLOSEPRICE(SDate=2025-08-18,EDate=2026-06-10).date',
'TR.CLOSEPRICE(SDate=2025-08-18,EDate=2026-06-10)'
]
)
display(df)
The client said that he wants a code that he can run in code editor of vs code. He said such codes can be run anywhere, not just in Workspace Codebook. He provided a sample as below and wanted the same for the above example.
import refinitiv.data as rd
import os
from dotenv import load_dotenv
load_dotenv()
APP_KEY = os.getenv('REFINITIV_APP_KEY')
def run_connection_test():
print("--- Starting Refinitiv Volume Discovery Test ---")
try:
# 2. Open Session
rd.open_session(app_key=APP_KEY)
print("[SUCCESS] Session opened successfully.")
# 3. Target RIC (STFc1 is the active SGX Rubber contract)
# We use a single RIC to make the output easy to read
test_ric = "STFc1"
# 4. Expanded Field List
# We include common volume fields used across different asset classes
test_fields = [
"TRDPRC_1", # Last Price (already confirmed working)
"VOLUME", # Standard Volume
"ACVOL_UNS", # Accumulated Volume
"VOL_TRD_CB", # Volume Traded Central Board (Common for SGX)
"TR.Volume" # Fundamental Volume field
]
print(f"Requesting multiple volume fields for: {test_ric}")
# 5. Data Fetch
df = rd.get_history(
universe=test_ric,
fields=test_fields,
count=10, # Increased count to see more history
interval="daily"
)
if not df.empty:
print("[SUCCESS] Data received. Check which column has numbers:")
print(df)
# Identify the working column automatically
for field in test_fields[1:]: # Skip Price
if not df[field].isnull().all():
print(f"\n[FOUND] Use this field in your main script: {field}")
else:
print("[WARNING] No data returned. Check your permissions for SGX data.")
except Exception as e:
print(f"[FAILURE] An error occurred: {e}")
finally:
rd.close_session()
print("--- Test Finished ---")<br>
Can you give me such a code?