Skip to content

Commit

Permalink
[general] Encapsulate fields in CurrencyPair
Browse files Browse the repository at this point in the history
  • Loading branch information
bigscoop committed Feb 19, 2025
1 parent 3290996 commit e18ff59
Show file tree
Hide file tree
Showing 150 changed files with 520 additions and 450 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public static String toSymbol(Instrument pair, Boolean isInverse) {
symbol = ((OptionsContract) pair).getCurrencyPair().toString().replace("/", "");
} else {
symbol =
((CurrencyPair) pair).base.getCurrencyCode()
+ ((CurrencyPair) pair).counter.getCurrencyCode();
((CurrencyPair) pair).getBase().getCurrencyCode()
+ ((CurrencyPair) pair).getCounter().getCurrencyCode();
}
return symbol;
}
Expand Down Expand Up @@ -585,13 +585,13 @@ public static ExchangeMetaData adaptExchangeMetaData(
.amountStepSize(stepSize)
.marketOrderEnabled(Arrays.asList(symbol.getOrderTypes()).contains("MARKET"))
.build());
Currency baseCurrency = currentCurrencyPair.base;
Currency baseCurrency = currentCurrencyPair.getBase();
CurrencyMetaData baseCurrencyMetaData =
BinanceAdapters.adaptCurrencyMetaData(
currencies, baseCurrency, assetDetailMap, basePrecision);
currencies.put(baseCurrency, baseCurrencyMetaData);

Currency counterCurrency = currentCurrencyPair.counter;
Currency counterCurrency = currentCurrencyPair.getCounter();
CurrencyMetaData counterCurrencyMetaData =
BinanceAdapters.adaptCurrencyMetaData(
currencies, counterCurrency, assetDetailMap, counterPrecision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ protected BitbayMarketDataServiceRaw(Exchange exchange) {
public BitbayTicker getBitbayTicker(CurrencyPair currencyPair) throws IOException {

return bitbay.getBitbayTicker(
currencyPair.base.getCurrencyCode().toUpperCase() + currencyPair.counter.getCurrencyCode());
currencyPair.getBase().getCurrencyCode().toUpperCase() + currencyPair.getCounter().getCurrencyCode());
}

public BitbayOrderBook getBitbayOrderBook(CurrencyPair currencyPair) throws IOException {

return bitbay.getBitbayOrderBook(
currencyPair.base.getCurrencyCode().toUpperCase() + currencyPair.counter.getCurrencyCode());
currencyPair.getBase().getCurrencyCode().toUpperCase() + currencyPair.getCounter().getCurrencyCode());
}

public BitbayTrade[] getBitbayTrades(CurrencyPair currencyPair, Object[] args)
Expand All @@ -49,7 +49,7 @@ public BitbayTrade[] getBitbayTrades(CurrencyPair currencyPair, Object[] args)
limit = ((Number) args[2]).intValue();
}
return bitbay.getBitbayTrades(
currencyPair.base.getCurrencyCode().toUpperCase() + currencyPair.counter.getCurrencyCode(),
currencyPair.getBase().getCurrencyCode().toUpperCase() + currencyPair.getCounter().getCurrencyCode(),
since,
sort,
limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public List<Map> getBitbayTransactions(CurrencyPair currencyPair)
exchange.getNonceFactory(),
currencyPair == null
? null
: currencyPair.base.toString() + "-" + currencyPair.counter.toString());
: currencyPair.getBase().toString() + "-" + currencyPair.getCounter().toString());
}

public BitbayTradeResponse placeBitbayOrder(LimitOrder order) throws IOException {
String currency = order.getCurrencyPair().base.toString();
String paymentCurrency = order.getCurrencyPair().counter.toString();
String currency = order.getCurrencyPair().getBase().toString();
String paymentCurrency = order.getCurrencyPair().getCounter().toString();
String type = order.getType() == Order.OrderType.ASK ? "ask" : "bid";

BitbayTradeResponse response =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public static UserTrades adaptUserTrades(BitbayUserTrades response) {
.price(trade.getRate())
.timestamp(timestamp)
.feeAmount(trade.getCommissionValue())
.feeCurrency(trade.getCommissionValue() == null ? null : pair.base)
.feeCurrency(trade.getCommissionValue() == null ? null : pair.getBase())
.build());
}
return new UserTrades(
trades, 0L, Trades.TradeSortType.SortByTimestamp, response.getNextPageCursor());
}

