knowm / XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.
http://knowm.org/open-source/xchange/
MIT License
3.85k stars 1.94k forks source link

GDAX trade history bid(buy) and ask(sell) side reversed? #2468

Open andrewlin0410 opened 6 years ago

andrewlin0410 commented 6 years ago

According to GDAX : The trade side indicates the maker order side. The maker order is the order that was open on the order book. buy side indicates a down-tick because the maker was a buy order and their order was removed. Conversely, sell side indicates an up-tick. However, the resultant xchange trades from Gdax do not follow this. I looked at the Json from gdax, it does follow the above statement. I think this line needs to be changed: OrderType type = trade.getSide().equals("sell") ? OrderType.BID : OrderType.ASK; For BFX, the Json and resultant xchange trades follow the opposite. For Binance, the resultant xchange trades follow the above statement. I did not check Json. It's all very confusing, I hope we can standardize this issue for xchange. To manually reverse I wrote the bellow. Tell me if there's a better way. void flipBuySellSides(Trades trades) { for (int i = 0; i < trades.getTrades().size(); i++) { Trade trade = trades.getTrades().get(i); if (trade.getType() == Order.OrderType.BID) { trades.getTrades().set(i, new Trade(Order.OrderType.ASK, trade.getOriginalAmount(), trade.getCurrencyPair(), trade.getPrice(), trade.getTimestamp(), trade.getId())); } else if (trade.getType() == Order.OrderType.ASK) { trades.getTrades().set(i, new Trade(Order.OrderType.BID, trade.getOriginalAmount(), trade.getCurrencyPair(), trade.getPrice(), trade.getTimestamp(), trade.getId())); } } }

andrewlin0410 commented 6 years ago

Is this issue gonna be addressed in the next version?

andrewlin0410 commented 6 years ago

Can you guys please do something about this cos the entire feature of getting trades seems useless when we don't know which side is which.

timmolter commented 6 years ago

Please submit a PR with the fix.

badgerwithagun commented 5 years ago

I have also observed this, however GDAX is not the only one.

GDAX, Bitfinex, Bitstamp and Kucoin all follow the same behaviour as GDAX (sell=ASK, buy=BID). The only exchange I use that does the opposite (sell=BID, buy=ASK) is Binance.

I was about to put in a fix which reversed the Binance behaviour to bring it in line with the rest, but if @andrewlin0410 is right and actually Binance is the only one that's correctly implemented, that complicates things a bit.

Should I go swapping the order types on all these exchanges? That's a pretty big impact on existing users, and ultimately probably academic. Who cares whether XChange returns BID or ASK as long as it's consistent between exchanges?

Thoughts @timmolter? I'm leaning towards just changing Binance.

timmolter commented 5 years ago

I think the best would be to make XChange consistent across all exchanges. Originally, we went with the sell=ASK and buy=BID convention from the client's (taker's) perspective. I think someone tried to reverse the convention of Binance once, and some people were opposed to it. However, I wasn't really aware of the overall convention mismatch at the time I think.

badgerwithagun commented 5 years ago

OK, so, @timmolter, it's either:

  1. Change every exchange except Binance, to bring XChange as a whole in line with the prevailing convention. Much higher impact but probably "right" or
  2. Change Binance to match the rest of XChange. Only affects one exchange, so lowest impact.

Are we leaning towards (2)?