Skip to content

Commit 8b12d35

Browse files
authored
Merge pull request #5169 from rizer1980/PR/bybit-metadata-fix
bybit some small fixes
2 parents d410a85 + 744469a commit 8b12d35

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

xchange-bybit/src/main/java/org/knowm/xchange/bybit/BybitAdapters.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public static InstrumentMetaData symbolToCurrencyPairMetaData(
239239
.tradingFee(instrumentInfo.getDeliveryFeeRate())
240240
.volumeScale(instrumentInfo.getLotSizeFilter().getQtyStep().scale())
241241
.amountStepSize(instrumentInfo.getLotSizeFilter().getQtyStep())
242+
.counterMinimumAmount(instrumentInfo.getLotSizeFilter().getMinNotionalValue())
242243
.build();
243244
}
244245

@@ -539,8 +540,10 @@ public static BybitAmendOrderPayload adaptChangeOrder(LimitOrder order, BybitCa
539540
order.getId(),
540541
order.getUserReference(),
541542
null,
542-
order.getOriginalAmount().toPlainString(),
543-
order.getLimitPrice().toPlainString(),
543+
// conditional
544+
order.getOriginalAmount() == null ? null :order.getOriginalAmount().toPlainString(),
545+
// conditional
546+
order.getLimitPrice() == null ? null: order.getLimitPrice().toPlainString(),
544547
null,
545548
null,
546549
null,

xchange-bybit/src/main/java/org/knowm/xchange/bybit/dto/marketdata/instruments/linear/BybitLinearInverseInstrumentInfo.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,11 @@ public static class LotSizeFilter {
116116

117117
@JsonProperty("postOnlyMaxOrderQty")
118118
BigDecimal postOnlyMaxOrderQty;
119+
120+
@JsonProperty("maxMktOrderQty")
121+
BigDecimal maxMktOrderQty;
122+
123+
@JsonProperty("minNotionalValue")
124+
BigDecimal minNotionalValue;
119125
}
120126
}

xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitStreamAdapters.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,10 @@ public static BybitStreamBatchAmendOrdersPayload adaptBatchAmendOrder(LimitOrder
300300
order.getId(),
301301
order.getUserReference(),
302302
null,
303-
order.getOriginalAmount().toPlainString(),
304-
order.getLimitPrice().toPlainString(),
303+
// conditional
304+
order.getOriginalAmount() == null ? null :order.getOriginalAmount().toPlainString(),
305+
// conditional
306+
order.getLimitPrice() == null ? null: order.getLimitPrice().toPlainString(),
305307
null,
306308
null,
307309
null,

xchange-stream-bybit/src/main/java/info/bitrich/xchangestream/bybit/BybitUserTradeStreamingService.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,4 @@ public String getUnsubscribeMessage(String channelName, Object... args) throws I
182182
return null;
183183
}
184184

185-
@Override
186-
public void sendMessage(String message) {
187-
LOG.debug("Sending message: {}", message);
188-
super.sendMessage(message);
189-
}
190185
}

