/***************************************************************************** * Function : createSession * Description : This function creates a session object and opens the market * bar service. Returns false on failure of either. * Arguments : none * Returns : bool *****************************************************************************/ private bool createSession() { if (d_session != null) { d_session.Stop(); } System.Console.WriteLine("Connecting to " + d_sessionOptions.ServerHost + ":" + d_sessionOptions.ServerPort); d_session = new Session(d_sessionOptions, new EventHandler(processEvent)); if (!d_session.Start()) { System.Console.WriteLine("Failed to start session"); return(false); } System.Console.WriteLine("Connected successfully\n"); if (!d_session.OpenService("//blp/mktbar")) { System.Console.WriteLine("Failed to open service //blp/mktbar"); d_session.Stop(); return(false); } System.Console.WriteLine("Subscribing..."); d_session.Subscribe(d_subscriptions); return(true); }
/// <summary> /// Initialises the specified URI session and opens the service. /// </summary> /// <param name="uri">The URI.</param> /// <returns></returns> private bool Initialise(string uri, int requestCount) { sessionOptions = new BB.SessionOptions(); sessionOptions.ServerHost = "localhost"; sessionOptions.ServerPort = 8194; if (requestCount > sessionOptions.MaxPendingRequests) { sessionOptions.MaxPendingRequests = requestCount; } UpdateStatus("Starting the Bloomberg session."); session = new BB.Session(sessionOptions, new BB.EventHandler(processEvent)); if (session.Start()) { if (!session.OpenService(uri)) { throw new Exception("Bloomberg failed to open session " + uri); } return(true); } else { throw new Exception("An error occurred starting the Bloomberg session. Ensure Bloomberg is installed."); } }
/// <summary> /// Initializes the SecurityLookup instance by creating a session and authorizing it so that its /// ready to conduct searches. Once initialized multiple searches may be conducted with the same instance. /// </summary> public void Init() { try { SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerHost = d_host; sessionOptions.ServerPort = d_port; sessionOptions.AuthenticationOptions = d_authOptions; Console.WriteLine("Connecting to {0}:{1}", d_host, d_port); session = new Session(sessionOptions); if (!session.Start()) { throw new Exception("Failed to start session"); } identity = null; if (d_authOptions != null) { Authorize(out identity, session); } if (!session.OpenService(INSTRUMENT_SERVICE)) { throw new Exception( string.Format("Failed to open: {0}", INSTRUMENT_SERVICE)); } } catch (Exception e) { Console.WriteLine(string.Format("Exception: {0}", e.Message)); Console.WriteLine(); } }
/// <summary> /// Sets config and other session data to create the session /// </summary> /// <returns></returns> private Session CreateBloombergSession() { // retrieves the appsettings and fills the config object config = new BloombergApiSessionConfig(); var sessionOptions = new SessionOptions { ServerHost = config.BbHost, ServerPort = config.BbPort }; var session = new Session(sessionOptions); if (!session.Start()) { //_Logging.Error("Unable to initiate Bloomberg session."); return null; } if (!session.OpenService(config.BbService)) { //_Logging.Error("Unable to open Bloomberg service."); return null; } return session; }
public void Connect() { string serverHost = "api.bloomberg.com"; int serverPort = 0; SessionOptions sessionOptions = new SessionOptions(); sessionOptions.ServerHost = serverHost; sessionOptions.ServerPort = serverPort; Log("Connecting to " + serverHost + ":" + serverPort); session = new Session(sessionOptions); bool sessionStarted = session.Start(); if (!sessionStarted) { throw new Exception("Failed to start Bloomberg API session."); } if (!session.OpenService("//blp/refdata")) { throw new Exception("Failed to open //blp/refdata"); } this.service = session.GetService("//blp/refdata"); }
/***************************************************************************** * Function : createSession * Description : This function creates a session object and opens the market * bar service. Returns false on failure. * Arguments : none * Returns : bool *****************************************************************************/ private bool createSession() { if (d_session != null) { d_session.Stop(); } string authOptions = string.Empty; d_sessionOptions = new SessionOptions(); if (d_authOption == "APPLICATION") { // Set Application Authentication Option authOptions = "AuthenticationMode=APPLICATION_ONLY;"; authOptions += "ApplicationAuthenticationType=APPNAME_AND_KEY;"; // ApplicationName is the entry in EMRS. authOptions += "ApplicationName=" + d_name; } else if (d_authOption == "USER_APP") { // Set User and Application Authentication Option authOptions = "AuthenticationMode=USER_AND_APPLICATION;"; authOptions += "AuthenticationType=OS_LOGON;"; authOptions += "ApplicationAuthenticationType=APPNAME_AND_KEY;"; // ApplicationName is the entry in EMRS. authOptions += "ApplicationName=" + d_name; } else if (d_authOption == "USER_DS_APP") { // Set User and Application Authentication Option authOptions = "AuthenticationMode=USER_AND_APPLICATION;"; authOptions += "AuthenticationType=DIRECTORY_SERVICE;"; authOptions += "DirSvcPropertyName=" + d_dsName + ";"; authOptions += "ApplicationAuthenticationType=APPNAME_AND_KEY;"; // ApplicationName is the entry in EMRS. authOptions += "ApplicationName=" + d_name; } else if (d_authOption == "DIRSVC") { // Authenticate user using active directory service property authOptions = "AuthenticationType=DIRECTORY_SERVICE;"; authOptions += "DirSvcPropertyName=" + d_dsName; } else { // Authenticate user using windows/unix login name (default) authOptions = "AuthenticationType=OS_LOGON"; } System.Console.WriteLine("Authentication Options = " + authOptions); d_sessionOptions.AuthenticationOptions = authOptions; SessionOptions.ServerAddress[] servers = new SessionOptions.ServerAddress[d_hosts.Count]; int index = 0; System.Console.WriteLine("Connecting to port " + d_port.ToString() + " on host(s):"); foreach (string host in d_hosts) { servers[index] = new SessionOptions.ServerAddress(host, d_port); System.Console.WriteLine(host); index++; } // auto restart on disconnect d_sessionOptions.ServerAddresses = servers; d_sessionOptions.AutoRestartOnDisconnection = true; d_sessionOptions.NumStartAttempts = d_hosts.Count; // change default subscription service d_sessionOptions.DefaultSubscriptionService = MKTBAR_SVC; // create session and start d_session = new Session(d_sessionOptions, processEvent); return(d_session.Start()); }