public synchronized void updateCurrentMarket() {
    Price buyTopPrice = buySide.topOfBookPrice();
    if (buyTopPrice == null) buyTopPrice = PriceFactory.makeLimitPrice((long) 0);

    Price sellTopPrice = sellSide.topOfBookPrice();
    if (sellTopPrice == null) sellTopPrice = PriceFactory.makeLimitPrice((long) 0);

    String str =
        buyTopPrice.toString()
            + buySide.topOfBookVolume()
            + sellTopPrice.toString()
            + sellSide.topOfBookVolume();

    if (!this.lastCurrentMarket.equals(str)) {
      MarketDataDTO mktDTO =
          new MarketDataDTO(
              this.productSymbol,
              buyTopPrice,
              buySide.topOfBookVolume(),
              sellTopPrice,
              sellSide.topOfBookVolume());

      CurrentMarketPublisher.getInstance().publishCurrentMarket(mktDTO);
      lastCurrentMarket = str;
    }
  }
 public void testManyToOneGenerics() throws Exception {
   Paper white = new Paper();
   white.setName("WhiteA4");
   PaperType type = new PaperType();
   type.setName("A4");
   SomeGuy me = new SomeGuy();
   white.setType(type);
   white.setOwner(me);
   Price price = new Price();
   price.setAmount(new Double(1));
   price.setCurrency("Euro");
   white.setValue(price);
   Session s = openSession();
   Transaction tx = s.beginTransaction();
   s.persist(type);
   s.persist(price);
   s.persist(me);
   s.persist(white);
   tx.commit();
   // s.close();
   s = openSession();
   tx = s.beginTransaction();
   white = (Paper) s.get(Paper.class, white.getId());
   s.delete(white.getType());
   s.delete(white.getOwner());
   s.delete(white.getValue());
   s.delete(white);
   tx.commit();
   // s.close();
 }
 public double getPriceByCategory(String category) {
   for (Price temp : priceList) {
     if (temp.getCategory().equals(category)) {
       return temp.getPrice();
     }
   }
   return priceList.get(0).getPrice();
 }
  public synchronized void addToBook(Quote q) throws Exception {
    Price sellQuote = q.getQuoteSide("SELL").getPrice();
    Price buyQuote = q.getQuoteSide("BUY").getPrice();

    if (sellQuote.lessOrEqual(buyQuote))
      throw new DataValidationException("SELL Price is less than or Equal to BUY Price");
    if (q.getQuoteSide("SELL").getOriginalVolume() <= 0
        || q.getQuoteSide("BUY").getOriginalVolume() <= 0)
      throw new DataValidationException("BUY or SELL side is less than or equal to zero");

    if (this.userQuotes.contains(q.getUserName())) {
      buySide.removeQuote(q.getUserName());
      sellSide.removeQuote(q.getUserName());
      this.updateCurrentMarket();
    }
    this.addToBook(BookSide.BUY, q.getQuoteSide("BUY"));
    this.addToBook(BookSide.SELL, q.getQuoteSide("SELL"));

    userQuotes.add(q.getUserName());
    this.updateCurrentMarket();
  }
Пример #5
0
  public void setPricePolicy(int cusType, int dateType, double dPrice) {
    Price price = null;

    if (_prices.containsKey(cusType)) {
      price = _prices.get(cusType);
    } else {
      switch (cusType) {
        case Customer.REGULAR:
          price = new RegularPrice();
          break;

        case Customer.REWARDS:
          price = new RewardsPrice();
          break;

        default:
          System.out.println("Error: setPricePolicy Failed! Caused by CustomType undefined.");
          return;
      }
    }

    if (price != null) {
      switch (dateType) {
        case Price.WEEKDAY_PRICE:
          price.setWeekdayPrice(dPrice);
          break;

        case Price.WEEKEND_PRICE:
          price.setWeekendPrice(dPrice);
          break;

        default:
          System.out.println("Error: setPricePolicy Failed! Caused by DateType undefined.");
          break;
      }
    }

    _prices.put((Integer) cusType, price);
  }
  public synchronized void openMarket() throws Exception {
    Price bestBuyPrice = buySide.topOfBookPrice();
    Price bestSellPrice = sellSide.topOfBookPrice();

    if (bestBuyPrice != null && bestSellPrice != null) {
      while (bestBuyPrice.greaterOrEqual(bestSellPrice)
          || bestBuyPrice.isMarket()
          || bestSellPrice.isMarket()) {
        ArrayList<Tradable> topOfBuySide = buySide.getEntriesAtPrice(bestBuyPrice);
        ArrayList<Tradable> toRemove = new ArrayList<Tradable>();
        HashMap<String, FillMessage> allFills = null;

        for (Tradable t : topOfBuySide) {
          allFills = sellSide.tryTrade(t);
          if (t.getRemainingVolume() == 0) {
            toRemove.add(t);
          }
        }

        for (Tradable t : toRemove) {
          buySide.removeTradable(t);
        }
        updateCurrentMarket();

        Price lastSalePrice = this.determineLastSalePrice(allFills);
        int lastSaleVolume = this.determineLastSaleQuantity(allFills);

        LastSalePublisher.getInstance()
            .publishLastSale(productSymbol, lastSalePrice, lastSaleVolume);

        bestBuyPrice = buySide.topOfBookPrice();
        bestSellPrice = sellSide.topOfBookPrice();

        if (bestBuyPrice == null || bestSellPrice == null) break;
      }
    }
  }
