Home : J-Integra for COM : Accessing Bloomberg® from Java
Q40283 - HOWTO: Accessing Bloomberg® from Java

Accessing Bloomberg® from Java

The following example shows how to access the Bloomberg® BLP Data Control from Java using J-Integra. This example will run on any OS, run on any platform, and requires no native code (no DLLs). You can also download this example by clicking on the attachment below.

For a third-party solution leveraging J-Integra, please see Optura®'s Virtual Investment Analytics (VIA) automation platform. Additional information can also be found here.

/* This example shows a pure Java client using the J-Integra pure Java-COM 
 * bridge to talk to the Bloomberg® BLP Data Control. You can run this
 * program on any machine that supports a standard JVM.
 *
 * Create a file called BloombergExample.java containing this Java code.
 * Create a subdirectory called "blpdatax" under the directory containing
 * this Java program.
 *
 * Generate the pure Java proxy files used by this program to access the
 * Bloomberg® BLP Data Control by running the 'com2java' tool from the J-Integra
 * 'bin' directory. Specify "blpdatax.dll" as the type library, "blpdatax"
 * as the package name, and the blpdatax subdirectory you created above as the
 * output directory.
 *
 * You will also need to create a surrogate for "blpdatax.dll" using the
 * setdllhost tool. Open a command prompt and 'cd' to the directory containing
 * the blpdatax.dll file. Enter the following command:
 * > setdllhost blpdatax.dll "Blpdatax"
 *
 * You may have to run DCOMCNFG and check that the DCOM settings for the new
 * surrogate are configured properly. For more information on DCOM configuration,
 * please see http://j-integra.intrinsyc.com/support/com/doc/remoteaccess.html.
 *
 * This example is courtesy of Mathew George of UBS Warburg: http://www.ubswarburg.com
 */ import blpdatax.*; public class BloombergExample {
  public static void main(String[] args) {
    try {
      Object returnedValues = null;
      Object[] bbgResultsArray = null;       System.out.println("Accessing Bloomberg...");       // Create the Bloomberg® object
      IBlpData2 blp = new BlpData();       // Products: An Object array of ISIN codes
      Object products = new Object[] {};       // BloombergFields: A String array of fields we want Bloomberg to calculate values for
      // e.g. PX_BID, YLD_YTM_BID, CNVX_BID, DAYS_ACC, INT_ACC, etc.
      Object bloombergFields = new String[] {};       // OverrideFields: An Object array of fields we want to override the values for
      // e.g. PX_BID, SETTLE_DT
      Object overrideFields = new Object[] {};       // OverrideValues: An Object array of the values we want to assign to these overriden fields
      Object overrideValues = new Object[] {};       // Call the subscribe method on this object, returning a 3-D array
      returnedValues = blp.getBLPSubscribe(products, bloombergFields,
                                           overrideFields, overrideValues);       System.out.println("Finished with Bloomberg...");       // Work with the returned data
      bbgResultsArray = (Object[])returnedValues;
      Object[] productsArr = (Object[])products;
      String[] bloombergFieldsArr = (String[])bloombergFields;       for(int i=0; i < productsArr.length; i++) {
        Object[] bbgResults = (Object[])bbgResultsArray[i];         for(int j=0; j < bloombergFieldsArr.length; j++) {
          Object bbgValue = bbgResults[j];
          double resultValue = 0.0;
          if ( !(bbgValue instanceof String) ) {
            Double doubleValue = (Double)bbgValue;
            resultValue = doubleValue.doubleValue();
          }           // Display the results for each product and field
          System.out.println("product[" + i + "]: " + productsArr[i]);
          System.out.println("bloombergField[" + j + "]: " + bloombergFieldsArr[j]);
          System.out.println("value: " + resultValue);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      com.linar.jintegra.Cleaner.releaseAll();
    }
  }
}
Related Articles
No Related Articles Available.

Article Attachments
BloombergExample.zip

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 5/4/2010.
Last Modified by J-Integra KB Admin.
Article has been viewed 18037 times.
Rated 5 out of 10 based on 31 votes.
Print Article
Email Article