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 0x7fdcf82938c0 {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-08-28 11:10:00 4596.49 4595.15 4595.82 4595.96 207 4597.2 4595.8 4596.52 4596.55 207 4596.845 4595.475 4596.17 4596.255

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-07-31 4111.39 4020.1257 4042.66675 4040.9448 4103.2 4044.3887 4106.4 4020.1257 4111.39 4021.51 4121.2
2026-08-03 4080.29 4018.69 4053.45 4052.65 4074.11 4054.25 4080.11 4018.69 4080.29 4019.68 4086.29
2026-08-04 4106.12 4042.03 4077.6549 4076.0139 4053.4299 4079.2959 4054.03 4042.03 4106.12 4043.0 4106.8
2026-08-05 4267.24 4064.9 4247.0249 4245.3975 4076.53 4248.6523 4077.73 4064.9 4267.24 4066.0 4268.7
2026-08-06 4303.9 4222.5122 4240.41505 4239.23 4248.34 4241.6001 4250.74 4222.5122 4303.9 4223.83 4308.1
2026-08-07 4371.63 4229.2153 4343.7402 4341.7114 4240.58 4345.769 4242.98 4229.2153 4371.63 4230.12 4372.7046
2026-08-10 4395.12 4311.49 4388.96 4388.5 4340.59 4389.42 4344.4 4311.49 4395.12 4313.41 4398.3
2026-08-11 4434.84 4355.896 4368.46485 4366.8408 4389.22 4370.0889 4390.41 4355.896 4434.84 4357.09 4436.1011
2026-08-12 4440.53 4358.59 4408.69505 4407.062 4366.8301 4410.3281 4370.1299 4358.59 4440.53 4363.05 4442.0
2026-08-13 4449.39 4343.2661 4351.34495 4350.1616 4408.68 4352.5283 4411.08 4343.2661 4449.39 4344.26 4451.0654
2026-08-14 4396.81 4310.063 4376.59865 4375.8931 4350.76 4377.3042 4351.8 4310.063 4396.81 4311.4 4397.6968
2026-08-17 4428.72 4366.6904 4416.82005 4415.1899 4377.12 4418.4502 4385.12 4366.6904 4428.72 4367.79 4429.8
2026-08-18 4435.73 4328.0332 4334.51515 4333.3311 4416.95 4335.6992 4418.15 4328.0332 4435.73 4329.69 4437.0581
2026-08-19 4523.79 4323.7983 4522.795 4521.09 4333.48 4524.5 4335.88 4323.7983 4523.79 4325.19 4525.6069
2026-08-20 4540.81 4450.083 4519.08 4517.87 4521.9751 4520.29 4522.585 4450.083 4540.81 4450.96 4542.1606
2026-08-21 4631.99 4508.1357 4603.5625 4602.6079 4516.0898 4604.5171 4522.0898 4508.1357 4631.99 4509.53 4633.2378
2026-08-24 4680.7 4594.1289 4651.87 4651.27 4615.79 4652.47 4621.79 4594.1289 4680.7 4595.24 4682.1
2026-08-25 4696.18 4604.647 4658.59445 4656.5898 4652.91 4660.5991 4655.31 4604.647 4696.18 4605.7 4699.1396
2026-08-26 4673.39 4582.2607 4593.67505 4592.0317 4654.0 4595.3184 4656.4 4582.2607 4673.39 4583.37 4675.019
2026-08-27 4642.9 4565.77 4601.2549 4601.0 4595.3 4601.5098 4598.2 4565.77 4642.9 4566.57 4643.8

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-07-31 4111.39 4020.1257 4042.66675 4040.9448 4103.2 4044.3887 4106.4 4020.1257 4111.39 4021.51 ... 57.01 57.6569 57.6319 58.8073 57.6819 58.8973 57.01 59.2727 57.043 59.3627
2026-08-03 4080.29 4018.69 4053.45 4052.65 4074.11 4054.25 4080.11 4018.69 4080.29 4019.68 ... 56.54 58.205 58.18 58.4739 58.23 58.6989 56.54 58.6016 56.566 58.82
2026-08-04 4106.12 4042.03 4077.6549 4076.0139 4053.4299 4079.2959 4054.03 4042.03 4106.12 4043.0 ... 57.9124 59.535 59.51 58.016 59.56 58.076 57.9124 60.043 58.018 60.09
2026-08-05 4267.24 4064.9 4247.0249 4245.3975 4076.53 4248.6523 4077.73 4064.9 4267.24 4066.0 ... 59.2939 62.1028 62.0778 59.6325 62.1278 59.6775 59.2939 62.79 59.4212 62.84
2026-08-06 4303.9 4222.5122 4240.41505 4239.23 4248.34 4241.6001 4250.74 4222.5122 4303.9 4223.83 ... 60.8573 61.505 61.48 61.4568 61.53 61.5468 60.8573 62.893 60.8876 62.94
2026-08-07 4371.63 4229.2153 4343.7402 4341.7114 4240.58 4345.769 4242.98 4229.2153 4371.63 4230.12 ... 61.1399 63.5766 63.5516 61.3345 63.6016 61.4245 61.1399 65.09 61.1896 65.234
2026-08-10 4395.12 4311.49 4388.96 4388.5 4340.59 4389.42 4344.4 4311.49 4395.12 4313.41 ... 62.98 65.76 65.735 63.59 65.785 63.64 62.98 66.0631 63.0102 66.1
2026-08-11 4434.84 4355.896 4368.46485 4366.8408 4389.22 4370.0889 4390.41 4355.896 4434.84 4357.09 ... 64.2161 64.7 64.675 65.7503 64.725 65.7693 64.2161 66.4702 64.248 66.51
2026-08-12 4440.53 4358.59 4408.69505 4407.062 4366.8301 4410.3281 4370.1299 4358.59 4440.53 4363.05 ... 64.5522 65.325 65.3 64.5522 65.35 64.5678 64.5522 66.7785 64.5678 66.8555
2026-08-13 4449.39 4343.2661 4351.34495 4350.1616 4408.68 4352.5283 4411.08 4343.2661 4449.39 4344.26 ... 64.1932 64.48 64.455 65.3416 64.505 65.4316 64.1932 66.2896 64.2378 66.3351
2026-08-14 4396.81 4310.063 4376.59865 4375.8931 4350.76 4377.3042 4351.8 4310.063 4396.81 4311.4 ... 63.4881 64.6819 64.6569 64.7223 64.7069 64.7673 63.4881 65.6901 63.5331 65.74
2026-08-17 4428.72 4366.6904 4416.82005 4415.1899 4377.12 4418.4502 4385.12 4366.6904 4428.72 4367.79 ... 64.439 65.825 65.8 64.4753 65.85 64.7753 64.439 66.57 64.7187 66.62
2026-08-18 4435.73 4328.0332 4334.51515 4333.3311 4416.95 4335.6992 4418.15 4328.0332 4435.73 4329.69 ... 63.1548 63.3243 63.2993 65.894 63.3493 65.939 63.1548 66.5463 63.194 66.59
2026-08-19 4523.79 4323.7983 4522.795 4521.09 4333.48 4524.5 4335.88 4323.7983 4523.79 4325.19 ... 62.54 66.9422 66.9172 62.735 66.9672 62.825 62.54 66.9916 62.5785 67.0416
2026-08-20 4540.81 4450.083 4519.08 4517.87 4521.9751 4520.29 4522.585 4450.083 4540.81 4450.96 ... 65.6166 68.08765 68.0749 66.79 68.1004 67.09 65.6166 69.02 65.653 69.07
2026-08-21 4631.99 4508.1357 4603.5625 4602.6079 4516.0898 4604.5171 4522.0898 4508.1357 4631.99 4509.53 ... 67.898 68.9925 68.9675 67.9911 69.0175 68.009 67.898 70.02 67.9281 70.07
2026-08-24 4680.7 4594.1289 4651.87 4651.27 4615.79 4652.47 4621.79 4594.1289 4680.7 4595.24 ... 68.287 68.9587 68.9362 69.4647 68.9812 69.6897 68.287 69.912 68.332 70.105
2026-08-25 4696.18 4604.647 4658.59445 4656.5898 4652.91 4660.5991 4655.31 4604.647 4696.18 4605.7 ... 67.43 68.6659 68.6409 69.205 68.6909 69.295 67.43 69.9288 67.463 69.9738
2026-08-26 4673.39 4582.2607 4593.67505 4592.0317 4654.0 4595.3184 4656.4 4582.2607 4673.39 4583.37 ... 67.5 68.1254 68.1004 68.4395 68.1504 68.5295 67.5 69.73 67.5268 69.78
2026-08-27 4642.9 4565.77 4601.2549 4601.0 4595.3 4601.5098 4598.2 4565.77 4642.9 4566.57 ... 67.51 69.2701 69.2564 67.51 69.2838 68.1397 67.51 69.73 67.6 69.78

20 rows × 22 columns

Hide code cell content

ld.close_session()