import blpdatax.BlpData;
import blpdatax._BlpDataEventsAdapter;
public class RealTimeDataExample {
// fire event types
final static int ByField = 0;
final static int ByRequest = 1;
final static int BySecurity = 2;
// list of securities we wish to monitor
static Object[] security = {"MSFT US Equity", "IBM US Equity", "EUR Curncy", "CAD Curncy"};
// security fields we wish to monitor
static Object[] fields = {"Last_Price", "Bid", "Ask", "Volume", "High", "Low"};
public static void main(String[] args) {
try{
//Uncomment this line if running J-Integra in native mode
//i.e. Java and Bloomberg are running in the same machine
//System.setProperty("JINTEGRA_NATIVE_MODE", "");
// Uncomment this line if running J-Integra in DCOM mode
// i.e. Java and Bloomberg are in different machines
// DCOM authentication: Make sure NT Domain, NT User, NT Password are valid credentials.
//com.linar.jintegra.AuthInfo.setDefault("NT DOMAIN", "NT USER", "NT PASSWORD");
// Create the Bloomberg object
// Specify host name or IP address of Bloomberg machine as parameter if
// running in DCOM mode, e.g.:
// BlpData blp = new BlpData("123.456.789.0");
BlpData bloomberg = new BlpData();
// set some configuration parameters
bloomberg.setSubscriptionMode(BySecurity);
bloomberg.setAutoRelease(false);
bloomberg.setActivateRealtime(true);
// add data listener
DataListener dataListener = new DataListener();
bloomberg.add_BlpDataEventsListener(dataListener);
// package the parameters
Object[] params = { security, new Integer(0), fields, null, null, null, null };
// call the subscribe method via late binding
// this is a workaround since early binding does not work
bloomberg.invokeMethodByName("subscribe", params);
// flush out the data
bloomberg.flush();
// let the program run indefinitely
while (true) {
Thread.sleep(10000);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
com.linar.jintegra.Cleaner.releaseAll();
}
}
}
class DataListener extends _BlpDataEventsAdapter {
// this event is called once the request is flushed out
public void data (blpdatax._BlpDataEventsDataEvent theEvent) throws java.io.IOException, com.linar.jintegra.AutomationException {
System.out.println("\n *** DATA EVENT CALLED *** " );
// obtain which stock info changed
Object[] securityArray = (Object[]) theEvent.getSecurity();
System.out.println("Security: " + securityArray[0]);
// display updated data
Object[] dataArray = (Object[]) theEvent.getData();
for(int i=0; i<dataArray.length; i++){
System.out.println(RealTimeDataExample.fields[i] + ": " + dataArray[i]);
}
}
public void status (blpdatax._BlpDataEventsStatusEvent theEvent) throws java.io.IOException, com.linar.jintegra.AutomationException {
System.out.println("*** STATUS EVENT CALLED *** " );
}
}
|