public static String adaptCurrencyPair(CurrencyPair currencyPair) {
return currencyPair.base + "-" + currencyPair.counter;
return currencyPair.getBase() + "-" + currencyPair.getCounter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOExce
// Request data
BitcoinAverageTicker bitcoinAverageTicker =
getBitcoinAverageTicker(
currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode());
currencyPair.getBase().getCurrencyCode(), currencyPair.getCounter().getCurrencyCode());

// Adapt to XChange DTOs
return BitcoinAverageAdapters.adaptTicker(bitcoinAverageTicker, currencyPair);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class BitcoindeUtils {
private BitcoindeUtils() {}

public static String createBitcoindePair(CurrencyPair currencyPair) {
return createBitcoindeCurrency(currencyPair.base)
+ createBitcoindeCurrency(currencyPair.counter);
return createBitcoindeCurrency(currencyPair.getBase())
+ createBitcoindeCurrency(currencyPair.getCounter());
}

public static String createBitcoindeCurrency(Currency currency) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public BitcoindeIdResponse bitcoindeCancelOrders(String order_id, CurrencyPair c
throws IOException {
try {
String currPair =
currencyPair.base.getCurrencyCode() + currencyPair.counter.getCurrencyCode();
currencyPair.getBase().getCurrencyCode() + currencyPair.getCounter().getCurrencyCode();
return bitcoinde.deleteOrder(apiKey, nonceFactory, signatureCreator, order_id, currPair);
} catch (BitcoindeException e) {
throw handleError(e);
Expand All @@ -44,8 +44,8 @@ public BitcoindeIdResponse bitcoindePlaceLimitOrder(LimitOrder l) throws IOExcep
try {
String side = l.getType().equals(OrderType.ASK) ? "sell" : "buy";
String bitcoindeCurrencyPair =
l.getCurrencyPair().base.getCurrencyCode()
+ l.getCurrencyPair().counter.getCurrencyCode();
l.getCurrencyPair().getBase().getCurrencyCode()
+ l.getCurrencyPair().getCounter().getCurrencyCode();
return bitcoinde.createOrder(
apiKey,
nonceFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ public static UserTrades adaptTradeHistory(
Currency feeCurrency;
if (trade.getType() == BitcoindeType.BUY) {
fee = trade.getFeeCurrencyToTrade();
feeCurrency = trade.getTradingPair().base;
feeCurrency = trade.getTradingPair().getBase();
} else if (trade.getType() == BitcoindeType.SELL) {
fee = trade.getFeeCurrencyToPay();
feeCurrency = trade.getTradingPair().counter;
feeCurrency = trade.getTradingPair().getCounter();
} else {
throw new TypeNotPresentException(trade.getType().toString(), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ BitcointoyouPublicTrade[] getBitcointoyouPublicTrades(CurrencyPair currencyPair)
BitcointoyouPublicTrade[] getBitcointoyouPublicTrades(
CurrencyPair currencyPair, Long tradeTimestamp, Long minTradeId) throws IOException {

String currency = currencyPair.base.toString();
String currency = currencyPair.getBase().toString();

try {
return bitcointoyou.getTrades(currency, tradeTimestamp, minTradeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public BitcointoyouOrderResponse sell(LimitOrder limitOrder) throws IOException
private BitcointoyouOrderResponse createOrder(String action, LimitOrder limitOrder)
throws IOException {
try {
String asset = limitOrder.getCurrencyPair().base.getSymbol();
String asset = limitOrder.getCurrencyPair().getBase().getSymbol();
return bitcointoyouAuthenticated.createOrder(
apiKey,
exchange.getNonceFactory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public ExchangeMetaData adaptMetaData(
// Remove currencies that are no-longer in use
Set<Currency> currencies =
currencyPairs.stream()
.flatMap(pair -> Stream.of(pair.base, pair.counter))
.flatMap(pair -> Stream.of(pair.getBase(), pair.getCounter()))
.collect(Collectors.toSet());
currenciesMap.keySet().retainAll(currencies);

Expand All @@ -653,16 +653,16 @@ public ExchangeMetaData adaptMetaData(
pairsMap.put(c, null);
}

if (!currenciesMap.containsKey(c.base)) {
if (!currenciesMap.containsKey(c.getBase())) {
currenciesMap.put(
c.base,
c.getBase(),
new CurrencyMetaData(
2,
null)); // When missing, add default meta-data with scale of 2 (Bitfinex's minimal
// scale)
}
if (!currenciesMap.containsKey(c.counter)) {
currenciesMap.put(c.counter, new CurrencyMetaData(2, null));
if (!currenciesMap.containsKey(c.getCounter())) {
currenciesMap.put(c.getCounter(), new CurrencyMetaData(2, null));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ public BitflyerMarketDataService(Exchange exchange) {

@Override
public Ticker getTicker(CurrencyPair currencyPair, Object... args) throws IOException {
BitflyerTicker ticker = getTicker(currencyPair.base + "_" + currencyPair.counter);
BitflyerTicker ticker = getTicker(currencyPair.getBase() + "_" + currencyPair.getCounter());
return BitflyerAdapters.adaptTicker(ticker, currencyPair);
}

@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {
BitflyerOrderbook orderbook = getOrderbook(currencyPair.base + "_" + currencyPair.counter);
BitflyerOrderbook orderbook = getOrderbook(
currencyPair.getBase() + "_" + currencyPair.getCounter());
List<LimitOrder> bids =
orderbook.getBids().stream()
.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private static UserTrade adaptUserTrade(
.originalAmount(bithumbTransaction.getUnits())
.type(adaptTransactionSearch(bithumbTransaction.getSearch()))
.feeAmount(bithumbTransaction.getFee())
.feeCurrency(currencyPair.counter)
.feeCurrency(currencyPair.getCounter())
.price(bithumbTransaction.getPrice())
.timestamp(new Date(bithumbTransaction.getTransferDate() / 1000L))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private BithumbUtils() {

public static String getBaseCurrency(@Nullable CurrencyPair currencyPair) {
return Optional.ofNullable(currencyPair)
.map(c -> c.base)
.map(c -> c.getBase())
.map(Currency::getCurrencyCode)
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static UserTrades adaptTradeHistory(BitsoUserTransaction[] bitsoUserTrans
final CurrencyPair currencyPair = new CurrencyPair(Currency.BTC, Currency.MXN);

String feeCurrency =
sell ? currencyPair.counter.getCurrencyCode() : currencyPair.base.getCurrencyCode();
sell ? currencyPair.getCounter().getCurrencyCode() : currencyPair.getBase().getCurrencyCode();
UserTrade trade =
UserTrade.builder()
.type(orderType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public BitsoTransaction[] getBitsoTransactions(Object... args) throws IOExceptio
}

public BitsoTicker getBitsoTicker(CurrencyPair pair) throws IOException {
return bitso.getTicker(pair.base + "_" + pair.counter);
return bitso.getTicker(pair.getBase() + "_" + pair.getCounter());
}

public enum BitsoTime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private static CurrencyPair adaptCurrencyPair(
private static BigDecimal getBaseCurrencyAmountFromBitstampTransaction(
BitstampOrderTransaction bitstampTransaction, CurrencyPair currencyPair) {

return bitstampTransaction.getAmount(currencyPair.base.getCurrencyCode().toLowerCase());
return bitstampTransaction.getAmount(currencyPair.getBase().getCurrencyCode().toLowerCase());
}

public static Order.OrderStatus adaptOrderStatus(BitstampOrderStatus bitstampOrderStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public String toString() {
? ""
: String.format(
"%s%s",
pair.base.getCurrencyCode().toLowerCase(),
pair.counter.getCurrencyCode().toLowerCase());
pair.getBase().getCurrencyCode().toLowerCase(),
pair.getCounter().getCurrencyCode().toLowerCase());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static List<UserTrade> adaptUserTrades(List<BittrexOrder> bittrexUserTrad
.id(bittrexOrder.getId())
.feeAmount(bittrexOrder.getCommission())
.feeCurrency(
BittrexUtils.toCurrencyPair(bittrexOrder.getMarketSymbol()).counter)
BittrexUtils.toCurrencyPair(bittrexOrder.getMarketSymbol()).getCounter())
.build())
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void testAdaptUserTrades() {
Assert.assertEquals(order1.getClosedAt(), trade1.getTimestamp());
Assert.assertEquals(order1.getId(), trade1.getId());
Assert.assertEquals(order1.getCommission(), trade1.getFeeAmount());
Assert.assertEquals(pair.counter, trade1.getFeeCurrency());
Assert.assertEquals(pair.getCounter(), trade1.getFeeCurrency());

UserTrade trade2 = tradesList.get(1);
Assert.assertEquals(Order.OrderType.ASK, trade2.getType());
Expand All @@ -226,6 +226,6 @@ public void testAdaptUserTrades() {
Assert.assertEquals(order2.getClosedAt(), trade2.getTimestamp());
Assert.assertEquals(order2.getId(), trade2.getId());
Assert.assertEquals(order2.getCommission(), trade2.getFeeAmount());
Assert.assertEquals(pair.counter, trade2.getFeeCurrency());
Assert.assertEquals(pair.getCounter(), trade2.getFeeCurrency());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static UserTrade adaptTrade(BityOrder order) {
.id(orderId)
.orderId(orderId)
.feeAmount(fee)
.feeCurrency(currencyPair.counter)
.feeCurrency(currencyPair.getCounter())
.build();
}

Expand All @@ -81,11 +81,11 @@ public static ExchangeMetaData adaptMetaData(
if (!pairsMap.containsKey(c)) {
pairsMap.put(c, null);
}
if (!currenciesMap.containsKey(c.base)) {
currenciesMap.put(c.base, null);
if (!currenciesMap.containsKey(c.getBase())) {
currenciesMap.put(c.getBase(), null);
}
if (!currenciesMap.containsKey(c.counter)) {
currenciesMap.put(c.counter, null);
if (!currenciesMap.containsKey(c.getCounter())) {
currenciesMap.put(c.getCounter(), null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class BitZUtils {
public static String toPairString(CurrencyPair currency) {
return String.format(
"%s_%s",
currency.base.getCurrencyCode().toLowerCase(),
currency.counter.getCurrencyCode().toLowerCase());
currency.getBase().getCurrencyCode().toLowerCase(),
currency.getCounter().getCurrencyCode().toLowerCase());
}

public static CurrencyPair toCurrencyPair(String pairstring) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Map<Currency, Map<Currency, BigDecimal>> getCoinRate(CurrencyPair... curr
List<String> coinList = new ArrayList<>(currencyPairs.length);
Arrays.stream(currencyPairs)
.forEach(
currencyPair -> coinList.add(currencyPair.counter.getCurrencyCode().toLowerCase()));
currencyPair -> coinList.add(currencyPair.getCounter().getCurrencyCode().toLowerCase()));
String coins = coinList.stream().collect(Collectors.joining(","));
return bitz.getCurrencyCoinRate(coins).getData();
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public Map<Currency, Map<Currency, BigDecimal>> getCurrencyCoinRate(CurrencyPair
throws IOException {
List<String> coinList = new ArrayList<>(currencyPairs.length);
Arrays.stream(currencyPairs)
.forEach(currencyPair -> coinList.add(currencyPair.base.getCurrencyCode().toLowerCase()));
.forEach(currencyPair -> coinList.add(currencyPair.getBase().getCurrencyCode().toLowerCase()));
String coins = coinList.stream().collect(Collectors.joining(","));
return bitz.getCurrencyCoinRate(coins).getData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static final long toEuroshi(BigDecimal bd) {
}

public static String toPairString(CurrencyPair currencyPair) {
return currencyPair.base.getCurrencyCode() + currencyPair.counter.getCurrencyCode();
return currencyPair.getBase().getCurrencyCode() + currencyPair.getCounter().getCurrencyCode();
}

public static Order.OrderType fromBl3pOrderType(String bl3pType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public final class BleutradeUtils {

public static String toPairString(CurrencyPair currencyPair) {

return currencyPair.base.getCurrencyCode().toUpperCase()
return currencyPair.getBase().getCurrencyCode().toUpperCase()
+ "_"
+ currencyPair.counter.getCurrencyCode().toUpperCase();
+ currencyPair.getCounter().getCurrencyCode().toUpperCase();
}

public static CurrencyPair toCurrencyPair(String pairString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public BleutradeTradeServiceRaw(Exchange exchange, IRestProxyFactory restProxyFa
}

private static String toMarket(CurrencyPair currencyPair) {
return currencyPair.base + "_" + currencyPair.counter;
return currencyPair.getBase() + "_" + currencyPair.getCounter();
}

public String buyLimit(LimitOrder limitOrder) throws IOException {
Expand Down
Loading

0 comments on commit e18ff59

Please sign in to comment.