use of org.knowm.xchange.dto.account.Fee in project XChange by knowm.
the class BinanceAccountService method getDynamicTradingFees.
@Override
public Map<CurrencyPair, Fee> getDynamicTradingFees() throws IOException {
try {
BinanceAccountInformation acc = account();
BigDecimal makerFee = acc.makerCommission.divide(new BigDecimal("10000"), 4, RoundingMode.UNNECESSARY);
BigDecimal takerFee = acc.takerCommission.divide(new BigDecimal("10000"), 4, RoundingMode.UNNECESSARY);
Map<CurrencyPair, Fee> tradingFees = new HashMap<>();
List<CurrencyPair> pairs = exchange.getExchangeSymbols();
pairs.forEach(pair -> tradingFees.put(pair, new Fee(makerFee, takerFee)));
return tradingFees;
} catch (BinanceException e) {
throw BinanceErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.dto.account.Fee in project XChange by knowm.
the class BittrexAccountService method getDynamicTradingFees.
@Override
public Map<CurrencyPair, Fee> getDynamicTradingFees() throws IOException {
try {
Map<CurrencyPair, Fee> result = new HashMap<>();
List<BittrexComissionRatesWithMarket> tradingFees = getTradingFees();
for (BittrexComissionRatesWithMarket tradingFee : tradingFees) {
result.put(BittrexUtils.toCurrencyPair(tradingFee.getMarketSymbol()), new Fee(BigDecimal.valueOf(tradingFee.getMakerRate()), BigDecimal.valueOf(tradingFee.getTakerRate())));
}
return result;
} catch (BittrexException e) {
throw BittrexErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.dto.account.Fee in project XChange by knowm.
the class GeminiAdaptersTest method testAdaptDynamicTradingFees.
@Test
public void testAdaptDynamicTradingFees() throws IOException {
// Read in the JSON from the example resources
InputStream is = GeminiAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/account/example-notionalvolume.json");
// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();
GeminiTrailingVolumeResponse trailingVolumeResp = mapper.readValue(is, GeminiTrailingVolumeResponse.class);
List<CurrencyPair> fakeSupportedCurrencyPairs = new ArrayList<CurrencyPair>(Arrays.asList(CurrencyPair.BTC_USD, CurrencyPair.BTC_LTC, CurrencyPair.LTC_XRP));
Map<CurrencyPair, Fee> dynamicFees = GeminiAdapters.AdaptDynamicTradingFees(trailingVolumeResp, fakeSupportedCurrencyPairs);
assertThat(dynamicFees.size()).isEqualTo(fakeSupportedCurrencyPairs.size());
for (CurrencyPair pair : fakeSupportedCurrencyPairs) {
assertThat(dynamicFees.get(pair).getMakerFee()).isEqualTo(new BigDecimal("0.0035"));
assertThat(dynamicFees.get(pair).getTakerFee()).isEqualTo(new BigDecimal("0.0010"));
}
}
use of org.knowm.xchange.dto.account.Fee in project XChange by knowm.
the class CoinbaseProAccountService method getDynamicTradingFees.
@Override
public Map<CurrencyPair, Fee> getDynamicTradingFees() throws IOException {
CoinbaseProFee fees = getCoinbaseProFees();
Map<CurrencyPair, Fee> tradingFees = new HashMap<>();
List<CurrencyPair> pairs = exchange.getExchangeSymbols();
pairs.forEach(pair -> tradingFees.put(pair, new Fee(fees.getMakerRate(), fees.getTakerRate())));
return tradingFees;
}
use of org.knowm.xchange.dto.account.Fee in project XChange by knowm.
the class BitfinexAdapters method adaptDynamicTradingFees.
/**
* Each element in the response array contains a set of currencies that are at a given fee tier.
* The API returns the fee per currency in each tier and does not make any promises that they are
* all the same, so this adapter will use the fee per currency instead of the fee per tier.
*/
public static Map<CurrencyPair, Fee> adaptDynamicTradingFees(BitfinexTradingFeeResponse[] responses, List<CurrencyPair> currencyPairs) {
Map<CurrencyPair, Fee> result = new HashMap<>();
for (BitfinexTradingFeeResponse response : responses) {
BitfinexTradingFeeResponse.BitfinexTradingFeeResponseRow[] responseRows = response.getTradingFees();
for (BitfinexTradingFeeResponse.BitfinexTradingFeeResponseRow responseRow : responseRows) {
Currency currency = Currency.getInstance(responseRow.getCurrency());
BigDecimal percentToFraction = BigDecimal.ONE.divide(BigDecimal.ONE.scaleByPowerOfTen(2));
Fee fee = new Fee(responseRow.getMakerFee().multiply(percentToFraction), responseRow.getTakerFee().multiply(percentToFraction));
for (CurrencyPair pair : currencyPairs) {
// Fee is typically assessed in units counter.
if (pair.base.equals(currency)) {
if (result.put(pair, fee) != null) {
throw new IllegalStateException("Fee for currency pair " + pair + " is overspecified");
}
}
}
}
}
return result;
}
Aggregations