I am working on Bloomberg API, I followed this tutorial
but i am getting error
InvalidOperationException was unhandled : Session not started at line result = session.OpenService("//blp/refdata");
i am new to Bloomberg and want to use its API so please let me know how to rectify these error. Below is my code. Thanks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bloomberglp.Blpapi;
namespace Bloomberg
{
class Program
{
static void Main(string[] args)
{
bool result;
bool done = false;
SessionOptions sessionOptions = new SessionOptions();
sessionOptions.ServerHost = "localhost";
sessionOptions.ServerPort = 8194;
Session session = new Session(sessionOptions);
result = session.Start();
result = session.OpenService("//blp/refdata");
Service referenceService = session.GetService("//blp/refdata");
Request request = referenceService.CreateRequest("HistoricalDataRequest");
request.Append("securities", "IBM US Equity");
request.Append("fields", "PX_LAST");
request.Set("startDate", "20130601");
request.Set("endDate", "20130630");
request.Set("maxDataPoints", 20);
session.SendRequest(request, null);
done = false;
while (!done)
{
Event eventObject = session.NextEvent();
if (eventObject.Type == Event.EventType.RESPONSE)
{
foreach (Message msg in eventObject)
{
System.Console.WriteLine(msg);
}
done = true;
}
}
Console.ReadKey();
session.Stop();
}
}
}
I have run your code on my machine and it works, the print statements print the historical prices of IBM. I was logged into my Bloomberg Terminal when running the code, were you? The info you're requesting is provided by Bloomberg only to Terminal clients, the Terminal license costs about $20K/year but provides a wealth of financial information.