Read a Bloomberg Message File

Updated: Jun 24, 2023

In this example, you are going to learn how you can use DataPipeline to read Bloomberg message files (.req), which are commonly used in financial markets for transmitting real-time and historical market data. It provides functionality to parse and extract data from these message files, allowing users to access and analyze the financial information contained within.

Real-life use cases for this library can be found in the financial industry, where professionals such as traders, analysts, and researchers rely on Bloomberg data for making informed investment decisions. By reading and processing Bloomberg message files, users can extract relevant market data, such as prices, volumes, trade details, and other essential information. They can then use this data for various purposes, such as backtesting trading strategies, conducting market research, performing data analysis, and generating reports. The library simplifies the extraction and utilization of Bloomberg data, enabling users to access the information they need efficiently and effectively.

 

Input File

# Borrowed from https://stackoverflow.com/questions/32891719/talend-split-a-data-file-into-two-flows-streams-header-info-data-rows
START-OF-FILE
RUNDATE=20150921
PROGRAMFLAG=oneshot

DATEFORMAT=yyyymmdd_sep
FIRMNAME=dl111111
FILETYPE=pc
REPLYFILENAME=r150921020044_20426_01_00
SECMASTER=yes
DERIVED=yes
CREDITRISK=yes
USERNUMBER=1111111
WS=0
SN=111111
CLOSINGVALUES=yes
SECID=BB_GLOBAL
PROGRAMNAME=getdata

START-OF-FIELDS
EXCH_CODE
ID_BB_GLOBAL
NAME
SECURITY_TYP
TICKER
END-OF-FIELDS

TIMESTARTED=Mon Sep 21 01:01:18 BST 2015
START-OF-DATA
BBG004C5BLW2|0|5|LABUAN INTL FIN|BBG004C5BLW2|1MDB GLOBAL INVESTMENTS|EURO-DOLLAR|OGIMK|
BBG000MGZ064|0|5|HK|BBG000MGZ064|361 DEGREES INTERNATIONAL|Common Stock|1361|
BBG000QVRHX9|0|5|AV|BBG000QVRHX9|3BG EMCORE CONVRT GLB-A|Open-End Fund|EMBDGCA|
BBG000BP52R2|0|5|US|BBG000BP52R2|3M CO|Common Stock|MMM|
BBG0068TPTD9|0|5|TRACE|BBG0068TPTD9|51JOB INC|US DOMESTIC|JOBS|
BBG0069D1BR3|0|5|NOT LISTED|BBG0069D1BR3|51JOB INC|EURO-DOLLAR|JOBS|
BBG000BJD1D4|0|5|US|BBG000BJD1D4|51JOB INC-ADR|ADR|JOBS|
BBG008CTTWK1|0|5|FRANKFURT|BBG008CTTWK1|AABAR INVESTMENTS PJSC|EURO MTN|AABAR|
BBG008D4J9S9|0|5|FRANKFURT|BBG008D4J9S9|AABAR INVESTMENTS PJSC|EURO MTN|AABAR|
BBG008B2BXH2|0|5|SIX|BBG008B2BXH2|AARGAUISCHE KANTONALBANK|DOMESTIC|KBAARG|
BBG0016WJL30|0|5|LX|BBG0016WJL30|AB-AMERICAN INCOME PT-ATEURH|Open-End Fund|ABAATEH|
BBG006F3D598|0|5|BH|BBG006F3D598|ABBEY CAPITAL DAILY FUTURE-B|Fund of Funds|ABBDFUB|
END-OF-DATA
TIMEFINISHED=Mon Sep 21 01:03:22 BST 2015
END-OF-FILE

 

Java Code Listing

package com.northconcepts.datapipeline.examples.bloomberg;

import java.io.File;

import com.northconcepts.datapipeline.bloomberg.BloombergMessage;
import com.northconcepts.datapipeline.bloomberg.BloombergMessageReader;
import com.northconcepts.datapipeline.core.DataWriter;
import com.northconcepts.datapipeline.core.StreamWriter;
import com.northconcepts.datapipeline.job.Job;

public class ReadABloombergMessageFile {

    public static void main(String[] args) {
        File file = new File("data/input/example-talend-stackoverflow.req");
        
        BloombergMessageReader reader = new BloombergMessageReader(file);
        DataWriter writer = new StreamWriter(System.out);
        Job.run(reader,  writer);
        
        // message is available after BloombergMessageReader.open() is called in Job.run(reader,  writer) above
        BloombergMessage message = reader.getMessage();  
        System.out.println("-----------------------------------------------");
        System.out.println("Header: " + message.getHeader().getProperties());
        System.out.println("Fields: " + message.getFields().getFields());
        System.out.println("Records: " + message.getData().getRecords().size());
        System.out.println("Footers: " + message.getFooter().getProperties());
    }

}

 

Code Walkthrough

  1. BloombergMessageReader is created corresponding to the input file example-talend-stackoverflow.req .
  2. StreamWriter will be responsible for writing the output to the console .
  3. Job.run(reader, writer) is used to transfer the data from reader to the writer.
  4. A message object of type BloombergMessage is then created to fetch the message from the reader.
  5. Lastly, we print out the message details e.g. message.getData().getRecords().size() that will return the number of records and message.getFields().getFields() that will return the field names.

 

Console Output

