Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bybit-stream] add all bybit parameters to PositionChanges subscription #4951

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,46 @@
import java.math.BigDecimal;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.knowm.xchange.bybit.dto.BybitCategory;
import org.knowm.xchange.dto.account.OpenPosition;
import org.knowm.xchange.instrument.Instrument;

@Getter
@Setter
@ToString
public class BybitComplexPositionChanges extends OpenPosition {

private int positionIdx;
private int tradeMode;
private int riskId;
private String riskLimitValue;
private BigDecimal markPrice;
private BigDecimal positionBalance;
private int autoAddMargin;
private BigDecimal positionMM;
private BigDecimal positionIM;
private BigDecimal bustPrice;
private BigDecimal positionValue;
private BigDecimal leverage;
private BigDecimal takeProfit;
private BigDecimal stopLoss;
private BigDecimal trailingStop;
private BigDecimal curRealisedPnl;
private BigDecimal sessionAvgPrice; //USDC contract session avg price
private String positionStatus;
private int adlRankIndicator;
private boolean isReduceOnly;
private String mmrSysUpdatedTime;
private String leverageSysUpdatedTime;
private long createdTime;
private long updatedTime;
private long seq;

public BybitComplexPositionChanges(
Instrument instrument,
Type type,
BigDecimal size,
BigDecimal liquidationPrice,
BigDecimal unRealisedPnl,
BigDecimal positionValue,
BigDecimal entryPrice,
BigDecimal leverage,
BigDecimal takeProfit,
BigDecimal stopLoss,
BigDecimal curRealisedPnl,
long createdTime,
long updatedTime,
public BybitComplexPositionChanges(Instrument instrument, Type type, BigDecimal size,
BigDecimal liquidationPrice, BigDecimal unRealisedPnl,
BigDecimal positionValue, BigDecimal entryPrice, BigDecimal leverage, BigDecimal takeProfit,
BigDecimal stopLoss, BigDecimal curRealisedPnl, long createdTime, long updatedTime,
long seq) {
super(instrument, type, size, entryPrice, liquidationPrice, unRealisedPnl);
this.positionValue = positionValue;
Expand All @@ -44,31 +55,77 @@ public BybitComplexPositionChanges(
this.seq = seq;
}

public BybitComplexPositionChanges(
Instrument instrument,
Type type,
BigDecimal size,
BigDecimal price,
BigDecimal liquidationPrice,
public BybitComplexPositionChanges(Instrument instrument, Type type, BigDecimal size,
BigDecimal price, BigDecimal liquidationPrice,
BigDecimal unRealisedPnl) {
super(instrument, type, size, price, liquidationPrice, unRealisedPnl);
}

public BybitComplexPositionChanges(BybitComplexPositionChanges changes) {
super(
changes.getInstrument(),
changes.getType(),
changes.getSize(),
changes.getPrice(),
changes.getLiquidationPrice(),
changes.getUnRealisedPnl());
super(changes.getInstrument(), changes.getType(), changes.getSize(), changes.getPrice(),
changes.getLiquidationPrice(), changes.getUnRealisedPnl());
this.positionIdx = changes.positionIdx;
this.tradeMode = changes.tradeMode;
this.riskId = changes.riskId;
this.riskLimitValue = changes.riskLimitValue;
this.markPrice = changes.markPrice;
this.positionBalance = changes.positionBalance;
this.autoAddMargin = changes.autoAddMargin;
this.positionMM = changes.positionMM;
this.positionIM = changes.positionIM;
this.bustPrice = changes.bustPrice;
this.positionValue = changes.positionValue;
this.leverage = changes.leverage;
this.takeProfit = changes.takeProfit;
this.stopLoss = changes.stopLoss;
this.trailingStop = changes.trailingStop;
this.curRealisedPnl = changes.curRealisedPnl;
this.sessionAvgPrice = changes.sessionAvgPrice;
this.positionStatus = changes.positionStatus;
this.adlRankIndicator = changes.adlRankIndicator;
this.isReduceOnly = changes.isReduceOnly;
this.mmrSysUpdatedTime = changes.mmrSysUpdatedTime;
this.leverageSysUpdatedTime = changes.leverageSysUpdatedTime;
this.createdTime = changes.createdTime;
this.updatedTime = changes.updatedTime;
this.seq = changes.seq;
}

public BybitComplexPositionChanges(Instrument instrument, Type type, BigDecimal size,
BigDecimal price, BigDecimal liquidationPrice, BigDecimal unRealisedPnl, int positionIdx,
int tradeMode, int riskId, String riskLimitValue, BigDecimal markPrice,
BigDecimal positionBalance, int autoAddMargin, BigDecimal positionMM, BigDecimal positionIM,
BigDecimal bustPrice, BigDecimal positionValue, BigDecimal leverage,
BigDecimal takeProfit, BigDecimal stopLoss, BigDecimal trailingStop,
BigDecimal curRealisedPnl,
BigDecimal sessionAvgPrice, String positionStatus, int adlRankIndicator, boolean isReduceOnly,
String mmrSysUpdatedTime, String leverageSysUpdatedTime, long createdTime, long updatedTime,
long seq) {
super(instrument, type, size, price, liquidationPrice, unRealisedPnl);
this.positionIdx = positionIdx;
this.tradeMode = tradeMode;
this.riskId = riskId;
this.riskLimitValue = riskLimitValue;
this.markPrice = markPrice;
this.positionBalance = positionBalance;
this.autoAddMargin = autoAddMargin;
this.positionMM = positionMM;
this.positionIM = positionIM;
this.bustPrice = bustPrice;
this.positionValue = positionValue;
this.leverage = leverage;
this.takeProfit = takeProfit;
this.stopLoss = stopLoss;
this.trailingStop = trailingStop;
this.curRealisedPnl = curRealisedPnl;
this.sessionAvgPrice = sessionAvgPrice;
this.positionStatus = positionStatus;
this.adlRankIndicator = adlRankIndicator;
this.isReduceOnly = isReduceOnly;
this.mmrSysUpdatedTime = mmrSysUpdatedTime;
this.leverageSysUpdatedTime = leverageSysUpdatedTime;
this.createdTime = createdTime;
this.updatedTime = updatedTime;
this.seq = seq;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,61 @@
import lombok.Getter;
import org.knowm.xchange.bybit.dto.BybitCategory;


@Getter
public class BybitPositionChangesResponse {

String id;
String topic;
long creationTime;
List<BybitPositionChanges> data = new ArrayList<>();
private String id;
private String topic;
private long creationTime;
private List<BybitPositionChanges> data = new ArrayList<>();

@Getter
public static class BybitPositionChanges {

BybitCategory category;
String symbol;
String side;
String size;
int positionIdx;
String tradeMode;
String positionValue;
int riskId;
String riskLimitValue;
String entryPrice;
String markPrice;
String leverage;
String positionBalance;
int autoAddMargin;
String positionMM;
String positionIM;
String liqPrice;
String bustPrice;
String tpslMode;
String takeProfit;
String stopLoss;
String trailingStop;
String unrealisedPnl;
String curRealisedPnl;
String sessionAvgPrice;
String delta;
String gamma;
String vega;
String theta;
String cumRealisedPnl;
String positionStatus;
int adlRankIndicator;
boolean isReduceOnly;

String mmrSysUpdatedTime;

String leverageSysUpdatedTime;

String createdTime;
String updatedTime;
long seq;
private BybitCategory category;
private String symbol;
private String side;
private String size;
private int positionIdx;
private int tradeMode;
private String positionValue;
private int riskId;
private String riskLimitValue;
private String entryPrice;
private String markPrice;
private String leverage;
private String positionBalance;
private int autoAddMargin;
private String positionMM;
private String positionIM;
private String liqPrice;
private String bustPrice;
private String tpslMode;
private String takeProfit;
private String stopLoss;
private String trailingStop;
private String unrealisedPnl;
private String curRealisedPnl;
private String sessionAvgPrice;
private String delta;
private String gamma;
private String vega;
private String theta;
private String cumRealisedPnl;
private String positionStatus;
private int adlRankIndicator;
private boolean isReduceOnly;

private String mmrSysUpdatedTime;

private String leverageSysUpdatedTime;

private String createdTime;
private String updatedTime;
private long seq;

}
}


Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,34 @@ public static List<BybitComplexPositionChanges> adaptComplexPositionChanges(
if (!position.getLiqPrice().isEmpty()) {
liqPrice = new BigDecimal(position.getLiqPrice());
}
BybitComplexPositionChanges positionChanges =
new BybitComplexPositionChanges(
guessSymbol(position.getSymbol(), position.getCategory()),
type,
new BigDecimal(position.getSize()),
liqPrice,
new BigDecimal(position.getUnrealisedPnl()),
new BigDecimal(position.getPositionValue()),
new BigDecimal(position.getEntryPrice()),
new BigDecimal(position.getLeverage()),
new BigDecimal(position.getTakeProfit()),
new BigDecimal(position.getStopLoss()),
new BigDecimal(position.getCurRealisedPnl()),
Long.parseLong(position.getCreatedTime()),
Long.parseLong(position.getUpdatedTime()),
position.getSeq());
BigDecimal bustPrice = null;
if(!position.getBustPrice().isEmpty()) {
bustPrice = new BigDecimal(position.getBustPrice());
}
BigDecimal sessionAvgPrice = null;
if (!position.getSessionAvgPrice().isEmpty()) {
sessionAvgPrice = new BigDecimal(position.getSessionAvgPrice());
}
BybitComplexPositionChanges positionChanges = new BybitComplexPositionChanges(
guessSymbol(position.getSymbol(),
position.getCategory()), type, new BigDecimal(position.getSize()),
new BigDecimal(position.getEntryPrice()), liqPrice,
new BigDecimal(position.getUnrealisedPnl()), position.getPositionIdx(),
position.getTradeMode(), position.getRiskId(), position.getRiskLimitValue(),
new BigDecimal(position.getMarkPrice()),
new BigDecimal(position.getPositionBalance()), position.getAutoAddMargin(),
new BigDecimal(position.getPositionMM()),
new BigDecimal(position.getPositionIM()),
bustPrice, new BigDecimal(position.getPositionValue()),
new BigDecimal(position.getLeverage()),
new BigDecimal(position.getTakeProfit()), new BigDecimal(position.getStopLoss()),
new BigDecimal(position.getTrailingStop()),
new BigDecimal(position.getCurRealisedPnl()),
sessionAvgPrice, position.getPositionStatus(),
position.getAdlRankIndicator(), position.isReduceOnly(),
position.getMmrSysUpdatedTime(), position.getLeverageSysUpdatedTime(),
Long.parseLong(position.getCreatedTime()), Long.parseLong(position.getUpdatedTime()),
position.getSeq());
result.add(positionChanges);
}
return result;
Expand All @@ -187,29 +199,17 @@ public static List<BybitComplexOrderChanges> adaptComplexOrdersChanges(
Order.OrderType orderType = getOrderType(change.getSide());
BigDecimal avgPrice =
change.getAvgPrice().isEmpty() ? null : new BigDecimal(change.getAvgPrice());
BybitComplexOrderChanges orderChanges =
new BybitComplexOrderChanges(
orderType,
new BigDecimal(change.getQty()),
guessSymbol(change.getSymbol(), change.getCategory()),
change.getOrderId(),
new Date(Long.parseLong(change.getCreatedTime())),
avgPrice,
new BigDecimal(change.getCumExecQty()),
new BigDecimal(change.getCumExecFee()),
adaptBybitOrderStatus(change.getOrderStatus()),
change.getOrderLinkId(),
change.getCategory(),
new BigDecimal(change.getPrice()),
change.getSide(),
new BigDecimal(change.getLeavesQty()),
new BigDecimal(change.getLeavesValue()),
new BigDecimal(change.getCumExecValue()),
change.getFeeCurrency(),
TimeInForce.valueOf(change.getTimeInForce().toUpperCase()),
change.getOrderType(),
change.isReduceOnly(),
new Date(Long.parseLong(change.getUpdatedTime())));
BybitComplexOrderChanges orderChanges = new BybitComplexOrderChanges(orderType,
new BigDecimal(change.getQty()), guessSymbol(change.getSymbol(), change.getCategory()),
change.getOrderId(),
new Date(Long.parseLong(change.getCreatedTime())), avgPrice,
new BigDecimal(change.getCumExecQty()), new BigDecimal(change.getCumExecFee()),
adaptBybitOrderStatus(change.getOrderStatus()), change.getOrderLinkId(),
change.getCategory(), new BigDecimal(change.getPrice()), change.getSide(),
new BigDecimal(change.getLeavesQty()), new BigDecimal(change.getLeavesValue()),
new BigDecimal(change.getCumExecValue()), change.getFeeCurrency(),
TimeInForce.valueOf(change.getTimeInForce().toUpperCase()), change.getOrderType(),
change.isReduceOnly(), new Date(Long.parseLong(change.getUpdatedTime())));
result.add(orderChanges);
}
return result;
Expand Down
Loading
Loading