Search in sources :

Example 1 with KrakenFee

use of org.knowm.xchange.kraken.dto.marketdata.KrakenFee in project XChange by knowm.

the class KrakenAdaptersTest method testAdaptFeeTiers1.

@Test
public void testAdaptFeeTiers1() {
    List<KrakenFee> krakenMakerFees = new ArrayList<KrakenFee>();
    List<KrakenFee> krakenTakerFees = new ArrayList<KrakenFee>();
    krakenMakerFees.add(new KrakenFee(BigDecimal.TEN, BigDecimal.ONE));
    krakenTakerFees.add(new KrakenFee(BigDecimal.TEN, new BigDecimal(2)));
    krakenMakerFees.add(new KrakenFee(new BigDecimal(45), new BigDecimal(0.5)));
    krakenTakerFees.add(new KrakenFee(new BigDecimal(30), new BigDecimal(0.75)));
    FeeTier[] adaptedFeeTiers = KrakenAdapters.adaptFeeTiers(krakenMakerFees, krakenTakerFees);
    assertThat(adaptedFeeTiers.length).isEqualTo(3);
    assertThat(adaptedFeeTiers[0].beginQuantity).isEqualByComparingTo(BigDecimal.TEN);
    assertThat(adaptedFeeTiers[0].fee.getMakerFee()).isEqualByComparingTo(BigDecimal.ONE.movePointLeft(2));
    assertThat(adaptedFeeTiers[0].fee.getTakerFee()).isEqualByComparingTo(new BigDecimal(2).movePointLeft(2));
    assertThat(adaptedFeeTiers[1].beginQuantity).isEqualByComparingTo(new BigDecimal(30));
    assertThat(adaptedFeeTiers[1].fee.getMakerFee()).isEqualByComparingTo(BigDecimal.ONE.movePointLeft(2));
    assertThat(adaptedFeeTiers[1].fee.getTakerFee()).isEqualByComparingTo(new BigDecimal(0.75).movePointLeft(2));
    assertThat(adaptedFeeTiers[2].beginQuantity).isEqualByComparingTo(new BigDecimal(45));
    assertThat(adaptedFeeTiers[2].fee.getMakerFee()).isEqualByComparingTo(new BigDecimal(0.5).movePointLeft(2));
    assertThat(adaptedFeeTiers[2].fee.getTakerFee()).isEqualByComparingTo(new BigDecimal(0.75).movePointLeft(2));
}
Also used : ArrayList(java.util.ArrayList) KrakenFee(org.knowm.xchange.kraken.dto.marketdata.KrakenFee) FeeTier(org.knowm.xchange.dto.meta.FeeTier) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with KrakenFee

use of org.knowm.xchange.kraken.dto.marketdata.KrakenFee in project XChange by knowm.

the class KrakenAdapters method adaptFeeTiers.

protected static FeeTier[] adaptFeeTiers(List<KrakenFee> makerFees, List<KrakenFee> takerFees) {
    Collections.sort(makerFees);
    Collections.sort(takerFees);
    List<FeeTier> resultFeeTiers = new ArrayList<FeeTier>();
    int makerFeeIdx = 0;
    int takerFeeIdx = 0;
    while (makerFeeIdx < makerFees.size() || takerFeeIdx < takerFees.size()) {
        int curMakerIdx = Math.min(makerFeeIdx, makerFees.size() - 1);
        int curTakerIdx = Math.min(takerFeeIdx, takerFees.size() - 1);
        BigDecimal quantityMaker = makerFees.get(curMakerIdx).getVolume();
        BigDecimal quantityTaker = takerFees.get(curTakerIdx).getVolume();
        BigDecimal resultQuantity = null;
        BigDecimal resultMakerFee = null;
        BigDecimal resultTakerFee = null;
        int makerVolCompTakerVol = quantityMaker.compareTo(quantityTaker);
        if ((makerVolCompTakerVol > 0 || makerFeeIdx >= makerFees.size()) && takerFeeIdx < takerFees.size()) {
            if (makerFeeIdx < 1) {
                throw new IllegalStateException("Kraken exchange specified fee tiers such that the maker fee was unspecified before a nonzero quantity was traded.");
            }
            KrakenFee takerFeeData = takerFees.get(curTakerIdx);
            resultTakerFee = takerFeeData.getPercentFee();
            resultMakerFee = makerFees.get(makerFeeIdx - 1).getPercentFee();
            resultQuantity = takerFeeData.getVolume();
            takerFeeIdx++;
        } else if ((makerVolCompTakerVol < 0 || takerFeeIdx >= takerFees.size()) && makerFeeIdx < makerFees.size()) {
            if (takerFeeIdx < 1) {
                throw new IllegalStateException("Kraken exchange specified fee tiers such that the taker fee was unspecified before a nonzero quantity was traded.");
            }
            KrakenFee makerFeeData = makerFees.get(curMakerIdx);
            resultMakerFee = makerFeeData.getPercentFee();
            resultTakerFee = takerFees.get(takerFeeIdx - 1).getPercentFee();
            resultQuantity = makerFeeData.getVolume();
            makerFeeIdx++;
        } else {
            // makerVolCompTakerVol == 0 && makerFeeIdx < makerFees.size() && takerFeeIdx <
            // takerFees.size()
            KrakenFee makerFeeData = makerFees.get(curMakerIdx);
            resultMakerFee = makerFeeData.getPercentFee();
            resultTakerFee = takerFees.get(curTakerIdx).getPercentFee();
            resultQuantity = makerFeeData.getVolume();
            takerFeeIdx++;
            makerFeeIdx++;
        }
        resultFeeTiers.add(new FeeTier(resultQuantity, new Fee(resultMakerFee.movePointLeft(2), resultTakerFee.movePointLeft(2))));
    }
    return resultFeeTiers.toArray(new FeeTier[resultFeeTiers.size()]);
}
Also used : KrakenFee(org.knowm.xchange.kraken.dto.marketdata.KrakenFee) KrakenVolumeFee(org.knowm.xchange.kraken.dto.account.KrakenVolumeFee) Fee(org.knowm.xchange.dto.account.Fee) ArrayList(java.util.ArrayList) KrakenFee(org.knowm.xchange.kraken.dto.marketdata.KrakenFee) FeeTier(org.knowm.xchange.dto.meta.FeeTier) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 FeeTier (org.knowm.xchange.dto.meta.FeeTier)2 KrakenFee (org.knowm.xchange.kraken.dto.marketdata.KrakenFee)2 Test (org.junit.Test)1 Fee (org.knowm.xchange.dto.account.Fee)1 KrakenVolumeFee (org.knowm.xchange.kraken.dto.account.KrakenVolumeFee)1