1313import org .apache .commons .lang3 .RandomStringUtils ;
1414import org .knowm .xchange .bybit .dto .BybitCategory ;
1515import org .knowm .xchange .bybit .dto .trade .BybitCancelOrderParams ;
16- import org .knowm .xchange .bybit .dto .trade .details .BybitHedgeMode ;
1716import org .knowm .xchange .bybit .service .BybitAccountService ;
1817import org .knowm .xchange .derivative .FuturesContract ;
1918import 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