Retrieve weekly eia inventory data to update my csv directly

Options
alkp
alkp Newcomer

This is my first part of script that should retrieve the latest data?

cell 1

import lseg.data as ldld.open_session(app_key="app-key").open()

cell 2

from lseg.data.content import historical_pricing as hp
from datetime import date
import os

1. Correct RIC for total commercial crude stocks

crude_rics = ["C-STK-T-EIA"]

2. Date range

start_date = "2020-01-01"
end_date = str(date.today())

3. Fetch data

response = hp.summaries.Definition(
universe=crude_rics,
interval=hp.Intervals.WEEKLY,
start=start_date,
end=end_date
).get_data()

4. Extract and rename

raw_df = response.data.df
print("Latest date returned:", raw_df.index.max())
print("Today's date:", date.today())

comm_last_df = raw_df[["COMM_LAST"]].copy()
comm_last_df.columns = ["TotalCrude"]

5. Save

os.makedirs("../data", exist_ok=True)
comm_last_df.to_csv("../data/crude_total_stocks.csv")
print("Saved:", os.path.exists("../data/crude_total_stocks.csv"))

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @alkp

    Please refer to the answer on this discussion.

    You can also contact the Historical Pricing API directly via LSEG Support to verify what the problem is.

    Please include the URL of this discussion in your raised question to prevent it from being redirected back to this Q&A forum.