@Test void beforeGain() { OrderBook book = OrderBook.builder().bestSell(1.0).build(); nnHitbtc.setFuturePriceGainPct(new BigDecimal("1")); FeeFitted fitted = fitter.before(book, hitbtc); assertThat(fitted.getSellPrice()).isEqualByComparingTo("1.012024"); assertThat(fitted.getBuyPrice()).isEqualByComparingTo("1"); assertThat(fitted.getSellAmount()).isEqualByComparingTo("1"); assertThat(fitted.getBuyAmount()).isEqualByComparingTo("1"); assertThat(fitted.getAmount()).isEqualByComparingTo("1"); assertThat(fitted.getProfitFrom()).isEqualByComparingTo("0"); assertThat(fitted.getProfitTo()).isEqualByComparingTo("0.010010975"); }
@Override public FeeFitted before(OrderBook book, ClientConfig config) { BigDecimal priceWeBuy = Util.ceilPrice(config, book.getBestSell()); BigDecimal amount = Util.calculateAmount(config, priceWeBuy); double charge = Util.computeCharge(config); BigDecimal priceWeSell = Util.ceilPrice(config, priceWeBuy.doubleValue() / charge / charge * Util.computeGain(config) ); BalanceChange delta = change(priceWeBuy, amount, priceWeSell, amount, config, FeeSystem.FEE_BEFORE); return new FeeFitted( priceWeBuy, priceWeSell, amount, amount, amount, delta.getFrom(), delta.getTo() ); }
BuyLowSellHighFitter implements Fitter { @Override public FeeFitted before(OrderBook book, ClientConfig config) { BigDecimal priceWeBuy = Util.ceilPrice(config, book.getBestSell()); BigDecimal amount = Util.calculateAmount(config, priceWeBuy); double charge = Util.computeCharge(config); BigDecimal priceWeSell = Util.ceilPrice(config, priceWeBuy.doubleValue() / charge / charge * Util.computeGain(config) ); BalanceChange delta = change(priceWeBuy, amount, priceWeSell, amount, config, FeeSystem.FEE_BEFORE); return new FeeFitted( priceWeBuy, priceWeSell, amount, amount, amount, delta.getFrom(), delta.getTo() ); } }
BuyLowSellHighFitter implements Fitter { @Override public FeeFitted before(OrderBook book, ClientConfig config) { BigDecimal priceWeBuy = Util.ceilPrice(config, book.getBestSell()); BigDecimal amount = Util.calculateAmount(config, priceWeBuy); double charge = Util.computeCharge(config); BigDecimal priceWeSell = Util.ceilPrice(config, priceWeBuy.doubleValue() / charge / charge * Util.computeGain(config) ); BalanceChange delta = change(priceWeBuy, amount, priceWeSell, amount, config, FeeSystem.FEE_BEFORE); return new FeeFitted( priceWeBuy, priceWeSell, amount, amount, amount, delta.getFrom(), delta.getTo() ); }  }
BuyLowSellHighFitter implements Fitter { @Override public FeeFitted before(OrderBook book, ClientConfig config) { BigDecimal priceWeBuy = Util.ceilPrice(config, book.getBestSell()); BigDecimal amount = Util.calculateAmount(config, priceWeBuy); double charge = Util.computeCharge(config); BigDecimal priceWeSell = Util.ceilPrice(config, priceWeBuy.doubleValue() / charge / charge * Util.computeGain(config) ); BalanceChange delta = change(priceWeBuy, amount, priceWeSell, amount, config, FeeSystem.FEE_BEFORE); return new FeeFitted( priceWeBuy, priceWeSell, amount, amount, amount, delta.getFrom(), delta.getTo() ); }  @Override FeeFitted after(OrderBook book, ClientConfig config); @Override FeeFitted before(OrderBook book, ClientConfig config); }
BuyLowSellHighFitter implements Fitter { @Override public FeeFitted before(OrderBook book, ClientConfig config) { BigDecimal priceWeBuy = Util.ceilPrice(config, book.getBestSell()); BigDecimal amount = Util.calculateAmount(config, priceWeBuy); double charge = Util.computeCharge(config); BigDecimal priceWeSell = Util.ceilPrice(config, priceWeBuy.doubleValue() / charge / charge * Util.computeGain(config) ); BalanceChange delta = change(priceWeBuy, amount, priceWeSell, amount, config, FeeSystem.FEE_BEFORE); return new FeeFitted( priceWeBuy, priceWeSell, amount, amount, amount, delta.getFrom(), delta.getTo() ); }  @Override FeeFitted after(OrderBook book, ClientConfig config); @Override FeeFitted before(OrderBook book, ClientConfig config);  }