Skip to content

Commit

Permalink
bitrich-info#446 revew fixes - events handling + more effective order…
Browse files Browse the repository at this point in the history
… timestamp calculation
  • Loading branch information
Pavel Chertalev committed Dec 4, 2019
1 parent 4f34ed6 commit 5684ae2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class BitstampWebSocketTransaction extends BitstampTransaction {
public BitstampWebSocketTransaction(@JsonProperty("microtimestamp") BigDecimal microtimestamp, @JsonProperty("id") long tid, @JsonProperty("price") BigDecimal price,
@JsonProperty("amount") BigDecimal amount, @JsonProperty("order_type") int type) {

super(microtimestamp.divide(new BigDecimal(1000), BigDecimal.ROUND_DOWN).longValue(),
tid, price, amount, type);
super(microtimestamp.longValue() / 1000, tid, price, amount, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ public class BitstampStreamingService extends JsonNettyStreamingService {

private static final String JSON_CHANNEL = "channel";
private static final String JSON_EVENT = "event";

public static final String EVENT_ORDERBOOK = "data";
public static final String EVENT_TRADE = "trade";
private static final String EVENT_SUBSCRIPTION_SUCCEEDED = "bts:subscription_succeeded";
private static final String EVENT_UNSUBSCRIPTION_SUCCEEDED = "bts:unsubscription_succeeded";

public BitstampStreamingService(String apiUrl) {
super(apiUrl, Integer.MAX_VALUE);
Expand Down Expand Up @@ -53,14 +56,23 @@ protected void handleMessage(JsonNode message) {
String channel = channelJsonNode.asText();
String event = eventJsonNode.asText();

if (!channels.containsKey(channel)) {
LOG.warn("The message has been received from disconnected channel '{}'. Skipped.", channel);
return;
}
switch (event) {
case EVENT_ORDERBOOK:
case EVENT_TRADE:
if (!channels.containsKey(channel)) {
LOG.warn("The message has been received from disconnected channel '{}'. Skipped.", channel);
return;
}
super.handleMessage(message);
break;
case EVENT_SUBSCRIPTION_SUCCEEDED:
LOG.info("Channel {} has been successfully subscribed", channel);
break;
case EVENT_UNSUBSCRIPTION_SUCCEEDED:
LOG.info("Channel {} has been successfully unsubscribed", channel);
break;
default:
LOG.error("Unsupported event type {} in message {}", event, message.toString());
}
}

Expand Down

0 comments on commit 5684ae2

Please sign in to comment.