Fetching commodity prices

Hide code cell content

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)

import lseg.data as ld

ld.open_session()
<lseg.data.session.Definition object at 0x7fb9149f78c0 {name='rdp'}>

You can use the LSEG Data Library for Python to retrieve the latest price of a commodity by passing its Refinitiv Instrument Code to the get_data function.

Adding an equals sign as a suffix will return the value in US dollars. Here’s the spot price of gold:

ld.get_data("XAU=")

The get_data query requires that you account have access to real-time trading data, which is not available to all users. If you don’t, you can request the latest "1min" intervals from the get_history method.

ld.get_history(
    "XAU=",
    interval="1min",
).tail(1)
XAU= BID_HIGH_1 BID_LOW_1 OPEN_BID BID BID_NUMMOV ASK_HIGH_1 ASK_LOW_1 OPEN_ASK ASK ASK_NUMMOV MID_HIGH MID_LOW MID_OPEN MID_PRICE
Timestamp
2026-07-20 10:05:00 4020.78 4019.5962 4019.69 4020.23 103 4022.0256 4020.64 4020.8 4020.92 103 4021.145 4020.245 4020.245 4020.575

Historical data

You can retrieve historical stock prices by passing a Refinitiv Instrument Code to the get_history function. By default it returns the closing price for the last 30 days.

ld.get_history('XAU=')
XAU= HIGH_1 LOW_1 MID_PRICE BID OPEN_BID ASK OPEN_ASK BID_LOW_1 BID_HIGH_1 ASK_LOW_1 ASK_HIGH_1
Date
2026-06-22 4219.57 4135.6587 4191.615 4190.4326 4141.61 4192.7974 4145.61 4135.6587 4219.57 4136.94 4222.0737
2026-06-23 4197.59 4090.2778 4110.2649 4108.3467 4189.98 4112.1831 4193.2798 4090.2778 4197.59 4091.23 4207.5
2026-06-24 4114.47 3958.7588 4000.69495 4000.4175 4111.96 4000.9724 4114.2 3958.7588 4114.47 3960.0 4116.0479
2026-06-25 4044.05 3962.11 4027.55505 4025.9963 3999.0601 4029.1138 4002.3601 3962.11 4044.05 3963.44 4045.1262
2026-06-26 4095.78 3981.89 4089.26245 4088.2334 4024.5701 4090.2915 4030.5701 3981.89 4095.78 3983.76 4100.1
2026-06-29 4086.6599 4000.49 4017.57495 4016.0247 4086.6599 4019.1252 4092.6599 4000.49 4086.6599 4002.1 4100.7
2026-06-30 4062.92 3942.99 4008.475 4007.2312 4015.9399 4009.7188 4019.24 3942.99 4062.92 3945.46 4066.7
2026-07-01 4114.99 3959.72 4031.0449 4029.894 4006.8401 4032.1958 4010.1399 3959.72 4114.99 3960.49 4116.1
2026-07-02 4143.7 4029.4099 4123.98485 4122.8003 4030.44 4125.1694 4031.64 4029.4099 4143.7 4031.3401 4144.7305
2026-07-03 4194.99 4119.95 4175.7 4174.9 4122.3501 4176.5 4125.6499 4119.95 4194.99 4121.89 4196.0933
2026-07-06 4202.13 4127.6143 4165.16505 4163.9766 4172.71 4166.3535 4178.71 4127.6143 4202.13 4128.77 4203.2178
2026-07-07 4180.31 4091.4277 4107.32495 4105.6963 4165.79 4108.9536 4168.19 4091.4277 4180.31 4092.62 4186.23
2026-07-08 4133.8 4021.4041 4077.95495 4076.322 4107.22 4079.5879 4108.42 4021.4041 4133.8 4022.12 4134.9722
2026-07-09 4137.8 4053.4795 4121.62 4121.02 4075.36 4122.22 4077.76 4053.4795 4137.8 4054.61 4138.9692
2026-07-10 4134.65 4071.09 4121.07735 4120.0771 4121.02 4122.0776 4122.22 4071.09 4134.65 4073.8 4137.8
2026-07-13 4119.6299 3985.7041 4001.8351 4000.6526 4119.6299 4003.0176 4125.6299 3985.7041 4119.6299 3987.04 4125.6299
2026-07-14 4100.49 3983.29 4055.5275 4053.897 4003.39 4057.158 4008.6 3983.29 4100.49 3985.6 4101.0
2026-07-15 4080.25 4016.8445 4062.0551 4060.405 4054.67 4063.7051 4056.27 4016.8445 4080.25 4017.75 4081.4
2026-07-16 4065.11 3968.6277 3972.9399 3969.9399 4057.8 3975.9399 4059.8 3968.6277 4065.11 3969.68 4075.0
2026-07-17 4023.55 3959.37 4017.595 4016.69 3969.95 4018.5 3975.95 3959.37 4023.55 3960.0 4024.8875

Multiple instruments

You can retrieve data for multiple instruments by passing a list of Refinitiv Instrument Codes to the get_data and get_history functions.

