diff --git a/src/main/java/com/bybit/api/client/domain/market/response/fundingRate/FundingRateEntry.java b/src/main/java/com/bybit/api/client/domain/market/response/fundingRate/FundingRateEntry.java index 7fe8be5..ebcbf7f 100644 --- a/src/main/java/com/bybit/api/client/domain/market/response/fundingRate/FundingRateEntry.java +++ b/src/main/java/com/bybit/api/client/domain/market/response/fundingRate/FundingRateEntry.java @@ -7,8 +7,8 @@ @Getter public class FundingRateEntry { private String symbol; - private String fundingRate; - private String fundingRateTimestamp; + private double fundingRate; + private long fundingRateTimestamp; @Override public String toString() { diff --git a/src/main/java/com/bybit/api/client/domain/market/response/kline/MarketKlineEntry.java b/src/main/java/com/bybit/api/client/domain/market/response/kline/MarketKlineEntry.java index a71be5d..998ad1d 100644 --- a/src/main/java/com/bybit/api/client/domain/market/response/kline/MarketKlineEntry.java +++ b/src/main/java/com/bybit/api/client/domain/market/response/kline/MarketKlineEntry.java @@ -9,12 +9,12 @@ @JsonFormat(shape = JsonFormat.Shape.ARRAY) public class MarketKlineEntry { private long startTime; - private String openPrice; - private String highPrice; - private String lowPrice; - private String closePrice; - private String volume; - private String turnover; + private double openPrice; + private double highPrice; + private double lowPrice; + private double closePrice; + private double volume; + private double turnover; @Override public String toString() { diff --git a/src/main/java/com/bybit/api/client/domain/market/response/serverTime/ServerTimeResult.java b/src/main/java/com/bybit/api/client/domain/market/response/serverTime/ServerTimeResult.java index 3ad6d29..776f5cf 100644 --- a/src/main/java/com/bybit/api/client/domain/market/response/serverTime/ServerTimeResult.java +++ b/src/main/java/com/bybit/api/client/domain/market/response/serverTime/ServerTimeResult.java @@ -8,7 +8,7 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class ServerTimeResult { @JsonProperty("timeSecond") - private String timeSecond; + private long timeSecond; @JsonProperty("timeNano") - private String timeNano; + private long timeNano; } diff --git a/src/main/java/com/bybit/api/client/impl/BybitApiMarketAsyncRestClientImpl.java b/src/main/java/com/bybit/api/client/impl/BybitApiMarketAsyncRestClientImpl.java index b82942d..10c7d17 100644 --- a/src/main/java/com/bybit/api/client/impl/BybitApiMarketAsyncRestClientImpl.java +++ b/src/main/java/com/bybit/api/client/impl/BybitApiMarketAsyncRestClientImpl.java @@ -4,6 +4,8 @@ import com.bybit.api.client.restApi.BybitApiCallback; import com.bybit.api.client.restApi.BybitApiService; import com.bybit.api.client.domain.market.request.MarketDataRequest; +import com.bybit.api.client.domain.GenericResponse; +import com.bybit.api.client.domain.market.response.serverTime.ServerTimeResult; import static com.bybit.api.client.service.BybitApiServiceGenerator.createService; @@ -15,7 +17,7 @@ public BybitApiMarketAsyncRestClientImpl(String baseUrl, boolean debugMode, long } // Market Data endpoints @Override - public void getServerTime(BybitApiCallback callback) { + public void getServerTime(BybitApiCallback> callback) { bybitApiService.getServerTime().enqueue(new BybitApiCallbackAdapter<>(callback)); } diff --git a/src/main/java/com/bybit/api/client/impl/BybitApiMarketRestClientImpl.java b/src/main/java/com/bybit/api/client/impl/BybitApiMarketRestClientImpl.java index 0bf8bac..07d2b1a 100644 --- a/src/main/java/com/bybit/api/client/impl/BybitApiMarketRestClientImpl.java +++ b/src/main/java/com/bybit/api/client/impl/BybitApiMarketRestClientImpl.java @@ -1,5 +1,7 @@ package com.bybit.api.client.impl; +import com.bybit.api.client.domain.GenericResponse; +import com.bybit.api.client.domain.market.response.serverTime.ServerTimeResult; import com.bybit.api.client.restApi.BybitApiMarketRestClient; import com.bybit.api.client.restApi.BybitApiService; import com.bybit.api.client.domain.market.request.MarketDataRequest; @@ -29,7 +31,7 @@ public Object getAnnouncementInfo(MarketDataRequest announcementInfoRequest) { } @Override - public Object getServerTime() { + public GenericResponse getServerTime() { return executeSync( bybitApiService.getServerTime()); } diff --git a/src/main/java/com/bybit/api/client/restApi/BybitApiAsyncMarketDataRestClient.java b/src/main/java/com/bybit/api/client/restApi/BybitApiAsyncMarketDataRestClient.java index 2d91928..cbdf830 100644 --- a/src/main/java/com/bybit/api/client/restApi/BybitApiAsyncMarketDataRestClient.java +++ b/src/main/java/com/bybit/api/client/restApi/BybitApiAsyncMarketDataRestClient.java @@ -1,11 +1,12 @@ package com.bybit.api.client.restApi; -import com.bybit.api.client.domain.announcement.request.AnnouncementInfoRequest; +import com.bybit.api.client.domain.GenericResponse; import com.bybit.api.client.domain.market.request.MarketDataRequest; +import com.bybit.api.client.domain.market.response.serverTime.ServerTimeResult; public interface BybitApiAsyncMarketDataRestClient { // Market endpoints - void getServerTime(BybitApiCallback callback); + void getServerTime(BybitApiCallback> callback); void getMarketLinesData(MarketDataRequest marketKlineRequest, BybitApiCallback callback); void getMarketPriceLinesData(MarketDataRequest marketKlineRequest, BybitApiCallback callback); void getIndexPriceLinesData(MarketDataRequest marketKlineRequest, BybitApiCallback callback); diff --git a/src/main/java/com/bybit/api/client/restApi/BybitApiMarketRestClient.java b/src/main/java/com/bybit/api/client/restApi/BybitApiMarketRestClient.java index 11e5352..b19bc78 100644 --- a/src/main/java/com/bybit/api/client/restApi/BybitApiMarketRestClient.java +++ b/src/main/java/com/bybit/api/client/restApi/BybitApiMarketRestClient.java @@ -1,11 +1,12 @@ package com.bybit.api.client.restApi; -import com.bybit.api.client.domain.announcement.request.AnnouncementInfoRequest; +import com.bybit.api.client.domain.GenericResponse; import com.bybit.api.client.domain.market.request.MarketDataRequest; +import com.bybit.api.client.domain.market.response.serverTime.ServerTimeResult; public interface BybitApiMarketRestClient { // Market Data - Object getServerTime(); + GenericResponse getServerTime(); Object getMarketLinesData(MarketDataRequest marketKlineRequest); Object getMarketPriceLinesData(MarketDataRequest marketKlineRequest); Object getIndexPriceLinesData(MarketDataRequest marketKlineRequest); diff --git a/src/main/java/com/bybit/api/client/restApi/BybitApiService.java b/src/main/java/com/bybit/api/client/restApi/BybitApiService.java index 0de970b..69a7543 100644 --- a/src/main/java/com/bybit/api/client/restApi/BybitApiService.java +++ b/src/main/java/com/bybit/api/client/restApi/BybitApiService.java @@ -1,6 +1,7 @@ package com.bybit.api.client.restApi; import com.bybit.api.client.constant.BybitApiConstants; +import com.bybit.api.client.domain.GenericResponse; import com.bybit.api.client.domain.account.request.*; import com.bybit.api.client.domain.asset.request.*; import com.bybit.api.client.domain.broker.request.BrokerGetIssuedVoucherRequest; @@ -8,6 +9,7 @@ import com.bybit.api.client.domain.broker.request.BrokerVoucherSpecRequest; import com.bybit.api.client.domain.institution.clientLending.ClientLendingFundsRequest; import com.bybit.api.client.domain.institution.insLending.UpdateInstitutionLoadUidRequest; +import com.bybit.api.client.domain.market.response.serverTime.ServerTimeResult; import com.bybit.api.client.domain.position.request.ConfirmNewRiskLimitRequest; import com.bybit.api.client.domain.position.request.*; import com.bybit.api.client.domain.spot.leverageToken.SpotLeverageTokenRequest; @@ -41,7 +43,7 @@ public interface BybitApiService { * timeNano string Bybit server timestamp (nano) */ @GET("/v5/market/time") - Call getServerTime(); + Call> getServerTime(); /** * Get Kline diff --git a/src/main/java/com/bybit/api/client/service/BybitApiServiceGenerator.java b/src/main/java/com/bybit/api/client/service/BybitApiServiceGenerator.java index 293bd42..4aad7bb 100644 --- a/src/main/java/com/bybit/api/client/service/BybitApiServiceGenerator.java +++ b/src/main/java/com/bybit/api/client/service/BybitApiServiceGenerator.java @@ -88,7 +88,7 @@ public static S createService(Class serviceClass, String apiKey, String s /** * Execute a REST call and block until the response is received. */ - public static Object executeSync(Call call) { + public static T executeSync(Call call) { try { var response = call.execute(); if (response.isSuccessful()) { diff --git a/src/test/java/com/bybit/api/domain/market/FundingRateResultDeserializerTest.java b/src/test/java/com/bybit/api/domain/market/FundingRateResultDeserializerTest.java index 8d9c1a4..9671860 100644 --- a/src/test/java/com/bybit/api/domain/market/FundingRateResultDeserializerTest.java +++ b/src/test/java/com/bybit/api/domain/market/FundingRateResultDeserializerTest.java @@ -14,6 +14,8 @@ import static org.junit.Assert.fail; public class FundingRateResultDeserializerTest { + double delta = 1e-6; + @Test public void testFundingRateResultDeserializer() { @@ -50,8 +52,8 @@ public void testFundingRateResultDeserializer() List entries = fundingRateResult.getFundingRateEntries(); assertEquals(entries.size(), 2); assertEquals(entries.get(0).getSymbol(), "BTCUSDT"); - assertEquals(entries.get(0).getFundingRate(), "0.00020343"); - assertEquals(entries.get(0).getFundingRateTimestamp(), "1699776000000"); + assertEquals(entries.get(0).getFundingRate(), 0.00020343, delta); + assertEquals(entries.get(0).getFundingRateTimestamp(), 1699776000000L); }catch (IOException e) { System.out.println(e.getMessage()); fail(); diff --git a/src/test/java/com/bybit/api/domain/market/MarketKlineResultDeserializerTest.java b/src/test/java/com/bybit/api/domain/market/MarketKlineResultDeserializerTest.java index 6ab3497..f7bdcbc 100644 --- a/src/test/java/com/bybit/api/domain/market/MarketKlineResultDeserializerTest.java +++ b/src/test/java/com/bybit/api/domain/market/MarketKlineResultDeserializerTest.java @@ -14,6 +14,7 @@ import static org.junit.Assert.fail; public class MarketKlineResultDeserializerTest { + double delta = 1e-6; @Test public void testMarketKlineResultDeserializer() { @@ -61,19 +62,19 @@ public void testMarketKlineResultDeserializer() { List entries = marketKlineResult.getMarketKlineEntries(); assertEquals(entries.size(), 2); assertEquals(Optional.of(entries.get(0).getStartTime()).get(), Long.valueOf("1691971200000")); - assertEquals(entries.get(0).getOpenPrice(), "28349.56"); - assertEquals(entries.get(0).getHighPrice(), "29752.1178"); - assertEquals(entries.get(0).getLowPrice(), "18000"); - assertEquals(entries.get(0).getClosePrice(), "21335"); - assertEquals(entries.get(0).getVolume(), "10531.829385"); - assertEquals(entries.get(0).getTurnover(), "290473145.2723997623"); + assertEquals(entries.get(0).getOpenPrice(), 28349.56, delta); + assertEquals(entries.get(0).getHighPrice(), 29752.1178, delta); + assertEquals(entries.get(0).getLowPrice(), 18000.0, delta); + assertEquals(entries.get(0).getClosePrice(), 21335.0, delta); + assertEquals(entries.get(0).getVolume(), 10531.829385, delta); + assertEquals(entries.get(0).getTurnover(), 290473145.2723997623, delta); assertEquals(Optional.of(entries.get(1).getStartTime()).get(), Long.valueOf("1691366400000")); - assertEquals(entries.get(1).getOpenPrice(), "31847.42"); - assertEquals(entries.get(1).getHighPrice(), "31895.5621"); - assertEquals(entries.get(1).getLowPrice(), "6331.63"); - assertEquals(entries.get(1).getClosePrice(), "28349.56"); - assertEquals(entries.get(1).getVolume(), "7519.172778"); - assertEquals(entries.get(1).getTurnover(), "188453792.2371207168"); + assertEquals(entries.get(1).getOpenPrice(), 31847.42, delta); + assertEquals(entries.get(1).getHighPrice(), 31895.5621, delta); + assertEquals(entries.get(1).getLowPrice(), 6331.63, delta); + assertEquals(entries.get(1).getClosePrice(), 28349.56, delta); + assertEquals(entries.get(1).getVolume(), 7519.172778, delta); + assertEquals(entries.get(1).getTurnover(), 188453792.2371207168, delta); } catch (IOException e) { System.out.println(e.getMessage()); fail(); diff --git a/src/test/java/com/bybit/api/domain/market/ServerTimeResultDeserializerTest.java b/src/test/java/com/bybit/api/domain/market/ServerTimeResultDeserializerTest.java index 3ccd4ad..75da367 100644 --- a/src/test/java/com/bybit/api/domain/market/ServerTimeResultDeserializerTest.java +++ b/src/test/java/com/bybit/api/domain/market/ServerTimeResultDeserializerTest.java @@ -38,8 +38,8 @@ public void testServerTimeResultDeserializer() assertEquals(response.getRetMsg(), "OK"); // Accessing the fields of the result ServerTimeResult serverTimeResult = response.getResult(); - assertEquals(serverTimeResult.getTimeNano(), "1699816496197575040"); - assertEquals(serverTimeResult.getTimeSecond(), "1699816496"); + assertEquals(serverTimeResult.getTimeNano(), 1699816496197575040L); + assertEquals(serverTimeResult.getTimeSecond(), 1699816496L); }catch (IOException e) { System.out.println(e.getMessage()); fail();