Skip to content

Commit 8aa6fb5

Browse files
committed
Fix examples now too. Deprecated the usage of the old naming. The enum itself is left in place for backwards compatibility.
1 parent 49eef34 commit 8aa6fb5

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class UserDataUpdateEvent {
2424

2525
private long eventTime;
2626

27-
private AccountUpdateEvent accountUpdateEvent;
27+
private AccountUpdateEvent outboundAccountPositionUpdateEvent;
2828

2929
private BalanceUpdateEvent balanceUpdateEvent;
3030

@@ -46,12 +46,20 @@ public void setEventTime(long eventTime) {
4646
this.eventTime = eventTime;
4747
}
4848

49+
/**
50+
* @Deprecated: left in for backwards compatibility. Use getOutboundAccountPositionUpdateEvent() instead, as that is what the Binance API documentation calls it.
51+
*/
52+
@Deprecated
4953
public AccountUpdateEvent getAccountUpdateEvent() {
50-
return accountUpdateEvent;
54+
return outboundAccountPositionUpdateEvent;
5155
}
5256

53-
public void setAccountUpdateEvent(AccountUpdateEvent accountUpdateEvent) {
54-
this.accountUpdateEvent = accountUpdateEvent;
57+
public AccountUpdateEvent getOutboundAccountPositionUpdateEvent() {
58+
return outboundAccountPositionUpdateEvent;
59+
}
60+
61+
public void setOutboundAccountPositionUpdateEvent(AccountUpdateEvent accountUpdateEvent) {
62+
this.outboundAccountPositionUpdateEvent = accountUpdateEvent;
5563
}
5664

5765
public BalanceUpdateEvent getBalanceUpdateEvent() {
@@ -76,7 +84,7 @@ public String toString() {
7684
.append("eventType", eventType)
7785
.append("eventTime", eventTime);
7886
if (eventType == UserDataUpdateEventType.ACCOUNT_POSITION_UPDATE) {
79-
sb.append("accountPositionUpdateEvent", accountUpdateEvent);
87+
sb.append("outboundAccountPositionUpdateEvent", outboundAccountPositionUpdateEvent);
8088
} else if (eventType == UserDataUpdateEventType.BALANCE_UPDATE) {
8189
sb.append("balanceUpdateEvent", balanceUpdateEvent);
8290
} else {
@@ -86,8 +94,11 @@ public String toString() {
8694
}
8795

8896
public enum UserDataUpdateEventType {
97+
/** Corresponds to "outboundAccountPosition" events. */
8998
ACCOUNT_POSITION_UPDATE("outboundAccountPosition"),
99+
/** Corresponds to "balanceUpdate" events. */
90100
BALANCE_UPDATE("balanceUpdate"),
101+
/** Corresponds to "executionReport" events. */
91102
ORDER_TRADE_UPDATE("executionReport"),
92103
;
93104

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public UserDataUpdateEvent deserialize(JsonParser jp, DeserializationContext ctx
4141

4242
if (userDataUpdateEventType == UserDataUpdateEventType.ACCOUNT_POSITION_UPDATE) {
4343
AccountUpdateEvent accountUpdateEvent = getUserDataUpdateEventDetail(json, AccountUpdateEvent.class, mapper);
44-
userDataUpdateEvent.setAccountUpdateEvent(accountUpdateEvent);
44+
userDataUpdateEvent.setOutboundAccountPositionUpdateEvent(accountUpdateEvent);
4545
} else if (userDataUpdateEventType == UserDataUpdateEventType.BALANCE_UPDATE) {
4646
BalanceUpdateEvent balanceUpdateEvent = getUserDataUpdateEventDetail(json, BalanceUpdateEvent.class, mapper);
4747
userDataUpdateEvent.setBalanceUpdateEvent(balanceUpdateEvent);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.Map;
1010
import java.util.TreeMap;
1111

12-
import static com.binance.api.client.domain.event.UserDataUpdateEvent.UserDataUpdateEventType.ACCOUNT_UPDATE;
12+
import static com.binance.api.client.domain.event.UserDataUpdateEvent.UserDataUpdateEventType.ACCOUNT_POSITION_UPDATE;
1313

1414
/**
1515
* Illustrates how to use the user data event stream to create a local cache for the balance of an account.
@@ -58,9 +58,9 @@ private void startAccountBalanceEventStreaming(String listenKey) {
5858
BinanceApiWebSocketClient client = clientFactory.newWebSocketClient();
5959

6060
client.onUserDataUpdateEvent(listenKey, response -> {
61-
if (response.getEventType() == ACCOUNT_UPDATE) {
61+
if (response.getEventType() == ACCOUNT_POSITION_UPDATE) {
6262
// Override cached asset balances
63-
for (AssetBalance assetBalance : response.getAccountUpdateEvent().getBalances()) {
63+
for (AssetBalance assetBalance : response.getOutboundAccountPositionUpdateEvent().getBalances()) {
6464
accountBalanceCache.put(assetBalance.getAsset(), assetBalance);
6565
}
6666
System.out.println(accountBalanceCache);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public static void main(String[] args) {
2828

2929
// Listen for changes in the account
3030
webSocketClient.onUserDataUpdateEvent(listenKey, response -> {
31-
if (response.getEventType() == UserDataUpdateEventType.ACCOUNT_UPDATE) {
32-
AccountUpdateEvent accountUpdateEvent = response.getAccountUpdateEvent();
31+
if (response.getEventType() == UserDataUpdateEventType.ACCOUNT_POSITION_UPDATE) {
32+
AccountUpdateEvent accountUpdateEvent = response.getOutboundAccountPositionUpdateEvent();
3333
// Print new balances of every available asset
3434
System.out.println(accountUpdateEvent.getBalances());
3535
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public static void main(String[] args) {
2727

2828
// Listen for changes in the account
2929
webSocketClient.onUserDataUpdateEvent(listenKey, response -> {
30-
if (response.getEventType() == UserDataUpdateEventType.ACCOUNT_UPDATE) {
31-
AccountUpdateEvent accountUpdateEvent = response.getAccountUpdateEvent();
30+
if (response.getEventType() == UserDataUpdateEventType.ACCOUNT_POSITION_UPDATE) {
31+
AccountUpdateEvent accountUpdateEvent = response.getOutboundAccountPositionUpdateEvent();
3232
// Print new balances of every available asset
3333
System.out.println(accountUpdateEvent.getBalances());
3434
} else {

0 commit comments

Comments
 (0)