-----------------------------------------------
0 - Record {
    0:[A]:STRING=[BBG004C5BLW2]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[LABUAN INTL FIN]:String
    4:[E]:STRING=[BBG004C5BLW2]:String
    5:[F]:STRING=[1MDB GLOBAL INVESTMENTS]:String
    6:[G]:STRING=[EURO-DOLLAR]:String
    7:[H]:STRING=[OGIMK]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
1 - Record {
    0:[A]:STRING=[BBG000MGZ064]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[HK]:String
    4:[E]:STRING=[BBG000MGZ064]:String
    5:[F]:STRING=[361 DEGREES INTERNATIONAL]:String
    6:[G]:STRING=[Common Stock]:String
    7:[H]:STRING=[1361]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
2 - Record {
    0:[A]:STRING=[BBG000QVRHX9]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[AV]:String
    4:[E]:STRING=[BBG000QVRHX9]:String
    5:[F]:STRING=[3BG EMCORE CONVRT GLB-A]:String
    6:[G]:STRING=[Open-End Fund]:String
    7:[H]:STRING=[EMBDGCA]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
3 - Record {
    0:[A]:STRING=[BBG000BP52R2]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[US]:String
    4:[E]:STRING=[BBG000BP52R2]:String
    5:[F]:STRING=[3M CO]:String
    6:[G]:STRING=[Common Stock]:String
    7:[H]:STRING=[MMM]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
4 - Record {
    0:[A]:STRING=[BBG0068TPTD9]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[TRACE]:String
    4:[E]:STRING=[BBG0068TPTD9]:String
    5:[F]:STRING=[51JOB INC]:String
    6:[G]:STRING=[US DOMESTIC]:String
    7:[H]:STRING=[JOBS]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
5 - Record {
    0:[A]:STRING=[BBG0069D1BR3]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[NOT LISTED]:String
    4:[E]:STRING=[BBG0069D1BR3]:String
    5:[F]:STRING=[51JOB INC]:String
    6:[G]:STRING=[EURO-DOLLAR]:String
    7:[H]:STRING=[JOBS]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
6 - Record {
    0:[A]:STRING=[BBG000BJD1D4]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[US]:String
    4:[E]:STRING=[BBG000BJD1D4]:String
    5:[F]:STRING=[51JOB INC-ADR]:String
    6:[G]:STRING=[ADR]:String
    7:[H]:STRING=[JOBS]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
7 - Record {
    0:[A]:STRING=[BBG008CTTWK1]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[FRANKFURT]:String
    4:[E]:STRING=[BBG008CTTWK1]:String
    5:[F]:STRING=[AABAR INVESTMENTS PJSC]:String
    6:[G]:STRING=[EURO MTN]:String
    7:[H]:STRING=[AABAR]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
8 - Record {
    0:[A]:STRING=[BBG008D4J9S9]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[FRANKFURT]:String
    4:[E]:STRING=[BBG008D4J9S9]:String
    5:[F]:STRING=[AABAR INVESTMENTS PJSC]:String
    6:[G]:STRING=[EURO MTN]:String
    7:[H]:STRING=[AABAR]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
9 - Record {
    0:[A]:STRING=[BBG008B2BXH2]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[SIX]:String
    4:[E]:STRING=[BBG008B2BXH2]:String
    5:[F]:STRING=[AARGAUISCHE KANTONALBANK]:String
    6:[G]:STRING=[DOMESTIC]:String
    7:[H]:STRING=[KBAARG]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
10 - Record {
    0:[A]:STRING=[BBG0016WJL30]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[LX]:String
    4:[E]:STRING=[BBG0016WJL30]:String
    5:[F]:STRING=[AB-AMERICAN INCOME PT-ATEURH]:String
    6:[G]:STRING=[Open-End Fund]:String
    7:[H]:STRING=[ABAATEH]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
11 - Record {
    0:[A]:STRING=[BBG006F3D598]:String
    1:[B]:STRING=[0]:String
    2:[C]:STRING=[5]:String
    3:[D]:STRING=[BH]:String
    4:[E]:STRING=[BBG006F3D598]:String
    5:[F]:STRING=[ABBEY CAPITAL DAILY FUTURE-B]:String
    6:[G]:STRING=[Fund of Funds]:String
    7:[H]:STRING=[ABBDFUB]:String
    8:[I]:STRING=[null]
}

-----------------------------------------------
12 records
16:26:55,572 DEBUG [main] datapipeline:661 - job::Success
-----------------------------------------------
Header: {RUNDATE=[20150921], PROGRAMFLAG=[oneshot], DATEFORMAT=[yyyymmdd_sep], FIRMNAME=[dl111111], FILETYPE=[pc], REPLYFILENAME=[r150921020044_20426_01_00], SECMASTER=[yes], DERIVED=[yes], CREDITRISK=[yes], USERNUMBER=[1111111], WS=[0], SN=[111111], CLOSINGVALUES=[yes], SECID=[BB_GLOBAL], PROGRAMNAME=[getdata], TIMESTARTED=[Mon Sep 21 01:01:18 BST 2015]}
Fields: [EXCH_CODE, ID_BB_GLOBAL, NAME, SECURITY_TYP, TICKER]
Records: 12
Footers: {TIMEFINISHED=[Mon Sep 21 01:03:22 BST 2015]}
Mobile Analytics