I need to get open, high, low, close, volume data from bloomberg api for commodities like CL1, S 1, C1...
Right now, I am doing
from xbbg import blp
blp.bdib(ticker="CL1 COMB Comdty", dt="2021-06-01", exch="CME")
which works for CL1, but it doesn't work when I try anything else. E.g. running
blp.bdib(ticker="S 1 COMB Comdty", dt="2021-06-01", exch="CME")
give me a KeyError: 'Cannot find exchange info for S1 COMB Comdty'
Any clue on how to fix this?
Xbbg uses an 'exchange' purely as a method for working out the timezone and trading hours for calls to the underlying Bloomberg API (as the API only takes a start and end UTC date/time).
The reason that "CL1" works and "S 1" doesn't is that the former ticker is listed in the default xbbg assets.yml file. This file provides a lookup of common tickers to identify their trading hours / TZ. The 'exchanges' are listed in exch.yml.
The parameter name to use for tickers that are not in assets.yml to specify CME is 'ref':
df = blp.bdib(ticker="S 1 COMB Comdty", dt="2021-06-01", ref="CME")
print(df.tail())
which gives:
S 1 COMB Comdty ...
open high ... num_trds value
2021-06-01 14:15:00-04:00 1548.75 1550.00 ... 105 365683.75
2021-06-01 14:16:00-04:00 1549.75 1550.00 ... 45 161172.75
2021-06-01 14:17:00-04:00 1549.50 1549.50 ... 29 139409.25
2021-06-01 14:18:00-04:00 1548.50 1549.00 ... 24 168826.25
2021-06-01 14:19:00-04:00 1548.25 1548.75 ... 43 247673.00
Alternatively you could add an entry to the assets.yml file ( on the path \Lib\site-packages\xbbg\markets\assets.yml ):
Comdty:
...
- tickers: [S]
exch: CME
freq: M
is_fut: True
...
And then you can just call:
df = blp.bdib(ticker="S 1 COMB Comdty", dt="2021-06-01")
The exch.yml entry for CME is:
CME:
tz: America/New_York
allday: [1800, 1700]
day: [800, 1700]