Skip to content

Commit

Permalink
Merge pull request knowm#2051 from npomfret/develop
Browse files Browse the repository at this point in the history
[cexio] fixed bug that produce zero quantity for (i think) market orders because the parser was using the wrong field
  • Loading branch information
timmolter authored Dec 27, 2017
2 parents a8dcfc4 + 25d6902 commit 364e73f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down

0 comments on commit 364e73f

Please sign in to comment.