Here you can find the source of getBtcToBuy(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal scalpAmount)
public static BigDecimal getBtcToBuy(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal scalpAmount)
//package com.java2s; //License from project: Open Source License import java.math.BigDecimal; import java.math.RoundingMode; public class Main { /**/*from ww w . j a va2 s .com*/ * Get the amount of BTC that needs to be bought after selling the scalpped amount: * * x = A*N*(1-F) / B * * Where: * * A = Ask * N = Scalp amount * F = Transaction fees * B = Bid * * @return */ public static BigDecimal getBtcToBuy(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal scalpAmount) { BigDecimal one = new BigDecimal(1); BigDecimal oneMinusFee = one.subtract(fee); BigDecimal btcToBuy = ask.multiply(scalpAmount) .multiply(oneMinusFee).divide(bid, 8, RoundingMode.FLOOR); return btcToBuy; } }