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

  1. # Borrowed from https://stackoverflow.com/questions/32891719/talend-split-a-data-file-into-two-flows-streams-header-info-data-rows
  2. START-OF-FILE
  3. RUNDATE=20150921
  4. PROGRAMFLAG=oneshot
  5.  
  6. DATEFORMAT=yyyymmdd_sep
  7. FIRMNAME=dl111111
  8. FILETYPE=pc
  9. REPLYFILENAME=r150921020044_20426_01_00
  10. SECMASTER=yes
  11. DERIVED=yes
  12. CREDITRISK=yes
  13. USERNUMBER=1111111
  14. WS=0
  15. SN=111111
  16. CLOSINGVALUES=yes
  17. SECID=BB_GLOBAL
  18. PROGRAMNAME=getdata
  19.  
  20. START-OF-FIELDS
  21. EXCH_CODE
  22. ID_BB_GLOBAL
  23. NAME
  24. SECURITY_TYP
  25. TICKER
  26. END-OF-FIELDS
  27.  
  28. TIMESTARTED=Mon Sep 21 01:01:18 BST 2015
  29. START-OF-DATA
  30. BBG004C5BLW2|0|5|LABUAN INTL FIN|BBG004C5BLW2|1MDB GLOBAL INVESTMENTS|EURO-DOLLAR|OGIMK|
  31. BBG000MGZ064|0|5|HK|BBG000MGZ064|361 DEGREES INTERNATIONAL|Common Stock|1361|
  32. BBG000QVRHX9|0|5|AV|BBG000QVRHX9|3BG EMCORE CONVRT GLB-A|Open-End Fund|EMBDGCA|
  33. BBG000BP52R2|0|5|US|BBG000BP52R2|3M CO|Common Stock|MMM|
  34. BBG0068TPTD9|0|5|TRACE|BBG0068TPTD9|51JOB INC|US DOMESTIC|JOBS|
  35. BBG0069D1BR3|0|5|NOT LISTED|BBG0069D1BR3|51JOB INC|EURO-DOLLAR|JOBS|
  36. BBG000BJD1D4|0|5|US|BBG000BJD1D4|51JOB INC-ADR|ADR|JOBS|
  37. BBG008CTTWK1|0|5|FRANKFURT|BBG008CTTWK1|AABAR INVESTMENTS PJSC|EURO MTN|AABAR|
  38. BBG008D4J9S9|0|5|FRANKFURT|BBG008D4J9S9|AABAR INVESTMENTS PJSC|EURO MTN|AABAR|
  39. BBG008B2BXH2|0|5|SIX|BBG008B2BXH2|AARGAUISCHE KANTONALBANK|DOMESTIC|KBAARG|
  40. BBG0016WJL30|0|5|LX|BBG0016WJL30|AB-AMERICAN INCOME PT-ATEURH|Open-End Fund|ABAATEH|
  41. BBG006F3D598|0|5|BH|BBG006F3D598|ABBEY CAPITAL DAILY FUTURE-B|Fund of Funds|ABBDFUB|
  42. END-OF-DATA
  43. TIMEFINISHED=Mon Sep 21 01:03:22 BST 2015
  44. END-OF-FILE

 

