Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #224 from mcourteaux/fix-outboundAccountPosition
Browse files Browse the repository at this point in the history
Fixes #223 Parsing of UserDataUpdateEvents with regard to the new outboundAccountPosition events.
  • Loading branch information
joaopsilva authored Aug 17, 2019
2 parents e038355 + 25a23ce commit 9aabc01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* User data update event which can be of two types:
*
* 1) outboundAccountInfo, whenever there is a change in the account (e.g. balance of an asset)
* 2) executionReport, whenever there is a trade or an order
* 2) outboundAccountPosition, the change in account balances caused by an event.
* 3) executionReport, whenever there is a trade or an order
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(using = UserDataUpdateEventDeserializer.class)
Expand Down Expand Up @@ -62,6 +63,8 @@ public String toString() {
.append("eventTime", eventTime);
if (eventType == UserDataUpdateEventType.ACCOUNT_UPDATE) {
sb.append("accountUpdateEvent", accountUpdateEvent);
} else if (eventType == UserDataUpdateEventType.ACCOUNT_POSITION_UPDATE) {
sb.append("accountPositionUpdateEvent", accountUpdateEvent);
} else {
sb.append("orderTradeUpdateEvent", orderTradeUpdateEvent);
}
Expand All @@ -70,6 +73,7 @@ public String toString() {

public enum UserDataUpdateEventType {
ACCOUNT_UPDATE("outboundAccountInfo"),
ACCOUNT_POSITION_UPDATE("outboundAccountPosition"),
ORDER_TRADE_UPDATE("executionReport");

private final String eventTypeId;
Expand All @@ -87,6 +91,8 @@ public static UserDataUpdateEventType fromEventTypeId(String eventTypeId) {
return ACCOUNT_UPDATE;
} else if (ORDER_TRADE_UPDATE.eventTypeId.equals(eventTypeId)) {
return ORDER_TRADE_UPDATE;
} else if (ACCOUNT_POSITION_UPDATE.eventTypeId.equals(eventTypeId)) {
return ACCOUNT_POSITION_UPDATE;
}
throw new IllegalArgumentException("Unrecognized user data update event type id: " + eventTypeId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public UserDataUpdateEvent deserialize(JsonParser jp, DeserializationContext ctx
userDataUpdateEvent.setEventType(userDataUpdateEventType);
userDataUpdateEvent.setEventTime(eventTime);

if (userDataUpdateEventType == UserDataUpdateEventType.ACCOUNT_UPDATE) {
if (userDataUpdateEventType == UserDataUpdateEventType.ACCOUNT_UPDATE ||
userDataUpdateEventType == UserDataUpdateEventType.ACCOUNT_POSITION_UPDATE) {
AccountUpdateEvent accountUpdateEvent = getUserDataUpdateEventDetail(json, AccountUpdateEvent.class, mapper);
userDataUpdateEvent.setAccountUpdateEvent(accountUpdateEvent);
} else { // userDataUpdateEventType == UserDataUpdateEventType.ORDER_TRADE_UPDATE
Expand All @@ -56,4 +57,4 @@ public <T> T getUserDataUpdateEventDetail(String json, Class<T> clazz, ObjectMap
throw new BinanceApiException(e);
}
}
}
}

0 comments on commit 9aabc01

Please sign in to comment.