作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Bloomberg API 来获取市场数据,这是 API SDK 给出的示例
package blpapi;
import com.bloomberglp.blpapi.CorrelationID;
import com.bloomberglp.blpapi.Element;
import com.bloomberglp.blpapi.Event;
import com.bloomberglp.blpapi.Message;
import com.bloomberglp.blpapi.MessageIterator;
import com.bloomberglp.blpapi.Name;
import com.bloomberglp.blpapi.Request;
import com.bloomberglp.blpapi.Service;
import com.bloomberglp.blpapi.Session;
import com.bloomberglp.blpapi.SessionOptions;
public class SimpleRefDataExample {
private static final Name SECURITY_DATA = new Name("securityData");
private static final Name SECURITY = new Name("security");
private static final Name FIELD_DATA = new Name("fieldData");
private static final Name FIELD_EXCEPTIONS = new Name("fieldExceptions");
private static final Name FIELD_ID = new Name("fieldId");
private static final Name ERROR_INFO = new Name("errorInfo");
private CorrelationID d_cid;
public static void main(String[] args) throws Exception {
SimpleRefDataExample example = new SimpleRefDataExample();
example.run(args);
System.out.println("Press ENTER to quit");
System.in.read();
}
private void run(String[] args) throws Exception {
String serverHost = "localhost";
int serverPort = 35230;
SessionOptions sessionOptions = new SessionOptions();
sessionOptions.setServerHost(serverHost);
sessionOptions.setServerPort(serverPort);
Session session = new Session(sessionOptions);
System.out.println("Connecting to " + serverHost + ":" + serverPort);
if (!session.start()) {
System.err.println("Failed to start session.");
return;
}
System.out.println("Connected successfully.");
if (!session.openService("//blp/refdata")) {
System.err.println("Failed to open //blp/refdata");
return;
}
Service refDataService = session.getService("//blp/refdata");
Request request = refDataService.createRequest("ReferenceDataRequest");
// append securities to request
Element securities = request.getElement("securities");
securities.appendValue("IBM US Equity");
securities.appendValue("/cusip/912828GM6@BGN");
// append fields to request
Element fields = request.getElement("fields");
fields.appendValue("PX_LAST");
fields.appendValue("DS002");
System.out.println("Sending Request: " + request);
d_cid = session.sendRequest(request, null);
while (true) {
Event event = session.nextEvent();
MessageIterator msgIter = event.messageIterator();
while (msgIter.hasNext()) {
Message msg = msgIter.next();
if (msg.correlationID() == d_cid) {
processMessage(msg);
}
}
if (event.eventType() == Event.EventType.RESPONSE) {
break;
}
}
}
private void processMessage(Message msg) throws Exception {
Element securityDataArray = msg.getElement(SECURITY_DATA);
int numSecurities = securityDataArray.numValues();
for (int i = 0; i < numSecurities; ++i) {
Element securityData = securityDataArray.getValueAsElement(i);
System.out.println(securityData.getElementAsString(SECURITY));
Element fieldData = securityData.getElement(FIELD_DATA);
for (int j = 0; j < fieldData.numElements(); ++j) {
Element field = fieldData.getElement(j);
if (field.isNull()) {
System.out.println(field.name() + " is NULL.");
} else {
System.out.println(field);
}
}
Element fieldExceptionArray =
securityData.getElement(FIELD_EXCEPTIONS);
for (int k = 0; k < fieldExceptionArray.numValues(); ++k) {
Element fieldException =
fieldExceptionArray.getValueAsElement(k);
System.out.println(
fieldException.getElement(ERROR_INFO).getElementAsString("category")
+ ": " + fieldException.getElementAsString(FIELD_ID));
}
System.out.println("\n");
}
}
}
run:
Connecting to localhost:35230
Failed to start session.
Press ENTER to quit
http://localhost:35230
但仍然出现此错误还需要什么配置?
最佳答案
本地的默认端口 bbcomm
进程一般是8194。你需要bbcomm.exe
程序运行并通过彭博终端连接到彭博。
关于java - 彭博无法开始 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17304714/
我是一名优秀的程序员,十分优秀!