ld.get_history(['XAU=', 'XAG='])
XAU= ... XAG=
HIGH_1 LOW_1 MID_PRICE BID OPEN_BID ASK OPEN_ASK BID_LOW_1 BID_HIGH_1 ASK_LOW_1 ... LOW_1 MID_PRICE BID OPEN_BID ASK OPEN_ASK BID_LOW_1 BID_HIGH_1 ASK_LOW_1 ASK_HIGH_1
Date
2026-06-22 4219.57 4135.6587 4191.615 4190.4326 4141.61 4192.7974 4145.61 4135.6587 4219.57 4136.94 ... 63.608 65.2025 65.1775 63.6556 65.2275 63.8056 63.608 67.12 63.758 67.2
2026-06-23 4197.59 4090.2778 4110.2649 4108.3467 4189.98 4112.1831 4193.2798 4090.2778 4197.59 4091.23 ... 61.28 61.575 61.55 64.9048 61.6 64.9948 61.28 65.1635 61.3545 65.716
2026-06-24 4114.47 3958.7588 4000.69495 4000.4175 4111.96 4000.9724 4114.2 3958.7588 4114.47 3960.0 ... 55.57 57.46 57.435 61.6241 57.485 61.6691 55.57 62.37 55.6687 62.42
2026-06-25 4044.05 3962.11 4027.55505 4025.9963 3999.0601 4029.1138 4002.3601 3962.11 4044.05 3963.44 ... 56.3 57.8925 57.8675 57.3275 57.9175 57.3725 56.3 59.007 56.3687 59.05
2026-06-26 4095.78 3981.89 4089.26245 4088.2334 4024.5701 4090.2915 4030.5701 3981.89 4095.78 3983.76 ... 55.67 59.185 59.16 57.84 59.21 57.94 55.67 59.56 55.722 59.62
2026-06-29 4086.6599 4000.49 4017.57495 4016.0247 4086.6599 4019.1252 4092.6599 4000.49 4086.6599 4002.1 ... 57.3924 58.3225 58.2975 58.68 58.3475 58.905 57.3924 59.42 57.43 59.73
2026-06-30 4062.92 3942.99 4008.475 4007.2312 4015.9399 4009.7188 4019.24 3942.99 4062.92 3945.46 ... 56.56 58.6 58.575 58.294 58.625 58.398 56.56 60.47 56.635 60.52
2026-07-01 4114.99 3959.72 4031.0449 4029.894 4006.8401 4032.1958 4010.1399 3959.72 4114.99 3960.49 ... 57.09 59.165 59.14 58.252 59.19 59.095 57.09 60.9886 57.1868 61.04
2026-07-02 4143.7 4029.4099 4123.98485 4122.8003 4030.44 4125.1694 4031.64 4029.4099 4143.7 4031.3401 ... 58.87 61.0325 61.0075 59.145 61.0575 59.195 58.87 62.0634 58.9383 62.1
2026-07-03 4194.99 4119.95 4175.7 4174.9 4122.3501 4176.5 4125.6499 4119.95 4194.99 4121.89 ... 60.87 62.425 62.4 61.02 62.45 61.07 60.87 62.9 60.9458 63.0
2026-07-06 4202.13 4127.6143 4165.16505 4163.9766 4172.71 4166.3535 4178.71 4127.6143 4202.13 4128.77 ... 61.33 62.1025 62.0775 62.28 62.1275 62.58 61.33 63.2561 61.3805 63.3011
2026-07-07 4180.31 4091.4277 4107.32495 4105.6963 4165.79 4108.9536 4168.19 4091.4277 4180.31 4092.62 ... 59.39 60.035 60.01 61.874 60.06 61.994 59.39 62.175 59.4631 62.2526
2026-07-08 4133.8 4021.4041 4077.95495 4076.322 4107.22 4079.5879 4108.42 4021.4041 4133.8 4022.12 ... 57.19 58.32 58.295 59.92 58.345 60.85 57.19 61.02 57.24 61.06
2026-07-09 4137.8 4053.4795 4121.62 4121.02 4075.36 4122.22 4077.76 4053.4795 4137.8 4054.61 ... 57.54 60.015 59.99 58.374 60.04 58.464 57.54 60.6104 57.6158 60.6428
2026-07-10 4134.65 4071.09 4121.07735 4120.0771 4121.02 4122.0776 4122.22 4071.09 4134.65 4073.8 ... 58.76 59.865 59.84 60.126 59.89 60.171 58.76 60.7494 58.81 60.8
2026-07-13 4119.6299 3985.7041 4001.8351 4000.6526 4119.6299 4003.0176 4125.6299 3985.7041 4119.6299 3987.04 ... 57.22 57.67 57.645 59.6942 57.695 59.9942 57.22 59.815 57.2759 59.9942
2026-07-14 4100.49 3983.29 4055.5275 4053.897 4003.39 4057.158 4008.6 3983.29 4100.49 3985.6 ... 56.82 58.68 58.625 57.54 58.735 57.7 56.82 59.6588 56.8885 59.7
2026-07-15 4080.25 4016.8445 4062.0551 4060.405 4054.67 4063.7051 4056.27 4016.8445 4080.25 4017.75 ... 56.59 57.795 57.77 58.6993 57.82 58.7593 56.59 59.0494 56.6343 59.4461
2026-07-16 4065.11 3968.6277 3972.9399 3969.9399 4057.8 3975.9399 4059.8 3968.6277 4065.11 3969.68 ... 55.29 55.53 55.505 56.9675 55.555 57.0425 55.29 58.046 55.3384 58.3021
2026-07-17 4023.55 3959.37 4017.595 4016.69 3969.95 4018.5 3975.95 3959.37 4023.55 3960.0 ... 54.74 55.95 55.9 55.7516 56.0 55.7707 54.74 56.1993 54.7934 56.26

20 rows × 22 columns

Hide code cell content

ld.close_session()