Skip to content

Commit

Permalink
Merge pull request #4962 from rvullriede/fix/kraken-ohlc-channel-id-o…
Browse files Browse the repository at this point in the history
…verflow

fix: fix channelId overflow
  • Loading branch information
timmolter authored Dec 12, 2024
2 parents 52e6a3e + 0f787f3 commit 383a47d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class KrakenStreamingService extends JsonNettyStreamingService {
private static final String EVENT = "event";
private static final String WEBSOCKET_REQUESTS_PER_SECOND =
"Kraken_Websocket_Requests_Per_Second";
private final Map<Integer, String> channels = new ConcurrentHashMap<>();
private final Map<Long, String> channels = new ConcurrentHashMap<>();
private final ObjectMapper mapper = StreamingObjectMapperHelper.getObjectMapper();
private final boolean isPrivate;
private final Supplier<KrakenWebsocketToken> authData;
Expand Down Expand Up @@ -167,7 +167,7 @@ protected void handleMessage(JsonNode message) {
}
statusMessage.setChannelName(channelName);

Integer channelId = statusMessage.getChannelID();
Long channelId = statusMessage.getChannelID();
switch (statusMessage.getStatus()) {
case subscribed:
LOG.info("Channel name={}, id={} has been subscribed", channelName, channelId);
Expand Down Expand Up @@ -229,7 +229,7 @@ protected void handleMessage(JsonNode message) {
protected String getChannelNameFromMessage(JsonNode message) throws IOException {
String channelName = null;
if (message.has("channelID")) {
int channelId = message.get("channelID").asInt();
long channelId = message.get("channelID").asLong();
return channels.getOrDefault(channelId, String.valueOf(channelId));
}
if (message.has("channelName")) {
Expand All @@ -238,9 +238,9 @@ protected String getChannelNameFromMessage(JsonNode message) throws IOException
}

if (message.isArray()) {
if (message.get(0).isInt()) {
LOG.trace("Taking channelName from ID from first field INT).");
int channelId = message.get(0).asInt();
if (message.get(0).isLong()) {
LOG.trace("Taking channelName from ID from first field LONG).");
long channelId = message.get(0).asLong();
return channels.getOrDefault(channelId, String.valueOf(channelId));
}
if (message.get(1).isTextual()) {
Expand Down Expand Up @@ -390,4 +390,4 @@ static Integer parseOrderBookSize(Object[] args) {
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public class KrakenSubscriptionStatusMessage extends KrakenEvent {

private final Integer channelID;
private final Long channelID;
private final Integer reqid;
private final KrakenSubscriptionStatus status;
private final String pair;
Expand All @@ -21,7 +21,7 @@ public class KrakenSubscriptionStatusMessage extends KrakenEvent {
@JsonCreator
public KrakenSubscriptionStatusMessage(
@JsonProperty("event") KrakenEventType event,
@JsonProperty("channelID") Integer channelID,
@JsonProperty("channelID") Long channelID,
@JsonProperty("reqid") Integer reqid,
@JsonProperty("status") KrakenSubscriptionStatus status,
@JsonProperty("pair") String pair,
Expand All @@ -36,7 +36,7 @@ public KrakenSubscriptionStatusMessage(
this.errorMessage = errorMessage;
}

public Integer getChannelID() {
public Long getChannelID() {
return channelID;
}

Expand Down Expand Up @@ -67,4 +67,4 @@ public String getChannelName() {
public void setChannelName(String channelName) {
this.channelName = channelName;
}
}
}

0 comments on commit 383a47d

Please sign in to comment.