xchange-stream-bybit/src/test/java/info/bitrich/xchangestream/bybit/example/BybitStreamWebsocketTradeExample.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.apache.commons.lang3.RandomStringUtils;
1414
import org.knowm.xchange.bybit.dto.BybitCategory;
1515
import org.knowm.xchange.bybit.dto.trade.BybitCancelOrderParams;
16-
import org.knowm.xchange.bybit.dto.trade.details.BybitHedgeMode;
1716
import org.knowm.xchange.bybit.service.BybitAccountService;
1817
import org.knowm.xchange.derivative.FuturesContract;
1918
import org.knowm.xchange.dto.Order.OrderType;
@@ -52,15 +51,15 @@ public static void main(String[] args) throws IOException {
5251
private static void websocketBatchTradeExample() throws IOException, InterruptedException {
5352
CompositeDisposable compositeDisposable = new CompositeDisposable();
5453
// switch mode to two-way
55-
((BybitAccountService) exchange.getAccountService()).switchPositionMode(BybitCategory.LINEAR, instrument, "USDT", 3);
54+
((BybitAccountService) exchange.getAccountService()).switchPositionMode(BybitCategory.LINEAR, instrument, "USDT", 0);
5655
BigDecimal minAmount =
5756
exchange.getExchangeMetaData().getInstruments().get(instrument).getMinimumAmount();
5857
Ticker ticker = exchange.getMarketDataService().getTicker(instrument);
5958
minAmount = getMinAmount(new BigDecimal("5"), minAmount, ticker, exchange.getExchangeMetaData().getInstruments().get(instrument).getVolumeScale());
6059
String limitOrder1UserId = RandomStringUtils.randomAlphanumeric(20);
61-
LimitOrder limitOrder1 = new Builder(OrderType.ASK, instrument).originalAmount(minAmount).limitPrice(ticker.getHigh()).userReference(limitOrder1UserId).flag(BybitHedgeMode.TWOWAY).build();
60+
LimitOrder limitOrder1 = new Builder(OrderType.ASK, instrument).originalAmount(minAmount).limitPrice(ticker.getHigh()).userReference(limitOrder1UserId).build();
6261
String limitOrder2UserId = RandomStringUtils.randomAlphanumeric(20);
63-
LimitOrder limitOrder2 = new Builder(OrderType.ASK, instrument).originalAmount(minAmount).limitPrice(ticker.getHigh().add(BigDecimal.ONE)).userReference(limitOrder2UserId).flag(BybitHedgeMode.TWOWAY).build();
62+
LimitOrder limitOrder2 = new Builder(OrderType.ASK, instrument).originalAmount(minAmount).limitPrice(ticker.getHigh().add(BigDecimal.ONE)).userReference(limitOrder2UserId).build();
6463
compositeDisposable.add(exchange.getStreamingTradeService().placeLimitOrder(limitOrder1)
6564
.subscribe(result -> {
6665
LOG.info("limitOrder1 is send, retCode: {}", result);
@@ -70,8 +69,8 @@ private static void websocketBatchTradeExample() throws IOException, Interrupted
7069
LOG.info("limitOrder2 is send, retCode: {}", result);
7170
}, throwable -> LOG.error("throwable", throwable)));
7271
Thread.sleep(1000);
73-
LimitOrder changeOrder1 = new Builder(OrderType.ASK, instrument).originalAmount(minAmount).limitPrice(ticker.getHigh().add(new BigDecimal("0.01"))).userReference(limitOrder1UserId).flag(BybitHedgeMode.TWOWAY).build();
74-
LimitOrder changeOrder2 = new Builder(OrderType.ASK, instrument).originalAmount(new BigDecimal("0.01")).limitPrice(ticker.getHigh()).userReference(limitOrder2UserId).flag(BybitHedgeMode.TWOWAY).build();
72+
LimitOrder changeOrder1 = new Builder(OrderType.ASK, instrument).originalAmount(minAmount).limitPrice(ticker.getHigh().add(new BigDecimal("0.01"))).userReference(limitOrder1UserId).build();
73+
LimitOrder changeOrder2 = new Builder(OrderType.ASK, instrument).originalAmount(new BigDecimal("0.01")).limitPrice(ticker.getHigh()).userReference(limitOrder2UserId).build();
7574
compositeDisposable.add(exchange.getStreamingTradeService().batchChangeOrder(List.of(changeOrder1,changeOrder2))
7675
.subscribe(result -> {
7776
LOG.info("changeOrder(1,2) is send, retCode: {}", result);
@@ -82,20 +81,20 @@ private static void websocketBatchTradeExample() throws IOException, Interrupted
8281

8382
private static void websocketTradeExample() throws IOException, InterruptedException {
8483
// switch mode to two-way
85-
((BybitAccountService) exchange.getAccountService()).switchPositionMode(BybitCategory.LINEAR, instrument, "USDT", 3);
84+
((BybitAccountService) exchange.getAccountService()).switchPositionMode(BybitCategory.LINEAR, instrument, "USDT", 0);
8685
BigDecimal minAmount =
8786
exchange.getExchangeMetaData().getInstruments().get(instrument).getMinimumAmount();
8887
Ticker ticker = exchange.getMarketDataService().getTicker(instrument);
8988
minAmount = getMinAmount(new BigDecimal("5"), minAmount, ticker, exchange.getExchangeMetaData().getInstruments().get(instrument).getVolumeScale());
9089
String limitOrder1UserId = RandomStringUtils.randomAlphanumeric(20);
91-
LimitOrder limitOrder1 = new Builder(OrderType.ASK, instrument).originalAmount(minAmount).limitPrice(ticker.getHigh()).userReference(limitOrder1UserId).flag(BybitHedgeMode.TWOWAY).build();
90+
LimitOrder limitOrder1 = new Builder(OrderType.ASK, instrument).originalAmount(minAmount).limitPrice(ticker.getHigh()).userReference(limitOrder1UserId).build();
9291
Disposable limitOrder1Disposable = exchange.getStreamingTradeService().placeLimitOrder(limitOrder1)
9392
.subscribe(result -> {
9493
LOG.info("limitOrder1 is send, retCode: {}", result);
9594
}, throwable -> LOG.error("throwable", throwable));
9695
Thread.sleep(1000);
9796
LOG.info("limitOrder1 is disposed: {}", limitOrder1Disposable.isDisposed());
98-
LimitOrder changeOrder1 = new Builder(OrderType.ASK, instrument).originalAmount(minAmount).limitPrice(ticker.getHigh().add(BigDecimal.ONE)).userReference(limitOrder1UserId).build();
97+
LimitOrder changeOrder1 = new Builder(OrderType.ASK, instrument).limitPrice(ticker.getHigh().add(BigDecimal.ONE)).userReference(limitOrder1UserId).build();
9998
Disposable changeOrder1Disposable = exchange.getStreamingTradeService().changeOrder(changeOrder1)
10099
.subscribe(result -> {
101100
LOG.info("changeOrder1 is send, retCode: {}", result);
@@ -110,7 +109,6 @@ private static void websocketTradeExample() throws IOException, InterruptedExcep
110109
LOG.info("cancelOrder1 is disposed: {}", cancelOrder1Disposable.isDisposed());
111110
Thread.sleep(1000);
112111
MarketOrder marketOrder = new MarketOrder(OrderType.ASK, minAmount, instrument);
113-
marketOrder.addOrderFlag(BybitHedgeMode.TWOWAY);
114112
Disposable marketOrderDisposable = exchange.getStreamingTradeService().placeMarketOrder(marketOrder)
115113
.subscribe(result -> {
116114
LOG.info("marketOrder is send, retCode: {}", result);

0 commit comments

Comments
 (0)