Skip to content

Commit

Permalink
Merge branch 'knowm-develop' into enforcer-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
bigscoop committed Aug 16, 2024
2 parents eb6d92f + 6db82a3 commit ba8347e
Show file tree
Hide file tree
Showing 27 changed files with 276 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package org.knowm.xchange.binance.dto.meta;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;

@Value
@Builder
@Jacksonized
public class BinanceSystemStatus {

// 0: normal,1:system maintenance
@JsonProperty private String status;
// normal or system maintenance
@JsonProperty private String msg;
@JsonProperty
String status;

public String getStatus() {
return status;
}
// normal or system maintenance
@JsonProperty
String msg;

public String getMsg() {
return msg;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.knowm.xchange.dto.marketdata.OrderBook;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.dto.marketdata.Trades;
import org.knowm.xchange.dto.meta.ExchangeHealth;
import org.knowm.xchange.dto.trade.LimitOrder;
import org.knowm.xchange.exceptions.ExchangeException;
import org.knowm.xchange.instrument.Instrument;
Expand All @@ -35,6 +36,20 @@ public BinanceMarketDataService(
super(exchange, resilienceRegistries);
}


@Override
public ExchangeHealth getExchangeHealth() {
try {
if (getSystemStatus().getStatus().equals("0")) {
return ExchangeHealth.ONLINE;
}
} catch (IOException e) {
return ExchangeHealth.OFFLINE;
}
return ExchangeHealth.OFFLINE;
}


/**
* optional parameters provided in the args array:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public List<FundingRecord> getFundingHistory(TradeHistoryParams params) {
@Override
public BinanceSystemStatus getSystemStatus() {
LOG.warn("getSystemStatus: {}", NOT_SUPPORTED);
return new BinanceSystemStatus();
return BinanceSystemStatus.builder().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.OrderBook;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.dto.meta.ExchangeHealth;
import org.knowm.xchange.instrument.Instrument;

public class MarketDataServiceIntegration extends BinanceExchangeIntegration {

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


@Test
public void valid_timestamp() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import jakarta.ws.rs.core.MediaType;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import org.knowm.xchange.bitstamp.dto.BitstampException;
import org.knowm.xchange.bitstamp.dto.BitstampTransferBalanceResponse;
import org.knowm.xchange.bitstamp.dto.account.BitstampBalance;
import org.knowm.xchange.bitstamp.dto.account.BitstampDepositAddress;
import org.knowm.xchange.bitstamp.dto.account.BitstampRippleDepositAddress;
import org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal;
import org.knowm.xchange.bitstamp.dto.account.DepositTransaction;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalFee;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest;
import org.knowm.xchange.bitstamp.dto.trade.BitstampCancelAllOrdersResponse;
import org.knowm.xchange.bitstamp.dto.trade.BitstampOrder;
Expand Down Expand Up @@ -646,7 +648,7 @@ BitstampTransferBalanceResponse transferSubAccountBalanceToMain(
@POST
@Path("withdrawal-requests/")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
WithdrawalRequest[] getWithdrawalRequests(
List<WithdrawalRequest> getWithdrawalRequests(
@HeaderParam("X-Auth") String apiKey,
@HeaderParam("X-Auth-Signature") ParamsDigest signer,
@HeaderParam("X-Auth-Nonce") SynchronizedValueFactory<String> nonce,
Expand All @@ -655,6 +657,16 @@ WithdrawalRequest[] getWithdrawalRequests(
@FormParam("timedelta") Long timeDelta)
throws BitstampException, IOException;

@POST
@Path("fees/withdrawal/")
List<WithdrawalFee> getWithdrawalFees(
@HeaderParam("X-Auth") String apiKey,
@HeaderParam("X-Auth-Signature") ParamsDigest signer,
@HeaderParam("X-Auth-Nonce") SynchronizedValueFactory<String> nonce,
@HeaderParam("X-Auth-Timestamp") SynchronizedValueFactory<String> timeStamp,
@HeaderParam("X-Auth-Version") String version)
throws BitstampException, IOException;

@POST
@Path("withdrawal/open/")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.knowm.xchange.bitstamp;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.knowm.xchange.BaseExchange;
Expand Down Expand Up @@ -68,8 +68,8 @@ public SynchronizedValueFactory<String> getTimestampFactory() {
public void remoteInit() throws IOException, ExchangeException {
BitstampMarketDataServiceRaw dataService =
(BitstampMarketDataServiceRaw) this.marketDataService;
BitstampPairInfo[] bitstampPairInfos = dataService.getTradingPairsInfo();
List<BitstampPairInfo> bitstampPairInfos = dataService.getTradingPairsInfo();
exchangeMetaData =
BitstampAdapters.adaptMetaData(Arrays.asList(bitstampPairInfos), exchangeMetaData);
BitstampAdapters.adaptMetaData(bitstampPairInfos, exchangeMetaData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ BitstampTransaction[] getTransactions(

@GET
@Path("trading-pairs-info/")
BitstampPairInfo[] getTradingPairsInfo() throws IOException, BitstampException;
List<BitstampPairInfo> getTradingPairsInfo() throws IOException, BitstampException;

class Pair {
public final CurrencyPair pair;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.knowm.xchange.bitstamp.dto.account;

import java.math.BigDecimal;
import lombok.Builder;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;
import org.knowm.xchange.currency.Currency;

@Jacksonized
@Value
@Builder
public class WithdrawalFee {

String network;

BigDecimal fee;

Currency currency;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.knowm.xchange.bitstamp.dto.account.BitstampRippleDepositAddress;
import org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal;
import org.knowm.xchange.bitstamp.dto.account.DepositTransaction;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalFee;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest;
import org.knowm.xchange.bitstamp.dto.trade.BitstampUserTransaction;
import org.knowm.xchange.client.ExchangeRestProxyBuilder;
Expand Down Expand Up @@ -349,16 +350,27 @@ public List<DepositTransaction> getUnconfirmedDeposits() throws IOException {
public List<WithdrawalRequest> getWithdrawalRequests(Long timeDelta) throws IOException {

try {
final List<WithdrawalRequest> response =
Arrays.asList(
bitstampAuthenticatedV2.getWithdrawalRequests(
return bitstampAuthenticatedV2.getWithdrawalRequests(
apiKeyForV2Requests,
signatureCreatorV2,
uuidNonceFactory,
timestampFactory,
API_VERSION,
timeDelta));
return response;
timeDelta);
} catch (BitstampException e) {
throw handleError(e);
}
}

public List<WithdrawalFee> getWithdrawalFees() throws IOException {

try {
return bitstampAuthenticatedV2.getWithdrawalFees(
apiKeyForV2Requests,
signatureCreatorV2,
uuidNonceFactory,
timestampFactory,
API_VERSION);
} catch (BitstampException e) {
throw handleError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public BitstampTransaction[] getTransactions(CurrencyPair pair, @Nullable Bitsta
}
}

public BitstampPairInfo[] getTradingPairsInfo() throws IOException {
public List<BitstampPairInfo> getTradingPairsInfo() throws IOException {
try {
return bitstampV2.getTradingPairsInfo();
} catch (BitstampException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.knowm.xchange.bitstamp.dto.account;

import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List;
import org.junit.Test;

public class WithdrawalFeesJSONTest {

@Test
public void testUnmarshal() throws IOException {

// Read in the JSON from the example resources
InputStream is =
WithdrawalFeesJSONTest.class.getResourceAsStream(
"/org/knowm/xchange/bitstamp/dto/account/withdrawal-fees.json");

// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();

List<WithdrawalFee> withdrawalFees =
mapper.readValue(
is,
mapper.getTypeFactory().constructCollectionType(List.class, WithdrawalFee.class));

assertThat(withdrawalFees.size()).isEqualTo(1);
assertThat(withdrawalFees.get(0).getNetwork()).isEqualTo("bitcoin");
assertThat(withdrawalFees.get(0).getCurrency().getCurrencyCode()).isEqualToIgnoringCase("btc");
assertThat(withdrawalFees.get(0).getFee()).isEqualTo(new BigDecimal("0.00015000"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"currency": "btc",
"fee": "0.00015000",
"network": "bitcoin"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@

public class BybitAdapters {

private static final SimpleDateFormat OPTION_DATE_FORMAT = new SimpleDateFormat("ddMMMyy", Locale.US);
private static final ThreadLocal<SimpleDateFormat> OPTION_DATE_FORMAT = ThreadLocal.withInitial(
() -> new SimpleDateFormat("ddMMMyy"));
public static final List<String> QUOTE_CURRENCIES = Arrays.asList("USDT", "USDC", "EUR", "BTC", "ETH", "DAI", "BRZ");

public static Wallet adaptBybitBalances(List<BybitCoinWalletBalance> coinWalletBalances) {
Expand Down Expand Up @@ -133,7 +134,7 @@ public static String convertToBybitSymbol(Instrument instrument) {
return String.format(
"%s-%s-%s-%s",
optionsContract.getBase(),
OPTION_DATE_FORMAT.format(optionsContract.getExpireDate()),
OPTION_DATE_FORMAT.get().format(optionsContract.getExpireDate()),
optionsContract.getStrike(),
optionsContract.getType().equals(OptionsContract.OptionType.PUT) ? "P" : "C")
.toUpperCase();
Expand Down Expand Up @@ -191,7 +192,7 @@ public static Instrument adaptInstrumentInfo(BybitInstrumentInfo instrumentInfo)
return new OptionsContract.Builder()
.currencyPair(
new CurrencyPair(instrumentInfo.getBaseCoin(), instrumentInfo.getQuoteCoin()))
.expireDate(OPTION_DATE_FORMAT.parse(expireDateString))
.expireDate(OPTION_DATE_FORMAT.get().parse(expireDateString))
.strike(strike)
.type(
optionInstrumentInfo.getOptionsType().equals(OptionType.CALL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.knowm.xchange.bybit.BybitAdapters;
import org.knowm.xchange.bybit.BybitExchange;
import org.knowm.xchange.bybit.dto.BybitCategory;
Expand Down Expand Up @@ -65,11 +64,19 @@ public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOExce

@Override
public List<Ticker> getTickers(Params params) throws IOException {
if (!(params instanceof BybitCategory)) {
// get category
BybitCategory category;
if (params == null) {
category = BybitCategory.SPOT;
}
else if (!(params instanceof BybitCategory)) {
throw new IllegalArgumentException("Params must be instance of BybitCategory");
}
BybitCategory category = (BybitCategory) params;
if (category.equals(BybitCategory.OPTION)) {
else {
category = (BybitCategory) params;
}

if (category == BybitCategory.OPTION) {
throw new NotYetImplementedForExchangeException("category OPTION not yet implemented");
}
BybitResult<BybitTickers<BybitTicker>> response = getTickers(category);
Expand Down
4 changes: 2 additions & 2 deletions xchange-bybit/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


<!-- Define logging for organization applications only -->
<logger name="org.knowm.xchange" level="DEBUG"/>
<logger name="si.mazi.rescu" level="TRACE"/>
<!-- <logger name="org.knowm.xchange" level="DEBUG"/>-->
<!-- <logger name="si.mazi.rescu" level="TRACE"/>-->

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.knowm.xchange.dto.meta;

public enum ExchangeHealth {
ONLINE,
OFFLINE,

/**
* Can only cancel the order but not place order
*/
CANCEL_ONLY;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
import java.util.List;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.*;
import org.knowm.xchange.dto.marketdata.CandleStickData;
import org.knowm.xchange.dto.marketdata.FundingRate;
import org.knowm.xchange.dto.marketdata.FundingRates;
import org.knowm.xchange.dto.marketdata.OrderBook;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.dto.marketdata.Trades;
import org.knowm.xchange.dto.meta.ExchangeHealth;
import org.knowm.xchange.exceptions.ExchangeException;
import org.knowm.xchange.exceptions.NotAvailableFromExchangeException;
import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException;
Expand All @@ -25,6 +31,15 @@
*/
public interface MarketDataService extends BaseService {

/**
* Get exchange health
*
* @return The exchange health
*/
default ExchangeHealth getExchangeHealth() {
return ExchangeHealth.ONLINE;
}

/**
* Get a ticker representing the current exchange rate
*
Expand Down
Loading

0 comments on commit ba8347e

Please sign in to comment.