Retrieve Bloomberg Current Data Using Bloomberg B-PIPE C++ Interface
This example shows how to retrieve current data from Bloomberg® for a single security and for multiple securities.
Connect to Bloomberg
Create a Bloomberg B-PIPE® connection using the IP address of the machine running the Bloomberg B-PIPE process. This example uses the Bloomberg B-PIPE C++ interface and assumes the following:
The authentication is Windows® authentication when you set
authtypeto'OS_LOGON'.The application name is blank because you are not connecting to Bloomberg B-PIPE using an application.
The IP address for the machine running the Bloomberg B-PIPE process is
'111.11.11.112'.The port number of the machine running the Bloomberg B-PIPE process is
8194.
c is a bloombergBPIPE object.
authtype = 'OS_LOGON'; appname = ''; ipaddress = {'111.11.11.112'}; port = 8194; c = bloombergBPIPE(authtype,appname,ipaddress,port);
Validate the Bloomberg connection.
v = isconnection(c)
v =
1
v returns true showing that the Bloomberg connection is valid.
Retrieve Current Data for Single Security
Retrieve last and open prices for Microsoft®.
d contains the Bloomberg last and open prices as fields in a structure. sec
contains the Bloomberg security name for Microsoft in a cell array. The security name is a character vector.
sec = 'MSFT US Equity'; fields = {'LAST_PRICE';'OPEN'}; % Retrieve data for last and open prices [d,sec] = getdata(c,sec,fields)
d =
struct with fields:
LAST_PRICE: 62.30
OPEN: 62.95
sec =
cell
'MSFT US Equity'Retrieve Current Data for Multiple Securities
Retrieve last and open prices for the IBM® and Ford Motor Company® securities.
d contains the Bloomberg last and open prices as fields in a structure. sec
contains the Bloomberg security names for IBM and Ford Motor Company in a cell array. Each security name is a character vector.
s = {'IBM US Equity','F US Equity'};
fields = {'LAST_PRICE';'OPEN'}; % Retrieve data for last and open prices
[d,sec] = getdata(c,s,fields)d =
struct with fields:
LAST_PRICE: [2×1 double]
OPEN: [2×1 double]
sec =
2×1 cell array
'IBM US Equity'
'F US Equity'Display the last price for both securities.
d.LAST_PRICE
ans =
166.73
12.63
Close Bloomberg Connection
close(c)
See Also
Objects
Functions
close|getdata|isconnection