Beispiel #1
0
 @Override
 public boolean equals(Object o) {
   if (o instanceof Depth) {
     Depth depth = (Depth) o;
     return depth.getMarketType() == getMarketType();
   }
   return super.equals(o);
 }
Beispiel #2
0
  public static Depth formatJsonOfMarketDepth(MarketType marketType, JSONObject json)
      throws JSONException {
    Depth depth = new Depth();

    double rate = ExchangeUtil.getRate(marketType);
    int bidMaxPrice = 0;
    int askMinPrice = Integer.MAX_VALUE;

    List<DateValueEntity> bidDateValueEntities = new ArrayList<DateValueEntity>();
    List<DateValueEntity> askDateValueEntities = new ArrayList<DateValueEntity>();
    double bidSumVolume = 0;
    int splitIndex = 0;
    if (!json.isNull(BIDS)) {
      JSONArray bidArray = json.getJSONArray(BIDS);

      for (int i = bidArray.length() - 1; i >= 0; i--) {
        JSONArray bid = bidArray.getJSONArray(i);
        int bidPrice = bid.getInt(0);
        double price = ((double) bidPrice) / 100 * rate;
        double volume = bid.getDouble(1) / Math.pow(10, 8);
        if (bidMaxPrice < bidPrice) {
          bidMaxPrice = bidPrice;
        }
        bidSumVolume = bidSumVolume + volume;
        DateValueEntity dateValueEntity =
            new DateValueEntity(
                (float) bidSumVolume, StringUtil.formatDoubleToMoneyString(price), bidPrice);
        bidDateValueEntities.add(dateValueEntity);
      }
      splitIndex = bidArray.length();
    }
    double askSumVolume = 0;
    if (!json.isNull(ASKS)) {
      JSONArray askArray = json.getJSONArray(ASKS);

      for (int i = 0; i < askArray.length(); i++) {
        JSONArray ask = askArray.getJSONArray(i);
        int askPrice = ask.getInt(0);
        double price = ((double) askPrice) / 100 * rate;
        double volume = ask.getDouble(1) / Math.pow(10, 8);
        askSumVolume = askSumVolume + volume;
        if (askPrice < askMinPrice) {
          askMinPrice = askPrice;
        }
        DateValueEntity dateValueEntity =
            new DateValueEntity(
                (float) askSumVolume, StringUtil.formatDoubleToMoneyString(price), askPrice);
        askDateValueEntities.add(dateValueEntity);
      }
    }
    int mixPrice = (askMinPrice + bidMaxPrice) / 2;
    DateValueEntity zeroDateValue =
        new DateValueEntity(
            0, StringUtil.formatDoubleToMoneyString(((double) mixPrice) / 100 * rate), mixPrice);
    List<DateValueEntity> dateValueEntities = new ArrayList<DateValueEntity>();
    dateValueEntities.addAll(bidDateValueEntities);
    dateValueEntities.add(zeroDateValue);
    dateValueEntities.addAll(askDateValueEntities);
    Collections.sort(dateValueEntities, new ComparatorDateValue());
    depth.setMaxVolume(Math.max(askSumVolume, bidSumVolume));
    depth.setDateValueEntities(dateValueEntities);
    depth.setSplitIndex(splitIndex);
    return depth;
  }