Skip to content

Commit

Permalink
format via mvn com.spotify.fmt:fmt-maven-plugin:format
Browse files Browse the repository at this point in the history
  • Loading branch information
timmolter committed Dec 11, 2024
1 parent da97115 commit 1e37e36
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ CoinexResponse<CoinexSingleMarketStatisticsV1> singleMarketStatistics(

@GET
@Path("v2/maintain/info")
CoinexResponse<List<CoinexMaintainInfo>> maintainInfo()
throws IOException, CoinexException;

CoinexResponse<List<CoinexMaintainInfo>> maintainInfo() throws IOException, CoinexException;

@GET
@Path("v2/spot/market")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,24 @@
@Jacksonized
public class CoinexMaintainInfo {

@JsonProperty("started_at")
private Instant startTime;
@JsonProperty("started_at")
private Instant startTime;

@JsonProperty("ended_at")
private Instant endTime;
@JsonProperty("ended_at")
private Instant endTime;

@JsonProperty("scope")
private List<String> scope;
@JsonProperty("scope")
private List<String> scope;

@JsonProperty("announce_enabled")
private Boolean announceEnabled;
@JsonProperty("announce_enabled")
private Boolean announceEnabled;

@JsonProperty("announce_url")
private URI announceUrl;
@JsonProperty("announce_url")
private URI announceUrl;

@JsonProperty("protect_duration_start")
private Instant protectStart;

@JsonProperty("protect_duration_end")
private Instant protectEnd;
@JsonProperty("protect_duration_start")
private Instant protectStart;

@JsonProperty("protect_duration_end")
private Instant protectEnd;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ public ExchangeHealth getExchangeHealth() {
try {
List<CoinexMaintainInfo> coinexMaintainInfos = getCoinexMaintainInfo();

for (CoinexMaintainInfo coinexMaintainInfo: coinexMaintainInfos) {
for (CoinexMaintainInfo coinexMaintainInfo : coinexMaintainInfos) {
Instant now = Instant.now(Config.getInstance().getClock());
if (ObjectUtils.allNotNull(coinexMaintainInfo.getStartTime(),
coinexMaintainInfo.getEndTime())) {
if (now.isAfter(coinexMaintainInfo.getStartTime()) && now.isBefore(
coinexMaintainInfo.getEndTime())) {
if (ObjectUtils.allNotNull(
coinexMaintainInfo.getStartTime(), coinexMaintainInfo.getEndTime())) {
if (now.isAfter(coinexMaintainInfo.getStartTime())
&& now.isBefore(coinexMaintainInfo.getEndTime())) {
return ExchangeHealth.OFFLINE;
}
}

if (ObjectUtils.allNotNull(coinexMaintainInfo.getProtectStart(),
coinexMaintainInfo.getProtectEnd())) {
if (now.isAfter(coinexMaintainInfo.getProtectStart()) && now.isBefore(
coinexMaintainInfo.getProtectEnd())) {
if (ObjectUtils.allNotNull(
coinexMaintainInfo.getProtectStart(), coinexMaintainInfo.getProtectEnd())) {
if (now.isAfter(coinexMaintainInfo.getProtectStart())
&& now.isBefore(coinexMaintainInfo.getProtectEnd())) {
return ExchangeHealth.OFFLINE;
}
}
Expand All @@ -66,7 +66,6 @@ public ExchangeHealth getExchangeHealth() {
return ExchangeHealth.ONLINE;
}


@Override
public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException {
return getTicker((Instrument) currencyPair, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ public CoinexMarketDataServiceRaw(CoinexExchange exchange) {
super(exchange);
}


public List<CoinexMaintainInfo> getCoinexMaintainInfo() throws IOException {
return coinex.maintainInfo().getData();
}


public List<CoinexChainInfo> getAllCoinexChainInfos() throws IOException {
return new ArrayList<>(coinex.allChainInfos().getData().values());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class CoinexMarketDataServiceIntegration {

@Test
public void exchange_health() {
assertThat(exchange.getMarketDataService().getExchangeHealth()).isEqualTo(ExchangeHealth.ONLINE);
assertThat(exchange.getMarketDataService().getExchangeHealth())
.isEqualTo(ExchangeHealth.ONLINE);
}


@Test
void valid_tickers() throws IOException {
List<Ticker> tickers = exchange.getMarketDataService().getTickers(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package org.knowm.xchange.service.trade.params;

/**
* {@link TradeHistoryParams} with client order id as param
*/
/** {@link TradeHistoryParams} with client order id as param */
public interface TradeHistoryParamClientOid extends TradeHistoryParams {

String getClientOid();

void setClientOid(String clientOid);

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package org.knowm.xchange.service.trade.params;

/**
* {@link TradeHistoryParams} with order id as param
*/
/** {@link TradeHistoryParams} with order id as param */
public interface TradeHistoryParamOrderId extends TradeHistoryParams {

String getOrderId();

void setOrderId(String orderId);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.knowm.xchange.service.trade.params;

/**
* {@link TradeHistoryParams} with id of single trade as param
*/
/** {@link TradeHistoryParams} with id of single trade as param */
public interface TradeHistoryParamTransactionId extends TradeHistoryParams {
String getTransactionId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public GateioTradeService(GateioExchange exchange) {
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
Validate.isInstanceOf(InstrumentParam.class, params);
Instrument instrument = ((InstrumentParam) params).getInstrument();
List<LimitOrder> limitOrders = listOrders(instrument, OrderStatus.OPEN).stream()
.map(GateioAdapters::toOrder)
.map(LimitOrder.class::cast)
.collect(Collectors.toList());
List<LimitOrder> limitOrders =
listOrders(instrument, OrderStatus.OPEN).stream()
.map(GateioAdapters::toOrder)
.map(LimitOrder.class::cast)
.collect(Collectors.toList());
return new OpenOrders(limitOrders);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ void open_orders() throws IOException {
.build();

OpenOrders openOrders =
gateioTradeService.getOpenOrders(new DefaultOpenOrdersParamInstrument(CurrencyPair.BTC_USDT));
gateioTradeService.getOpenOrders(
new DefaultOpenOrdersParamInstrument(CurrencyPair.BTC_USDT));
assertThat(openOrders.getOpenOrders()).hasSize(1);
assertThat(openOrders.getOpenOrders()).first().usingRecursiveComparison().isEqualTo(expected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public class BinanceStreamingMarketDataService implements StreamingMarketDataSer
orderBookRawUpdatesSubscriptions;
private Observable<List<BinanceTicker24h>> allRollingWindowTickerSubscriptions;


/**
* A scheduler for initialisation of binance order book snapshots, which is delegated to a
* dedicated thread in order to avoid blocking of the Web Socket threads.
Expand Down Expand Up @@ -217,15 +216,19 @@ public Observable<BinanceTicker24h> getRawTicker(Instrument instrument) {
instrument, s -> triggerObservableBody(rawTickerStream(instrument)).share());
}

public Observable<BinanceTicker24h> rollingWindow(Instrument instrument, KlineInterval windowSize) {
public Observable<BinanceTicker24h> rollingWindow(
Instrument instrument, KlineInterval windowSize) {
if (!service.isLiveSubscriptionEnabled()
&& !service.getProductSubscription().getTicker().contains(instrument)) {
throw new UpFrontSubscriptionRequiredException();
}
if(windowSize.equals(KlineInterval.h1) || windowSize.equals(KlineInterval.h4) || windowSize.equals(KlineInterval.d1)) {
if (windowSize.equals(KlineInterval.h1)
|| windowSize.equals(KlineInterval.h4)
|| windowSize.equals(KlineInterval.d1)) {
return rollingWindowTickerSubscriptions.computeIfAbsent(
instrument, s -> triggerObservableBody(rollingWindowStream(instrument, windowSize)).share());
}else {
instrument,
s -> triggerObservableBody(rollingWindowStream(instrument, windowSize)).share());
} else {
throw new UnsupportedOperationException("RollingWindow not supported for other window size!");
}
}
Expand All @@ -234,13 +237,16 @@ public Observable<List<BinanceTicker24h>> allRollingWindow(KlineInterval windowS
if (!service.isLiveSubscriptionEnabled()) {
throw new UpFrontSubscriptionRequiredException();
}
if(windowSize.equals(KlineInterval.h1) || windowSize.equals(KlineInterval.h4) || windowSize.equals(KlineInterval.d1)) {
if(null != allRollingWindowTickerSubscriptions){
if (windowSize.equals(KlineInterval.h1)
|| windowSize.equals(KlineInterval.h4)
|| windowSize.equals(KlineInterval.d1)) {
if (null != allRollingWindowTickerSubscriptions) {
return allRollingWindowTickerSubscriptions.share();
}
allRollingWindowTickerSubscriptions = triggerObservableBody(allRollingWindowStream(windowSize)).share();
allRollingWindowTickerSubscriptions =
triggerObservableBody(allRollingWindowStream(windowSize)).share();
return allRollingWindowTickerSubscriptions;
}else {
} else {
throw new UnsupportedOperationException("RollingWindow not supported for other window size!");
}
}
Expand Down Expand Up @@ -405,7 +411,6 @@ public void unsubscribeKline(Instrument instrument, KlineInterval klineInterval)
unsubscribe(instrument, KLINE, klineInterval);
}


public void unsubscribeAllRollingWindow(KlineInterval klineInterval) {
unsubscribe(null, TICKER_WINDOW, klineInterval);
}
Expand Down Expand Up @@ -436,9 +441,9 @@ private void unsubscribe(
tickerSubscriptions.remove(instrument);
break;
case TICKER_WINDOW:
if(null == instrument){
if (null == instrument) {
allRollingWindowTickerSubscriptions = null;
}else {
} else {
rollingWindowTickerSubscriptions.remove(instrument);
}
break;
Expand Down Expand Up @@ -504,11 +509,18 @@ private Observable<BinanceTicker24h> rawTickerStream(Instrument instrument) {
.map(transaction -> transaction.getData().getTicker());
}

private Observable<BinanceTicker24h> rollingWindowStream(Instrument instrument, KlineInterval windowSize) {
private Observable<BinanceTicker24h> rollingWindowStream(
Instrument instrument, KlineInterval windowSize) {
return this.service
.subscribeChannel(this.getChannelPrefix(instrument) + "@" + BinanceSubscriptionType.TICKER_WINDOW.getType() + windowSize.code(), new Object[0])
.subscribeChannel(
this.getChannelPrefix(instrument)
+ "@"
+ BinanceSubscriptionType.TICKER_WINDOW.getType()
+ windowSize.code(),
new Object[0])
.map(
(it) -> this.<TickerBinanceWebsocketTransaction>readTransaction(it, TICKER_TYPE, "ticker"))
(it) ->
this.<TickerBinanceWebsocketTransaction>readTransaction(it, TICKER_TYPE, "ticker"))
.filter(
transaction ->
BinanceAdapters.adaptSymbol(
Expand All @@ -519,10 +531,18 @@ private Observable<BinanceTicker24h> rollingWindowStream(Instrument instrument,

private Observable<List<BinanceTicker24h>> allRollingWindowStream(KlineInterval windowSize) {
return this.service
.subscribeChannel("!" + BinanceSubscriptionType.TICKER_WINDOW.getType() + windowSize.code() + "@arr", new Object[0])
.subscribeChannel(
"!" + BinanceSubscriptionType.TICKER_WINDOW.getType() + windowSize.code() + "@arr",
new Object[0])
.map(
(it) -> this.<List<TickerBinanceWebsocketTransaction>>readTransaction(it, WINDOW_TICKER_TYPE , "ticker"))
.map( transaction -> transaction.getData().stream().map(TickerBinanceWebsocketTransaction::getTicker).collect(Collectors.toList()));
(it) ->
this.<List<TickerBinanceWebsocketTransaction>>readTransaction(
it, WINDOW_TICKER_TYPE, "ticker"))
.map(
transaction ->
transaction.getData().stream()
.map(TickerBinanceWebsocketTransaction::getTicker)
.collect(Collectors.toList()));
}

private Observable<BinanceBookTicker> rawBookTickerStream(Instrument instrument) {
Expand Down Expand Up @@ -768,7 +788,8 @@ private static JavaType getWindowTickerType() {
return getObjectMapper()
.getTypeFactory()
.constructType(
new TypeReference<BinanceWebsocketTransaction<List<TickerBinanceWebsocketTransaction>>>() {});
new TypeReference<
BinanceWebsocketTransaction<List<TickerBinanceWebsocketTransaction>>>() {});
}

private static JavaType getBookTickerType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ void spot_balances() {

TestObserver<Balance> testObserver = observable.test();

List<Balance> balances = testObserver
// .awaitDone(10, TimeUnit.MINUTES)
.awaitCount(1)
.values();
List<Balance> balances =
testObserver
// .awaitDone(10, TimeUnit.MINUTES)
.awaitCount(1)
.values();

testObserver.dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ void order_book() {

TestObserver<OrderBook> testObserver = observable.test();

OrderBook orderBook = testObserver
// .awaitDone(1, TimeUnit.MINUTES)
.awaitCount(1)
.values().get(0);
OrderBook orderBook =
testObserver
// .awaitDone(1, TimeUnit.MINUTES)
.awaitCount(1)
.values()
.get(0);

testObserver.dispose();

Expand All @@ -45,10 +47,12 @@ void trades() {

TestObserver<Trade> testObserver = observable.test();

Trade trade = testObserver
// .awaitDone(1, TimeUnit.MINUTES)
.awaitCount(1)
.values().get(0);
Trade trade =
testObserver
// .awaitDone(1, TimeUnit.MINUTES)
.awaitCount(1)
.values()
.get(0);

testObserver.dispose();

Expand All @@ -63,10 +67,12 @@ void ticker() {

TestObserver<Ticker> testObserver = observable.test();

Ticker ticker = testObserver
.awaitCount(1)
// .awaitDone(1, TimeUnit.MINUTES)
.values().get(0);
Ticker ticker =
testObserver
.awaitCount(1)
// .awaitDone(1, TimeUnit.MINUTES)
.values()
.get(0);

testObserver.dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ void user_trades_all() {

TestObserver<UserTrade> testObserver = observable.test();

List<UserTrade> userTrades = testObserver
// .awaitDone(10, TimeUnit.MINUTES)
.awaitCount(1)
.values();
List<UserTrade> userTrades =
testObserver
// .awaitDone(10, TimeUnit.MINUTES)
.awaitCount(1)
.values();

testObserver.dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,4 @@ public void pingPongDisconnectIfConnected() {
pingPongSubscription.dispose();
}
}
}
}
Loading

0 comments on commit 1e37e36

Please sign in to comment.