我正在研究Bloomberg API,我遵循了本教程
但我收到错误
InvalidOperationException未处理:会话未在line result = session.OpenService(“// blp / refdata”);
我是Bloomberg的新手,想要使用它的API,请让我知道如何纠正这些错误。以下是我的代码。谢谢
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();
}
}
}
答案 0 :(得分:1)
我已在我的机器上运行您的代码并且它正常工作,print语句打印IBM的历史价格。我在运行代码时登录了我的Bloomberg终端,是吗?您要求的信息仅由Bloomberg提供给终端客户,终端许可证每年约2万美元,但提供丰富的财务信息。