Search in sources :

Example 1 with Fee

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);
    }
}
Also used : BinanceException(org.knowm.xchange.binance.dto.BinanceException) HashMap(java.util.HashMap) Fee(org.knowm.xchange.dto.account.Fee) BinanceAccountInformation(org.knowm.xchange.binance.dto.account.BinanceAccountInformation) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with Fee

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);
    }
}
Also used : HashMap(java.util.HashMap) BittrexComissionRatesWithMarket(org.knowm.xchange.bittrex.dto.account.BittrexComissionRatesWithMarket) Fee(org.knowm.xchange.dto.account.Fee) BittrexException(org.knowm.xchange.bittrex.dto.BittrexException) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with Fee

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"));
    }
}
Also used : GeminiTrailingVolumeResponse(org.knowm.xchange.gemini.v1.dto.account.GeminiTrailingVolumeResponse) InputStream(java.io.InputStream) Fee(org.knowm.xchange.dto.account.Fee) ArrayList(java.util.ArrayList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Example 4 with Fee

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;
}
Also used : HashMap(java.util.HashMap) CoinbaseProFee(org.knowm.xchange.coinbasepro.dto.account.CoinbaseProFee) Fee(org.knowm.xchange.dto.account.Fee) CoinbaseProFee(org.knowm.xchange.coinbasepro.dto.account.CoinbaseProFee) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 5 with Fee

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;
}
Also used : HashMap(java.util.HashMap) Fee(org.knowm.xchange.dto.account.Fee) Currency(org.knowm.xchange.currency.Currency) BitfinexTickerFundingCurrency(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerFundingCurrency) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) BitfinexTradingFeeResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexTradingFeeResponse)

Aggregations

Fee (org.knowm.xchange.dto.account.Fee)16 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)15 BigDecimal (java.math.BigDecimal)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)5 Currency (org.knowm.xchange.currency.Currency)4 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)4 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)4 FeeTier (org.knowm.xchange.dto.meta.FeeTier)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 KrakenFee (org.knowm.xchange.kraken.dto.marketdata.KrakenFee)3 IOException (java.io.IOException)2 BitfinexTradingFeeResponse (org.knowm.xchange.bitfinex.v1.dto.account.BitfinexTradingFeeResponse)2 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)2 KrakenVolumeFee (org.knowm.xchange.kraken.dto.account.KrakenVolumeFee)2 Hashtable (java.util.Hashtable)1 BinanceException (org.knowm.xchange.binance.dto.BinanceException)1 BinanceAccountInformation (org.knowm.xchange.binance.dto.account.BinanceAccountInformation)1