Java BigDecimal getBtcToBuy(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal scalpAmount)

Here you can find the source of getBtcToBuy(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal scalpAmount)

Description

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

License

Open Source License

Declaration

public static BigDecimal getBtcToBuy(BigDecimal ask, BigDecimal bid,
        BigDecimal fee, BigDecimal scalpAmount) 

Method Source Code

//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;
    }
}

Related

  1. floatValue(BigDecimal val)
  2. fromLongToBigDecimal(long longValue)
  3. getArcCosineFor(BigDecimal radians)
  4. getAsDouble(BigDecimal value)
  5. getBalance(BigDecimal balance)
  6. getByteArrayFromBigDecimalArray(Object value)
  7. getConversionUsdBased(final String destinycode, final BigDecimal amount, final BigDecimal usdBasedBaseRate, BigDecimal usdBasedDestinyRate)
  8. getDateFromRank(BigDecimal rank)
  9. getDepositAmount(Boolean isReceipt, BigDecimal amount)