diff --git a/src/main/java/com/binance/api/client/domain/event/ListStatusEvent.java b/src/main/java/com/binance/api/client/domain/event/ListStatusEvent.java new file mode 100644 index 000000000..a6325fdb7 --- /dev/null +++ b/src/main/java/com/binance/api/client/domain/event/ListStatusEvent.java @@ -0,0 +1,151 @@ +package com.binance.api.client.domain.event; + +import com.binance.api.client.domain.account.Order; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ListStatusEvent { + + @JsonProperty("e") + private String eventType; + + @JsonProperty("E") + private long eventTime; + + @JsonProperty("s") + private String symbol; + + @JsonProperty("g") + private long orderListId; + + @JsonProperty("c") + private String contingencyType; + + @JsonProperty("l") + private String listStatusType; + + @JsonProperty("L") + private String listOrderStatus; + + @JsonProperty("r") + private String listRejectReason; + + @JsonProperty("C") + private String listClientOrderId; + + @JsonProperty("T") + private long transactionTime; + + @JsonProperty("O") + @JsonDeserialize(contentUsing = OrderDeserializer.class) + private List orders; + + public String getEventType() { + return eventType; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public long getEventTime() { + return eventTime; + } + + public void setEventTime(long eventTime) { + this.eventTime = eventTime; + } + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public long getOrderListId() { + return orderListId; + } + + public void setOrderListId(long orderListId) { + this.orderListId = orderListId; + } + + public String getContingencyType() { + return contingencyType; + } + + public void setContingencyType(String contingencyType) { + this.contingencyType = contingencyType; + } + + public String getListStatusType() { + return listStatusType; + } + + public void setListStatusType(String listStatusType) { + this.listStatusType = listStatusType; + } + + public String getListOrderStatus() { + return listOrderStatus; + } + + public void setListOrderStatus(String listOrderStatus) { + this.listOrderStatus = listOrderStatus; + } + + public String getListRejectReason() { + return listRejectReason; + } + + public void setListRejectReason(String listRejectReason) { + this.listRejectReason = listRejectReason; + } + + public String getListClientOrderId() { + return listClientOrderId; + } + + public void setListClientOrderId(String listClientOrderId) { + this.listClientOrderId = listClientOrderId; + } + + public long getTransactionTime() { + return transactionTime; + } + + public void setTransactionTime(long transactionTime) { + this.transactionTime = transactionTime; + } + + public List getOrders() { + return orders; + } + + public void setOrders(List orders) { + this.orders = orders; + } + + @Override + public String toString() { + return "ListStatusEvent{" + + "eventType='" + eventType + '\'' + + ", eventTime=" + eventTime + + ", symbol='" + symbol + '\'' + + ", orderListId=" + orderListId + + ", contingencyType='" + contingencyType + '\'' + + ", listStatusType='" + listStatusType + '\'' + + ", listOrderStatus='" + listOrderStatus + '\'' + + ", listRejectReason='" + listRejectReason + '\'' + + ", listClientOrderId='" + listClientOrderId + '\'' + + ", transactionTime=" + transactionTime + + ", orders=" + orders + + '}'; + } +} diff --git a/src/main/java/com/binance/api/client/domain/event/OrderDeserializer.java b/src/main/java/com/binance/api/client/domain/event/OrderDeserializer.java new file mode 100644 index 000000000..85dbefcdf --- /dev/null +++ b/src/main/java/com/binance/api/client/domain/event/OrderDeserializer.java @@ -0,0 +1,28 @@ +package com.binance.api.client.domain.event; + +import com.binance.api.client.domain.account.Order; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; + +import java.io.IOException; + +public class OrderDeserializer extends JsonDeserializer { + + @Override + public Order deserialize(JsonParser jp, DeserializationContext ctx) throws IOException { + ObjectCodec oc = jp.getCodec(); + JsonNode node = oc.readTree(jp); + final String symbol = node.get("s").asText(); + final long orderId = node.get("i").asLong(); + final String clientOrderId = node.get("c").asText(); + + Order order = new Order(); + order.setSymbol(symbol); + order.setOrderId(orderId); + order.setClientOrderId(clientOrderId); + return order; + } +} \ No newline at end of file diff --git a/src/main/java/com/binance/api/client/domain/event/OutboundAccountPositionEvent.java b/src/main/java/com/binance/api/client/domain/event/OutboundAccountPositionEvent.java new file mode 100644 index 000000000..5cff4bf48 --- /dev/null +++ b/src/main/java/com/binance/api/client/domain/event/OutboundAccountPositionEvent.java @@ -0,0 +1,69 @@ +package com.binance.api.client.domain.event; + +import com.binance.api.client.domain.account.AssetBalance; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class OutboundAccountPositionEvent { + + @JsonProperty("e") + private String eventType; + + @JsonProperty("E") + private long eventTime; + + @JsonProperty("u") + private long lastAccountUpdate; + + @JsonProperty("B") + @JsonDeserialize(contentUsing = AssetBalanceDeserializer.class) + private List balances; + + public String getEventType() { + return eventType; + } + + public void setEventType(String eventType) { + this.eventType = eventType; + } + + public long getEventTime() { + return eventTime; + } + + public void setEventTime(long eventTime) { + this.eventTime = eventTime; + } + + public long getLastAccountUpdate() { + return lastAccountUpdate; + } + + public void setLastAccountUpdate(long lastAccountUpdate) { + this.lastAccountUpdate = lastAccountUpdate; + } + + public List getBalances() { + return balances; + } + + public void setBalances(List balances) { + this.balances = balances; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) + .append("eventType", eventType) + .append("eventTime", eventTime) + .append("lastAccountUpdate", lastAccountUpdate) + .append("balances", balances) + .toString(); + } +} diff --git a/src/main/java/com/binance/api/client/domain/event/UserDataUpdateEvent.java b/src/main/java/com/binance/api/client/domain/event/UserDataUpdateEvent.java index 647db9c57..4b7ee32f0 100644 --- a/src/main/java/com/binance/api/client/domain/event/UserDataUpdateEvent.java +++ b/src/main/java/com/binance/api/client/domain/event/UserDataUpdateEvent.java @@ -23,6 +23,10 @@ public class UserDataUpdateEvent { private OrderTradeUpdateEvent orderTradeUpdateEvent; + private OutboundAccountPositionEvent outboundAccountPositionEvent; + + private ListStatusEvent listStatusEvent; + public UserDataUpdateEventType getEventType() { return eventType; } @@ -55,22 +59,44 @@ public void setOrderTradeUpdateEvent(OrderTradeUpdateEvent orderTradeUpdateEvent this.orderTradeUpdateEvent = orderTradeUpdateEvent; } + public OutboundAccountPositionEvent getOutboundAccountPositionEvent() { + return outboundAccountPositionEvent; + } + + public void setOutboundAccountPositionEvent(OutboundAccountPositionEvent outboundAccountPositionEvent) { + this.outboundAccountPositionEvent = outboundAccountPositionEvent; + } + + public ListStatusEvent getListStatusEvent() { + return listStatusEvent; + } + + public void setListStatusEvent(ListStatusEvent listStatusEvent) { + this.listStatusEvent = listStatusEvent; + } + @Override public String toString() { ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) - .append("eventType", eventType) - .append("eventTime", eventTime); + .append("eventType", eventType) + .append("eventTime", eventTime); if (eventType == UserDataUpdateEventType.ACCOUNT_UPDATE) { sb.append("accountUpdateEvent", accountUpdateEvent); - } else { + } else if (eventType == UserDataUpdateEventType.ORDER_TRADE_UPDATE) { sb.append("orderTradeUpdateEvent", orderTradeUpdateEvent); + } else if (eventType == UserDataUpdateEventType.OUTBOUND_ACCOUNT_POSITION) { + sb.append("outboundAccountPositionEvent", outboundAccountPositionEvent); + } else if (eventType == UserDataUpdateEventType.LIST_STATUS) { + sb.append("listStatusEvent", listStatusEvent); } return sb.toString(); } public enum UserDataUpdateEventType { ACCOUNT_UPDATE("outboundAccountInfo"), - ORDER_TRADE_UPDATE("executionReport"); + ORDER_TRADE_UPDATE("executionReport"), + OUTBOUND_ACCOUNT_POSITION("outboundAccountPosition"), + LIST_STATUS("listStatus"); private final String eventTypeId; @@ -87,7 +113,12 @@ public static UserDataUpdateEventType fromEventTypeId(String eventTypeId) { return ACCOUNT_UPDATE; } else if (ORDER_TRADE_UPDATE.eventTypeId.equals(eventTypeId)) { return ORDER_TRADE_UPDATE; + } else if (OUTBOUND_ACCOUNT_POSITION.eventTypeId.equals(eventTypeId)) { + return OUTBOUND_ACCOUNT_POSITION; + } else if (LIST_STATUS.eventTypeId.equals(eventTypeId)) { + return LIST_STATUS; } + throw new IllegalArgumentException("Unrecognized user data update event type id: " + eventTypeId); } } diff --git a/src/main/java/com/binance/api/client/domain/event/UserDataUpdateEventDeserializer.java b/src/main/java/com/binance/api/client/domain/event/UserDataUpdateEventDeserializer.java index 3198839c3..3cf748d85 100644 --- a/src/main/java/com/binance/api/client/domain/event/UserDataUpdateEventDeserializer.java +++ b/src/main/java/com/binance/api/client/domain/event/UserDataUpdateEventDeserializer.java @@ -24,25 +24,36 @@ public UserDataUpdateEvent deserialize(JsonParser jp, DeserializationContext ctx String json = node.toString(); final String eventTypeId = node.get("e").asText(); - final Long eventTime = node.get("E").asLong(); + final long eventTime = node.get("E").asLong(); UserDataUpdateEventType userDataUpdateEventType = UserDataUpdateEventType.fromEventTypeId(eventTypeId); UserDataUpdateEvent userDataUpdateEvent = new UserDataUpdateEvent(); userDataUpdateEvent.setEventType(userDataUpdateEventType); userDataUpdateEvent.setEventTime(eventTime); - if (userDataUpdateEventType == UserDataUpdateEventType.ACCOUNT_UPDATE) { - AccountUpdateEvent accountUpdateEvent = getUserDataUpdateEventDetail(json, AccountUpdateEvent.class); - userDataUpdateEvent.setAccountUpdateEvent(accountUpdateEvent); - } else { // userDataUpdateEventType == UserDataUpdateEventType.ORDER_TRADE_UPDATE - OrderTradeUpdateEvent orderTradeUpdateEvent = getUserDataUpdateEventDetail(json, OrderTradeUpdateEvent.class); - userDataUpdateEvent.setOrderTradeUpdateEvent(orderTradeUpdateEvent); + switch (userDataUpdateEventType) { + case ACCOUNT_UPDATE: + AccountUpdateEvent accountUpdateEvent = getUserDataUpdateEventDetail(json, AccountUpdateEvent.class); + userDataUpdateEvent.setAccountUpdateEvent(accountUpdateEvent); + break; + case ORDER_TRADE_UPDATE: + OrderTradeUpdateEvent orderTradeUpdateEvent = getUserDataUpdateEventDetail(json, OrderTradeUpdateEvent.class); + userDataUpdateEvent.setOrderTradeUpdateEvent(orderTradeUpdateEvent); + break; + case OUTBOUND_ACCOUNT_POSITION: + OutboundAccountPositionEvent outboundAccountPositionEvent = getUserDataUpdateEventDetail(json, OutboundAccountPositionEvent.class); + userDataUpdateEvent.setOutboundAccountPositionEvent(outboundAccountPositionEvent); + break; + case LIST_STATUS: + ListStatusEvent listStatusEvent = getUserDataUpdateEventDetail(json, ListStatusEvent.class); + userDataUpdateEvent.setListStatusEvent(listStatusEvent); + break; } return userDataUpdateEvent; } - public T getUserDataUpdateEventDetail(String json, Class clazz) { + private T getUserDataUpdateEventDetail(String json, Class clazz) { ObjectMapper mapper = new ObjectMapper(); try { return mapper.readValue(json, clazz);