Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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