gpt4 book ai didi

java - 彭博无法开始 session

转载 作者:行者123 更新时间:2023-12-04 04:52:00 30 4
gpt4 key购买 nike

我正在使用 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

本地主机通过 xampp 在我的系统上运行,我尝试使用默认端口:8080,没有端口也没有工作,然后我启动了玻璃鱼服务器,它也在工作 http://localhost:35230但仍然出现此错误还需要什么配置?

最佳答案

本地的默认端口 bbcomm进程一般是8194。你需要bbcomm.exe程序运行并通过彭博终端连接到彭博。

关于java - 彭博无法开始 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17304714/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com