Skip to content

Commit

Permalink
Merge pull request webcerebrium#41 from datalorax/expose_first_update
Browse files Browse the repository at this point in the history
Expose the 'U' (first update), as well as the 'u' (final update) on Depth Event.
  • Loading branch information
joaopsilva authored Jan 23, 2018
2 parents 4d76c23 + 299411f commit 382a679
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
36 changes: 32 additions & 4 deletions src/main/java/com/binance/api/client/domain/event/DepthEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ public class DepthEvent {
@JsonProperty("s")
private String symbol;

@JsonProperty("U")
private long firstUpdateId;

/**
* updateId to sync up with updateid in /api/v1/depth
*/
@JsonProperty("u")
private long updateId;
private long finalUpdateId;

/**
* Bid depth delta.
Expand Down Expand Up @@ -65,12 +68,36 @@ public void setSymbol(String symbol) {
this.symbol = symbol;
}

public long getFirstUpdateId() {
return firstUpdateId;
}

public void setFirstUpdateId(final long firstUpdateId) {
this.firstUpdateId = firstUpdateId;
}

public long getFinalUpdateId() {
return finalUpdateId;
}

public void setFinalUpdateId(long finalUpdateId) {
this.finalUpdateId = finalUpdateId;
}

/**
* @deprecated Use {@link #getFinalUpdateId}
*/
@Deprecated
public long getUpdateId() {
return updateId;
return finalUpdateId;
}

/**
* @deprecated Use {@link #setFinalUpdateId}
*/
@Deprecated
public void setUpdateId(long updateId) {
this.updateId = updateId;
this.finalUpdateId = updateId;
}

public List<OrderBookEntry> getBids() {
Expand All @@ -95,7 +122,8 @@ public String toString() {
.append("eventType", eventType)
.append("eventTime", eventTime)
.append("symbol", symbol)
.append("updateId", updateId)
.append("firstUpdateId", firstUpdateId)
.append("finalUpdateId", finalUpdateId)
.append("bids", bids)
.append("asks", asks)
.toString();
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/binance/api/examples/DepthCacheExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ private void startDepthEventStreaming(String symbol) {
BinanceApiWebSocketClient client = factory.newWebSocketClient();

client.onDepthEvent(symbol.toLowerCase(), response -> {
if (response.getUpdateId() > lastUpdateId) {
if (response.getFinalUpdateId() > lastUpdateId) {
System.out.println(response);
lastUpdateId = response.getUpdateId();
lastUpdateId = response.getFinalUpdateId();
updateOrderBook(getAsks(), response.getAsks());
updateOrderBook(getBids(), response.getBids());
printDepthCache();
Expand Down Expand Up @@ -125,9 +125,9 @@ public Map<String, NavigableMap<BigDecimal, BigDecimal>> getDepthCache() {
*/
private void printDepthCache() {
System.out.println(depthCache);
System.out.println("ASKS:");
System.out.println("ASKS:(" + getAsks().size() + ")");
getAsks().entrySet().forEach(entry -> System.out.println(toDepthCacheEntryString(entry)));
System.out.println("BIDS:");
System.out.println("BIDS:(" + getBids().size() + ")");
getBids().entrySet().forEach(entry -> System.out.println(toDepthCacheEntryString(entry)));
System.out.println("BEST ASK: " + toDepthCacheEntryString(getBestAsk()));
System.out.println("BEST BID: " + toDepthCacheEntryString(getBestBid()));
Expand Down

0 comments on commit 382a679

Please sign in to comment.