Skip to content

Commit b2e3633

Browse files
authored
Merge pull request binance-exchange#41 from datalorax/expose_first_update
Expose the 'U' (first update), as well as the 'u' (final update) on Depth Event.
2 parents b718ffa + e546c0d commit b2e3633

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/main/java/com/binance/api/client/domain/event/DepthEvent.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ public class DepthEvent {
2323
@JsonProperty("s")
2424
private String symbol;
2525

26+
@JsonProperty("U")
27+
private long firstUpdateId;
28+
2629
/**
2730
* updateId to sync up with updateid in /api/v1/depth
2831
*/
2932
@JsonProperty("u")
30-
private long updateId;
33+
private long finalUpdateId;
3134

3235
/**
3336
* Bid depth delta.
@@ -65,12 +68,36 @@ public void setSymbol(String symbol) {
6568
this.symbol = symbol;
6669
}
6770

71+
public long getFirstUpdateId() {
72+
return firstUpdateId;
73+
}
74+
75+
public void setFirstUpdateId(final long firstUpdateId) {
76+
this.firstUpdateId = firstUpdateId;
77+
}
78+
79+
public long getFinalUpdateId() {
80+
return finalUpdateId;
81+
}
82+
83+
public void setFinalUpdateId(long finalUpdateId) {
84+
this.finalUpdateId = finalUpdateId;
85+
}
86+
87+
/**
88+
* @deprecated Use {@link #getFinalUpdateId}
89+
*/
90+
@Deprecated
6891
public long getUpdateId() {
69-
return updateId;
92+
return finalUpdateId;
7093
}
7194

95+
/**
96+
* @deprecated Use {@link #setFinalUpdateId}
97+
*/
98+
@Deprecated
7299
public void setUpdateId(long updateId) {
73-
this.updateId = updateId;
100+
this.finalUpdateId = updateId;
74101
}
75102

76103
public List<OrderBookEntry> getBids() {
@@ -95,7 +122,8 @@ public String toString() {
95122
.append("eventType", eventType)
96123
.append("eventTime", eventTime)
97124
.append("symbol", symbol)
98-
.append("updateId", updateId)
125+
.append("firstUpdateId", firstUpdateId)
126+
.append("finalUpdateId", finalUpdateId)
99127
.append("bids", bids)
100128
.append("asks", asks)
101129
.toString();

src/test/java/com/binance/api/examples/DepthCacheExample.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ private void startDepthEventStreaming(String symbol) {
6363
BinanceApiWebSocketClient client = factory.newWebSocketClient();
6464

6565
client.onDepthEvent(symbol.toLowerCase(), response -> {
66-
if (response.getUpdateId() > lastUpdateId) {
66+
if (response.getFinalUpdateId() > lastUpdateId) {
6767
System.out.println(response);
68-
lastUpdateId = response.getUpdateId();
68+
lastUpdateId = response.getFinalUpdateId();
6969
updateOrderBook(getAsks(), response.getAsks());
7070
updateOrderBook(getBids(), response.getBids());
7171
printDepthCache();
@@ -125,9 +125,9 @@ public Map<String, NavigableMap<BigDecimal, BigDecimal>> getDepthCache() {
125125
*/
126126
private void printDepthCache() {
127127
System.out.println(depthCache);
128-
System.out.println("ASKS:");
128+
System.out.println("ASKS:(" + getAsks().size() + ")");
129129
getAsks().entrySet().forEach(entry -> System.out.println(toDepthCacheEntryString(entry)));
130-
System.out.println("BIDS:");
130+
System.out.println("BIDS:(" + getBids().size() + ")");
131131
getBids().entrySet().forEach(entry -> System.out.println(toDepthCacheEntryString(entry)));
132132
System.out.println("BEST ASK: " + toDepthCacheEntryString(getBestAsk()));
133133
System.out.println("BEST BID: " + toDepthCacheEntryString(getBestBid()));

0 commit comments

Comments
 (0)