java - Interactive Broker Java API 从historyData 中不返回任何内容
问题描述
假设下面的代码将返回并打印历史市场数据列表,例如开盘价、收盘价、最高价、最低价、交易量。与 Interactive Broker API 的连接应该没问题。但是在 Java 控制台中,它没有从回调中打印市场数据。看起来它没有通过historyData函数。如何激活该功能并将市场数据存储在对象中?
id 1
-1 2104 Market data farm connection is OK:usfarm.nj
-1 2104 Market data farm connection is OK:cashfarm
-1 2104 Market data farm connection is OK:usfarm
-1 2106 HMDS data farm connection is OK:cashhmds
-1 2106 HMDS data farm connection is OK:hkhmds
-1 2106 HMDS data farm connection is OK:ushmds
-1 2158 Sec-def data farm connection is OK:secdefil
...
示例代码:
void run() {
m_client.eConnect("localhost", 7497, 123);
final EReader reader = new EReader(m_client, m_signal);
reader.start();
new Thread() {
@Override
public void run() {
while (m_client.isConnected()) {
m_signal.waitForSignal();
try {
reader.processMsgs();
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
}
}
}.start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void nextValidId(int orderId) {
System.out.println("id "+orderId);
nextOrderID = orderId;
//Contract c = new StkContract("AAPL");
Contract c = new Contract();
c.symbol("EUR");
c.exchange("IDEALPRO");
c.secType("CASH");
c.currency("USD");
m_client.reqHistoricalData(1, c,
LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)+ " 16:00:00",
"1 D", "1 min", "MIDPOINT", 1, 1, false, null);
m_client.reqMktData(1, c, "", false, false, null);
}
@Override
public void error(int id, int errorCode, String errorMsg) {
System.out.println(id + " " + errorCode + " " + errorMsg);
}
@Override
public void historicalData(int reqId, String date, double open, double high, double low, double close, int volume, int count, double WAP, boolean hasGaps) {
//if being run on the next calendar day, this works
if (LocalDate.now().minusDays(1).format(DateTimeFormatter.BASIC_ISO_DATE).equals(date)){
this.date = date;
this.high = high;
this.low = low;
this.open = open;
this.close = close;
System.out.println(date + " h: " + high + " l: " +low);
}
System.out.println("Requesting Data...");
System.out.println(EWrapperMsgGenerator.historicalData(reqId, date, open, high, low, close, volume, count, WAP));
System.out.println("Data Input Ended...");
}
解决方案
推荐阅读
- python - RuntimeError: populate() 不是可重入的导入循环
- javascript - 阻止对象共享值
- ssrs-2012 - SSRS:报告存在但在页面上不可见
- javascript - 表示返回空参数的嵌套路由
- javascript - FlatList/ScrollView 不在 Touchables 之间滚动
- laravel - 使用 hasMany (第一行)加入,然后是 hasOne
- github - GitHub Pages 图片未显示(区分大小写和路径)
- vb.net - 如何从 PowerShell 脚本(PSObjects?)实时输出到 WinForms 文本框?
- php - 所有自定义请求的常见验证错误 ibn laravel
- azure - 带有 az login 的 az devops login 仍然请求个人访问令牌