Java Code Listing

  1. package com.northconcepts.datapipeline.examples.bloomberg;
  2.  
  3. import java.io.File;
  4.  
  5. import com.northconcepts.datapipeline.bloomberg.BloombergMessage;
  6. import com.northconcepts.datapipeline.bloomberg.BloombergMessageReader;
  7. import com.northconcepts.datapipeline.core.DataWriter;
  8. import com.northconcepts.datapipeline.core.StreamWriter;
  9. import com.northconcepts.datapipeline.job.Job;
  10.  
  11. public class ReadABloombergMessageFile {
  12.  
  13. public static void main(String[] args) {
  14. File file = new File("data/input/example-talend-stackoverflow.req");
  15. BloombergMessageReader reader = new BloombergMessageReader(file);
  16. DataWriter writer = new StreamWriter(System.out);
  17. Job.run(reader, writer);
  18. // message is available after BloombergMessageReader.open() is called in Job.run(reader, writer) above
  19. BloombergMessage message = reader.getMessage();
  20. System.out.println("-----------------------------------------------");
  21. System.out.println("Header: " + message.getHeader().getProperties());
  22. System.out.println("Fields: " + message.getFields().getFields());
  23. System.out.println("Records: " + message.getData().getRecords().size());
  24. System.out.println("Footers: " + message.getFooter().getProperties());
  25. }
  26.  
  27. }
  28.  

 

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

  1. -----------------------------------------------
  2. 0 - Record {
  3. 0:[A]:STRING=[BBG004C5BLW2]:String
  4. 1:[B]:STRING=[0]:String
  5. 2:[C]:STRING=[5]:String
  6. 3:[D]:STRING=[LABUAN INTL FIN]:String
  7. 4:[E]:STRING=[BBG004C5BLW2]:String
  8. 5:[F]:STRING=[1MDB GLOBAL INVESTMENTS]:String
  9. 6:[G]:STRING=[EURO-DOLLAR]:String
  10. 7:[H]:STRING=[OGIMK]:String
  11. 8:[I]:STRING=[null]
  12. }
  13.  
  14. -----------------------------------------------
  15. 1 - Record {
  16. 0:[A]:STRING=[BBG000MGZ064]:String
  17. 1:[B]:STRING=[0]:String
  18. 2:[C]:STRING=[5]:String
  19. 3:[D]:STRING=[HK]:String
  20. 4:[E]:STRING=[BBG000MGZ064]:String
  21. 5:[F]:STRING=[361 DEGREES INTERNATIONAL]:String
  22. 6:[G]:STRING=[Common Stock]:String
  23. 7:[H]:STRING=[1361]:String
  24. 8:[I]:STRING=[null]
  25. }
  26.  
  27. -----------------------------------------------
  28. 2 - Record {
  29. 0:[A]:STRING=[BBG000QVRHX9]:String
  30. 1:[B]:STRING=[0]:String
  31. 2:[C]:STRING=[5]:String
  32. 3:[D]:STRING=[AV]:String
  33. 4:[E]:STRING=[BBG000QVRHX9]:String
  34. 5:[F]:STRING=[3BG EMCORE CONVRT GLB-A]:String
  35. 6:[G]:STRING=[Open-End Fund]:String
  36. 7:[H]:STRING=[EMBDGCA]:String
  37. 8:[I]:STRING=[null]
  38. }
  39.  
  40. -----------------------------------------------
  41. 3 - Record {
  42. 0:[A]:STRING=[BBG000BP52R2]:String
  43. 1:[B]:STRING=[0]:String
  44. 2:[C]:STRING=[5]:String
  45. 3:[D]:STRING=[US]:String
  46. 4:[E]:STRING=[BBG000BP52R2]:String
  47. 5:[F]:STRING=[3M CO]:String
  48. 6:[G]:STRING=[Common Stock]:String
  49. 7:[H]:STRING=[MMM]:String
  50. 8:[I]:STRING=[null]
  51. }
  52.  
  53. -----------------------------------------------
  54. 4 - Record {
  55. 0:[A]:STRING=[BBG0068TPTD9]:String
  56. 1:[B]:STRING=[0]:String
  57. 2:[C]:STRING=[5]:String
  58. 3:[D]:STRING=[TRACE]:String
  59. 4:[E]:STRING=[BBG0068TPTD9]:String
  60. 5:[F]:STRING=[51JOB INC]:String
  61. 6:[G]:STRING=[US DOMESTIC]:String
  62. 7:[H]:STRING=[JOBS]:String
  63. 8:[I]:STRING=[null]
  64. }
  65.  
  66. -----------------------------------------------
  67. 5 - Record {
  68. 0:[A]:STRING=[BBG0069D1BR3]:String
  69. 1:[B]:STRING=[0]:String
  70. 2:[C]:STRING=[5]:String
  71. 3:[D]:STRING=[NOT LISTED]:String
  72. 4:[E]:STRING=[BBG0069D1BR3]:String
  73. 5:[F]:STRING=[51JOB INC]:String
  74. 6:[G]:STRING=[EURO-DOLLAR]:String
  75. 7:[H]:STRING=[JOBS]:String
  76. 8:[I]:STRING=[null]
  77. }
  78.  
  79. -----------------------------------------------
  80. 6 - Record {
  81. 0:[A]:STRING=[BBG000BJD1D4]:String
  82. 1:[B]:STRING=[0]:String
  83. 2:[C]:STRING=[5]:String
  84. 3:[D]:STRING=[US]:String
  85. 4:[E]:STRING=[BBG000BJD1D4]:String
  86. 5:[F]:STRING=[51JOB INC-ADR]:String
  87. 6:[G]:STRING=[ADR]:String
  88. 7:[H]:STRING=[JOBS]:String
  89. 8:[I]:STRING=[null]
  90. }
  91.  
  92. -----------------------------------------------
  93. 7 - Record {
  94. 0:[A]:STRING=[BBG008CTTWK1]:String
  95. 1:[B]:STRING=[0]:String
  96. 2:[C]:STRING=[5]:String
  97. 3:[D]:STRING=[FRANKFURT]:String
  98. 4:[E]:STRING=[BBG008CTTWK1]:String
  99. 5:[F]:STRING=[AABAR INVESTMENTS PJSC]:String
  100. 6:[G]:STRING=[EURO MTN]:String
  101. 7:[H]:STRING=[AABAR]:String
  102. 8:[I]:STRING=[null]
  103. }
  104.  
  105. -----------------------------------------------
  106. 8 - Record {
  107. 0:[A]:STRING=[BBG008D4J9S9]:String
  108. 1:[B]:STRING=[0]:String
  109. 2:[C]:STRING=[5]:String
  110. 3:[D]:STRING=[FRANKFURT]:String
  111. 4:[E]:STRING=[BBG008D4J9S9]:String
  112. 5:[F]:STRING=[AABAR INVESTMENTS PJSC]:String
  113. 6:[G]:STRING=[EURO MTN]:String
  114. 7:[H]:STRING=[AABAR]:String
  115. 8:[I]:STRING=[null]
  116. }
  117.  
  118. -----------------------------------------------
  119. 9 - Record {
  120. 0:[A]:STRING=[BBG008B2BXH2]:String
  121. 1:[B]:STRING=[0]:String
  122. 2:[C]:STRING=[5]:String
  123. 3:[D]:STRING=[SIX]:String
  124. 4:[E]:STRING=[BBG008B2BXH2]:String
  125. 5:[F]:STRING=[AARGAUISCHE KANTONALBANK]:String
  126. 6:[G]:STRING=[DOMESTIC]:String
  127. 7:[H]:STRING=[KBAARG]:String
  128. 8:[I]:STRING=[null]
  129. }
  130.  
  131. -----------------------------------------------
  132. 10 - Record {
  133. 0:[A]:STRING=[BBG0016WJL30]:String
  134. 1:[B]:STRING=[0]:String
  135. 2:[C]:STRING=[5]:String
  136. 3:[D]:STRING=[LX]:String
  137. 4:[E]:STRING=[BBG0016WJL30]:String
  138. 5:[F]:STRING=[AB-AMERICAN INCOME PT-ATEURH]:String
  139. 6:[G]:STRING=[Open-End Fund]:String
  140. 7:[H]:STRING=[ABAATEH]:String
  141. 8:[I]:STRING=[null]
  142. }
  143.  
  144. -----------------------------------------------
  145. 11 - Record {
  146. 0:[A]:STRING=[BBG006F3D598]:String
  147. 1:[B]:STRING=[0]:String
  148. 2:[C]:STRING=[5]:String
  149. 3:[D]:STRING=[BH]:String
  150. 4:[E]:STRING=[BBG006F3D598]:String
  151. 5:[F]:STRING=[ABBEY CAPITAL DAILY FUTURE-B]:String
  152. 6:[G]:STRING=[Fund of Funds]:String
  153. 7:[H]:STRING=[ABBDFUB]:String
  154. 8:[I]:STRING=[null]
  155. }
  156.  
  157. -----------------------------------------------
  158. 12 records
  159. 16:26:55,572 DEBUG [main] datapipeline:661 - job::Success
  160. -----------------------------------------------
  161. 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]}
  162. Fields: [EXCH_CODE, ID_BB_GLOBAL, NAME, SECURITY_TYP, TICKER]
  163. Records: 12
  164. Footers: {TIMEFINISHED=[Mon Sep 21 01:03:22 BST 2015]}
Mobile Analytics