Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Parse "no data" message on candle subscription
Browse files Browse the repository at this point in the history
Use NoDataError exception on such errors.
  • Loading branch information
Sergey Lukashevich committed May 30, 2019
1 parent 1a21ed4 commit 5dd5f5a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/main/java/com/finplant/ib/IbExceptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ public DuplicatedRequestError(RequestKey key) {
}
}

public static class NoTicksError extends IbClientError {
public NoTicksError(int requestId) {
super(requestId, "Has no ticks");
public static class NoDataError extends IbClientError {
public NoDataError(int requestId) {
super(requestId, "Has no data");
}

public NoDataError(int requestId, String message) {
super(requestId, message);
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/finplant/ib/impl/TerminalErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,24 @@ public void handle(int id, int code, String message) {
private void onHistoricalDataError(int code, int id, String message) {

final String HISTORICAL_DATA_MSG = "Historical Market Data Service error message";

final String HISTORICAL_DATA_CANCEL_MSG = "API historical data query cancelled";
final String HISTORICAL_DATA_NO_PERMISSIONS_MSG = "No market data permissions for";
final String HISTORICAL_DATA_NO_DATA_MSG = "HMDS query returned no data";

if (!message.startsWith(HISTORICAL_DATA_MSG)) {
log.error("Unexpected message for REQ_HISTORICAL_DATA: {}", message);
requests.onError(null, id,
new IbExceptions.TerminalError(id, message, code));
requests.onError(null, id, new IbExceptions.TerminalError(id, message, code));
return;
}

String messageInfo = message.substring(HISTORICAL_DATA_MSG.length() + 1);
//noinspection StatementWithEmptyBody Subscription canceling is not an error
if (messageInfo.startsWith(HISTORICAL_DATA_CANCEL_MSG)) {
// Subscription canceling is not an error
} else if (messageInfo.startsWith(HISTORICAL_DATA_NO_PERMISSIONS_MSG)) {
requests.onError(null, id,
new IbExceptions.NoPermissions(id, messageInfo), true);
requests.onError(null, id, new IbExceptions.NoPermissions(id, messageInfo), true);
} else if (messageInfo.startsWith(HISTORICAL_DATA_NO_DATA_MSG)) {
requests.onError(null, id, new IbExceptions.NoDataError(id, messageInfo), true);
} else {
requests.onError(null, id, new IbExceptions.IbClientError(id, message), true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/finplant/ib/impl/Wrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public void tickSnapshotEnd(final int tickerId) {
IbTick tick = cache.getTick(tickerId);
if (tick == null) {
log.info("No ticks for ticker {}", tickerId);
requests.onError(tickerId, new IbExceptions.NoTicksError(tickerId));
requests.onError(tickerId, new IbExceptions.NoDataError(tickerId));
return;
}

Expand Down

0 comments on commit 5dd5f5a

Please sign in to comment.