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

OKX getOpenPositions is inconsistenet #4776

Open douggie opened 1 year ago

douggie commented 1 year ago

Hi, the getOpenPositions for coin based positions will display in the notional amoutns i.e. number of contracts * multiplier but for the usdt based positions it will display contracts.

I suggest we always display contract position by changing this

 public static OpenPositions adaptOpenPositions(OkexResponse<List<OkexPosition>> positions, ExchangeMetaData exchangeMetaData) {
    List<OpenPosition> openPositions = new ArrayList<>();

    positions.getData().forEach(okexPosition -> openPositions.add(
        new OpenPosition.Builder().instrument(adaptOkexInstrumentId(okexPosition.getInstrumentId()))
            .liquidationPrice(okexPosition.getLiquidationPrice()).price(okexPosition.getAverageOpenPrice()).type(adaptOpenPositionType(okexPosition))
            .size(okexPosition.getPosition().abs()
                .multiply(exchangeMetaData.getInstruments().get(adaptOkexInstrumentId(okexPosition.getInstrumentId())).getContractValue()))
            .unRealisedPnl(okexPosition.getUnrealizedPnL()).build()));
    return new OpenPositions(openPositions);
  }

to

public static OpenPositions adaptOpenPositions(OkexResponse<List<OkexPosition>> positions, ExchangeMetaData exchangeMetaData) {
    List<OpenPosition> openPositions = new ArrayList<>();

    positions.getData().forEach(okexPosition -> openPositions.add(
        new OpenPosition.Builder().instrument(adaptOkexInstrumentId(okexPosition.getInstrumentId()))
            .liquidationPrice(okexPosition.getLiquidationPrice()).price(okexPosition.getAverageOpenPrice()).type(adaptOpenPositionType(okexPosition))
            .size(okexPosition.getPosition())
            .unRealisedPnl(okexPosition.getUnrealizedPnL()).build()));
    return new OpenPositions(openPositions);
  }}