Example #1
0
  public Double calcProfit(Trade trade, Double brokerFeeFactor) {

    Double profit = 0.0;

    if (reversedOrder != null) {

      Double totalTradeAmount = trade.getAmount() * brokerFeeFactor;

      Double tradeAmountRatio = trade.getAmount() / reversedOrder.getBrokerAmount();
      Double bruttoAmountEquivalent = reversedOrder.getAmount() * tradeAmountRatio;

      Double feeDeduction = (bruttoAmountEquivalent - totalTradeAmount) * rate;

      if (type.equals("sell")) {

        Double sellPrice = totalTradeAmount * rate;
        Double buyPrice = bruttoAmountEquivalent * reversedOrder.getRate();

        System.out.println(
            "sell: "
                + totalTradeAmount
                + "*"
                + rate
                + ", "
                + bruttoAmountEquivalent
                + "*"
                + reversedOrder.getRate());
        profit = (sellPrice - buyPrice) - feeDeduction;
        System.out.println("profit=" + profit);

      } else if (type.equals("buy")) {

        Double buyPrice = bruttoAmountEquivalent * rate;
        Double sellPrice = totalTradeAmount * reversedOrder.getRate();

        System.out.println(
            "buy: "
                + totalTradeAmount
                + "*"
                + rate
                + ", "
                + bruttoAmountEquivalent
                + "*"
                + reversedOrder.getRate());
        profit = (sellPrice - buyPrice) - feeDeduction;
        System.out.println("profit=" + profit);
      }
    }

    return profit;
  }
Example #2
0
  public Double calcFinalRevenue() {

    Double finalRevenue = 0.0;

    if (reversedOrder != null) {

      if (type.equals("sell")) {

        finalRevenue =
            (finalAmount * rate) - (reversedOrder.getFinalAmount() * reversedOrder.getRate());

      } else if (type.equals("buy")) {

        finalRevenue =
            (reversedOrder.getFinalAmount() * reversedOrder.getRate()) - (finalAmount * rate);
      }
    }

    return finalRevenue;
  }