From 25d6902949079f4f76221bc2fbea1775d4c25f92 Mon Sep 17 00:00:00 2001 From: npomfret Date: Wed, 27 Dec 2017 14:12:15 +0000 Subject: [PATCH] [cexio] fixed bug that produce zero quantity for (i think) market orders because the parser was using the wrong field --- .../knowm/xchange/cexio/CexIOAdapters.java | 27 +++++++------- .../cexio/dto/trade/CexIOArchivedOrder.java | 35 +++++++++++++++++-- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/xchange-cexio/src/main/java/org/knowm/xchange/cexio/CexIOAdapters.java b/xchange-cexio/src/main/java/org/knowm/xchange/cexio/CexIOAdapters.java index 22899423cbd..205f1e740be 100644 --- a/xchange-cexio/src/main/java/org/knowm/xchange/cexio/CexIOAdapters.java +++ b/xchange-cexio/src/main/java/org/knowm/xchange/cexio/CexIOAdapters.java @@ -1,13 +1,6 @@ package org.knowm.xchange.cexio; -import static org.knowm.xchange.utils.DateUtils.fromISODateString; - -import java.math.BigDecimal; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - +import com.fasterxml.jackson.databind.exc.InvalidFormatException; import org.knowm.xchange.cexio.dto.account.CexIOBalance; import org.knowm.xchange.cexio.dto.account.CexIOBalanceInfo; import org.knowm.xchange.cexio.dto.marketdata.CexIODepth; @@ -32,7 +25,13 @@ import org.knowm.xchange.dto.trade.UserTrade; import org.knowm.xchange.utils.DateUtils; -import com.fasterxml.jackson.databind.exc.InvalidFormatException; +import java.math.BigDecimal; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import static org.knowm.xchange.utils.DateUtils.fromISODateString; /** * Author: brox Since: 2/6/14 @@ -45,7 +44,7 @@ public class CexIOAdapters { /** * Adapts a CexIOTrade to a Trade Object * - * @param trade CexIO trade object + * @param trade CexIO trade object * @param currencyPair trade currencies * @return The XChange Trade */ @@ -61,7 +60,7 @@ public static Trade adaptTrade(CexIOTrade trade, CurrencyPair currencyPair) { /** * Adapts a CexIOTrade[] to a Trades Object * - * @param cexioTrades The CexIO trade data returned by API + * @param cexioTrades The CexIO trade data returned by API * @param currencyPair trade currencies * @return The trades */ @@ -83,7 +82,7 @@ public static Trades adaptTrades(CexIOTrade[] cexioTrades, CurrencyPair currency /** * Adapts a CexIOTicker to a Ticker Object * - * @param ticker The exchange specific ticker + * @param ticker The exchange specific ticker * @param currencyPair The currency pair (e.g. BTC/USD) * @return The ticker */ @@ -104,7 +103,7 @@ public static Ticker adaptTicker(CexIOTicker ticker, CurrencyPair currencyPair) /** * Adapts Cex.IO Depth to OrderBook Object * - * @param depth Cex.IO order book + * @param depth Cex.IO order book * @param currencyPair The currency pair (e.g. BTC/USD) * @return The XChange OrderBook */ @@ -185,7 +184,7 @@ public static UserTrade adaptArchivedOrder(CexIOArchivedOrder cexIOArchivedOrder Date timestamp = fromISODateString(cexIOArchivedOrder.time); OrderType orderType = cexIOArchivedOrder.type.equals("sell") ? OrderType.ASK : OrderType.BID; - BigDecimal originalAmount = new BigDecimal(cexIOArchivedOrder.amount); + BigDecimal originalAmount = cexIOArchivedOrder.amount; CurrencyPair currencyPair = new CurrencyPair(cexIOArchivedOrder.symbol1, cexIOArchivedOrder.symbol2); BigDecimal price = cexIOArchivedOrder.price; String id = cexIOArchivedOrder.id; diff --git a/xchange-cexio/src/main/java/org/knowm/xchange/cexio/dto/trade/CexIOArchivedOrder.java b/xchange-cexio/src/main/java/org/knowm/xchange/cexio/dto/trade/CexIOArchivedOrder.java index 3e6d4d11dd4..345fc4c3394 100644 --- a/xchange-cexio/src/main/java/org/knowm/xchange/cexio/dto/trade/CexIOArchivedOrder.java +++ b/xchange-cexio/src/main/java/org/knowm/xchange/cexio/dto/trade/CexIOArchivedOrder.java @@ -70,6 +70,31 @@ } Avg. Execution price: 2080.0000 + Example for a market order + { + "id": "5241152072", + "type": "buy", + "time": "2017-12-20T17:15:18.169Z", + "lastTxTime": "2017-12-20T17:15:18.169Z", + "lastTx": "5241152082", + "pos": null, + "status": "d", + "symbol1": "BCH", + "symbol2": "BTC", + "amount": "0.00000000", + "amount2": "0.50000000", + "remains": "0.00000000", + "tfa:BTC": "0.00114737", + "tta:BTC": "0.49885262", + "a:BCH:cds": "2.15022778", + "a:BTC:cds": "0.50000000", + "f:BTC:cds": "0.00114737", + "tradingFeeTaker": "0.23", + "tradingFeeUserVolumeAmount": "1315189290", + "orderId": "5241152072" + }, + + status - "d" — done (fully executed), "c" — canceled (not executed), "cd" — cancel-done (partially executed) ta:USD/tta:USD – total amount in current currency (Maker/Taker) fa:USD/tfa:USD – fee amount in current currency (Maker/Taker) @@ -90,7 +115,7 @@ public class CexIOArchivedOrder { public final String status; public final String symbol1; public final String symbol2; - public final String amount; + public final BigDecimal amount; public final BigDecimal price; public final String remains; public final String tradingFeeMaker; @@ -102,7 +127,7 @@ public class CexIOArchivedOrder { public CexIOArchivedOrder(String id, String type, String time, String lastTxTime, String lastTx, String pos, String status, String symbol1, - String symbol2, String amount, BigDecimal price, String remains, + String symbol2, BigDecimal amount, BigDecimal price, String remains, String tradingFeeMaker, String tradingFeeTaker, String tradingFeeUserVolumeAmount, String orderId, BigDecimal feeValue, String feeCcy) { this.id = id; @@ -169,6 +194,10 @@ public CexIOArchivedOrder deserialize(JsonParser jsonParser, DeserializationCont int scale = 8;//todo: check if this is correct for all BigDecimal price = filled.get(counter).divide(filled.get(base), scale, BigDecimal.ROUND_HALF_UP); + BigDecimal amount = new BigDecimal(map.get("amount")); + if(amount.compareTo(BigDecimal.ZERO) == 0) + amount = new BigDecimal(map.get("amount2"));//madness - i think the 'amount' field changes name for market orders + return new CexIOArchivedOrder( map.get("id"), map.get("type"), @@ -179,7 +208,7 @@ public CexIOArchivedOrder deserialize(JsonParser jsonParser, DeserializationCont map.get("status"), base, counter, - map.get("amount"), + amount, price, map.get("remains"), map.get("tradingFeeMaker"),