How to get TWAP data using python API.
Time weighted average price
Sample code AAPL.OQ
@sureshbabu
Thank you for reaching out to us. This forum is dedicated to software developers using LSEG APIs. The moderators on this forum do not have deep expertise in every bit of content available through LSEG products, which is required to answer content questions such as this one. The best resource for content questions is the Helpdesk support team, which can be reached by submitting queries through LSEG Support. The support team will either have the required content expertise ready available or can reach out to relevant content experts to get the answer for you. You need to ask for the Excel formula, such as =RDP.Data, that can be used to retrieve the required data. Then, we can help you converting that formula to Python code. You can also refer to these articles:
Otherwise, the client may need to use the API to retrieve price data and then calculate the TWAP values using Python. I found that there are several methods for calculating TWAP, such as using price data directly or deriving it from OHLC (Open, High, Low, Close) data. This sample calculates TWAP using hourly historical data.
df = ld.get_history( universe = ['AAPL.OQ'], fields = ['OPEN_PRC', 'HIGH_1', 'LOW_1','TRDPRC_1'], start = '2026-09-02T00:00:00', end = '2026-09-04T23:59:59', interval = '1h') df["OHLC_AVG"] = ( df["OPEN_PRC"] + df["HIGH_1"] + df["LOW_1"] + df["TRDPRC_1"] ) / 4 df["TWAP_OHLC"] = df["OHLC_AVG"].expanding().mean() df["TWAP_CLOSE"] = df['TRDPRC_1'].expanding().mean() df
However, please verify this approach with the Content Support team before sharing it with the client.