Пример #7
0
 @Override
 public final Object clone() throws CloneNotSupportedException {
   Residence clone =
       new Residence(
           residenceId,
           name,
           description,
           (Address) address.clone(),
           (Price) price.clone(),
           (Date) published.clone(),
           (Date) expire.clone(),
           mainPhotoPath,
           phathOfPhotos,
           (User) contact.clone());
   return clone;
 }
Пример #8
0
  public String toString() {
    StringBuilder squery = new StringBuilder();

    if (price != null) {
      squery.append(price.toString());
    }

    if (time != null) {
      squery.append(time.toString());
    }

    if (location != null) {
      squery.append(location.toString());
    }

    if (ccontent != null) {
      squery.append(ccontent.toString());
    }

    return squery.toString();
  }
Пример #9
0
  public static void main(String args[]) throws Exception {
    SqlSession sqlSession = RazorServer.openSession();
    try {
      JAXBContext jc = JAXBContext.newInstance("net.cbtltd.rest.interhome.price");
      Unmarshaller um = jc.createUnmarshaller();

      Prices prices = (Prices) um.unmarshal(new java.io.FileInputStream("C:/price_0505_eur.xml"));

      int i = 0;
      for (Price price : prices.getPrice()) {
        System.out.println(i++ + " " + price);
        Product product =
            sqlSession
                .getMapper(ProductMapper.class)
                .altread(new NameId(PartyIds.PARTY_INTERHOME_ID, price.getCode()));
        if (product == null) {
          throw new ServiceException(Error.product_id, price.getCode());
        }

        net.cbtltd.shared.Price action = new net.cbtltd.shared.Price();
        action.setName(NameId.Type.Reservation.name());
        action.setType(NameId.Type.Reservation.name());
        action.setEntitytype(NameId.Type.Product.name());
        action.setEntityid(product.getId());
        action.setPartyid(PartyIds.PARTY_INTERHOME_ID); // TODO
        action.setState(net.cbtltd.shared.Price.CREATED);
        action.setDate(price.getStartdate().toGregorianCalendar().getTime());
        action.setTodate(price.getEnddate().toGregorianCalendar().getTime());
        net.cbtltd.shared.Price exists = sqlSession.getMapper(PriceMapper.class).exists(action);
        if (exists == null) {
          sqlSession.getMapper(PriceMapper.class).create(action);
        } else {
          action = exists;
        }
        //				price.getFixprice();
        //				price.getMaxrentalprice();
        //				price.getMidweekrentalprice();
        action.setMinimum(price.getMinrentalprice().doubleValue());
        action.setValue(price.getRentalprice().doubleValue());
        action.setCurrency(Currency.Code.EUR.name());
        action.setQuantity(0.0); // TODO: for 8, 15, 22 day breaks
        action.setUnit(Unit.WEE);
        //				price.getWeekendrentalprice();

        for (Service service : price.getServices().getService()) {
          service.getCode();
          service.getServiceprice();
          // TODO: add mandatory charges to product
          // Map code to price ID for Mandatory charge
        }

        Specialoffer specialoffer = price.getSpecialoffer();
        if (specialoffer != null) {
          specialoffer.getCode();
          specialoffer.getSpecialofferprice();
        }

        sqlSession.getMapper(PriceMapper.class).update(action);
        System.out.println(action);
        sqlSession.commit();
        // if (i > 100)break;
      }
    } catch (Throwable x) {
      x.printStackTrace();
    }

    System.out.println("Finished...");
    System.exit(0);
  }
Пример #10
0
 public Ticket(Price price) {
   this.price = price.getInitialPrice();
 }
Пример #11
0
 public String getSetPrice2String(boolean isBuy) {
   return Price.toString((isBuy) ? this._buySetPrice2 : this._sellSetPrice2);
 }
Пример #12
0
 @Override
 public int compareTo(Price o) {
   return storeName.compareTo(o.getStoreName());
 }
Пример #13
0
 /**
  * Gives the amount of its price
  *
  * @return int, amount of price.
  */
 public int getPrice() {
   return price.getAmount();
 }