Examples of Trader


Examples of org.apache.openjpa.trader.domain.Trader

    public Trader login(String trader) {
        for (Trader t : _traders) {
            if (t.getName().equals(trader))
                return t;
        }
        Trader t = new Trader(trader);
        _traders.add(t);
        return t;
    }
View Full Code Here

Examples of org.apache.openjpa.trader.domain.Trader

        });
       
        // Counter Party
        setRenderer(3, new GridCellRenderer<Trade>() {
            public Widget render(Trade t) {
                Trader cpty = session.getTrader().equals(t.getBuyer()) ? t.getSeller() : t.getBuyer();
                return new Label(cpty.getName());
           }
        });
    }
View Full Code Here

Examples of org.apache.openjpa.trader.domain.Trader

     * On receipt of the event determines if it is relevant for this instance.
     * Because an instance display either the Trades sold or bought.
     * If relevant then updates the display.
     */
    public void onTradeCommitted(ServiceEvent.TradeCommitted event) {
        Trader trader = session.getTrader();
        Trade trade = event.getPayload();
        if ((trader.equals(trade.getSeller()) && _type == Ask.class)
         || (trader.equals(trade.getBuyer())  && _type == Bid.class)) {  
            insert(trade);
        }
    }
View Full Code Here

Examples of org.apache.openjpa.trader.domain.Trader

        final RadioButton[] buttons = new RadioButton[matches.size()];
        if (!matches.isEmpty()) {
            for (int i = 0;  i < matches.size(); i++) {
                Match match = matches.get(i);
                Tradable t2 = ask ? match.getBid() : match.getAsk();
                Trader cpty = ask ? match.getBid().getBuyer() : match.getAsk().getSeller();
                buttons[i] = new RadioButton("matches");
                buttons[i].setValue(i == 0);
                body.setWidget(i, 0, buttons[i]);
                body.setWidget(i, 1, FormatUtil.formatPrice(t2.getPrice()));
                body.setWidget(i, 2, FormatUtil.formatVolume(t2.getVolume()));
                body.setText(i, 3, " by " + cpty.getName());
            }
           
            Button act = new Button(ask ? "Sell" : "Buy");
            act.setFocus(true);
            body.setWidget(matches.size()+1, 1, act);
View Full Code Here

Examples of org.apache.openjpa.trader.domain.Trader

    }

    public Trader login(String traderName) {
        EntityManager em = getEntityManager();
        begin();
        Trader trader = em.find(Trader.class, traderName);
        if (trader == null) {
            trader = new Trader(traderName);
            em.persist(trader);
        }
        commit();
        return trader;
    }
View Full Code Here

Examples of org.apache.openjpa.trader.domain.Trader

                Stock stock = new Stock((String)d[0], (String)d[0], (Sector)d[1], (Double)d[2]);
                em.persist(stock);
            }
       
            for (int i = 0; i < 4; i++) {
                Trader trader = new Trader("Trader-"+i);
                em.persist(trader);
            }
            stocks = em.createQuery(GET_ALL_STOCKS, Stock.class).getResultList();
        }
        commit();
View Full Code Here

Examples of org.jbehave.examples.core.model.Trader

        }
        return false;
    }

    public Object convertValue(String value, Type type) {
        Trader trader = persister.retrieveTrader(value);
        if (trader == null) {
            throw new ParameterConvertionFailed("Trader not found for name " + value, null);
        }
        return trader;
    }
View Full Code Here

Examples of org.jbehave.examples.core.model.Trader

    }
    return mockTradePersister().retrieveTrader(name);
  }

  static TraderPersister mockTradePersister() {
    return new TraderPersister(new Trader("Mauro", asList(new Stock("STK1", 10.d))));
  }
View Full Code Here

Examples of org.jbehave.examples.core.model.Trader

    public Stock newStock(String symbol, double threshold) {
        return new Stock(symbol, threshold);
    }

    public Trader newTrader(String name, String rank) {
        return new Trader(name, rank);
    }
View Full Code Here

Examples of org.nightlabs.jfire.trade.Trader

    if (!JbpmConstantsRecurringOffer.Vendor.NODE_NAME_RECURRENCE_STARTED.equals(nodeName)) {
      throw new IllegalStateException("The recurrence for RecurringOffer " + JDOHelper.getObjectId(recurringOffer) + " is not started, it is in the state '" + nodeName + "'.");
    }
    logger.debug("Starting creation of RecurredOffer (with new Order) for RecurringOffer: " + JDOHelper.getObjectId(recurringOffer));
    PersistenceManager pm = getPersistenceManager();
    Trader trader = Trader.getTrader(pm);

    Order order = trader.createOrder(recurringOffer.getVendor(),
        recurringOffer.getCustomer(), null, recurringOffer.getCurrency());
    logger.debug("Created Order: " + JDOHelper.getObjectId(order));

    User user = SecurityReflector.getUserDescriptor().getUser(pm);

    String offerIDPrefix = recurringOffer.getOfferIDPrefix();

    Collection<Segment> recurringSegments = new HashSet<Segment>();
    for (Article article : recurringOffer.getArticles()) {
      recurringSegments.add(article.getSegment());
    }

    // create the new segment for the order
    for (Segment segment : recurringSegments) {
      trader.createSegment(order, segment.getSegmentType());
    }

    RecurredOffer recurredOffer = createRecurredOffer(recurringOffer,user, order, offerIDPrefix);

    logger.debug("Created RecurredOffer: " + JDOHelper.getObjectId(recurredOffer));

    // Loop over all articles in the given offer and group
    // them by SegmentType and ProductType-class
    Map<SegmentType, Map<Class<? extends ProductType>, Set<Article>>> segmentTypes2PTClass2Articles =  new HashMap<SegmentType, Map<Class<? extends ProductType>, Set<Article>>>();
    Set<Article> articles = new HashSet<Article>();

    for (Article recurringArticle : recurringOffer.getArticles()) {
      SegmentType segmentType = recurringArticle.getSegment().getSegmentType();
      Map<Class<? extends ProductType>, Set<Article>> ptClass2Articles = segmentTypes2PTClass2Articles.get(segmentType);
      if (ptClass2Articles == null) {
        ptClass2Articles = new HashMap<Class<? extends ProductType>, Set<Article>>();
        segmentTypes2PTClass2Articles.put(segmentType, ptClass2Articles);
      }
      Class<? extends ProductType> productTypeClass = recurringArticle.getProductType().getClass();
      articles = ptClass2Articles.get(productTypeClass);
      if (articles == null) {
        articles = new HashSet<Article>();
        ptClass2Articles.put(productTypeClass, articles);
      }
      articles.add(recurringArticle);
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Grouped articles in RecurringOffer:");
      for (Map.Entry<SegmentType, Map<Class<? extends ProductType>, Set<Article>>> segmentTypeEntry : segmentTypes2PTClass2Articles.entrySet()) {
        logger.debug("  SegmentType: " + JDOHelper.getObjectId(segmentTypeEntry.getKey()));
        for (Map.Entry<Class<? extends ProductType>, Set<Article>> productTypeEntry : segmentTypeEntry.getValue().entrySet()) {
          logger.debug("    ProductType class: " + productTypeEntry.getKey());
          for (Article article : productTypeEntry.getValue()) {
            logger.debug("      Article: " + JDOHelper.getObjectId(article));
          }
        }
      }
    }

    // loop over the segments added to the order
    for (Segment segment : order.getSegments()) {
      logger.debug("Creating articles for RecurredOffer for SegmentType " + JDOHelper.getObjectId(segment.getSegmentType()));
      Map<Class<? extends ProductType>, Set<Article>> collected = segmentTypes2PTClass2Articles.get(segment.getSegmentType());
      if (collected != null) { // it is possible that there are segments with no articles in the RecurringOffer
        // add each segment to the RecurredOffer
        recurredOffer.addSegment(segment);
        for (Iterator< Class<? extends ProductType>> it = collected.keySet().iterator(); it.hasNext();)
        {
          // now for each ProductType class find the handler and let him create the articles
          Class<? extends ProductType> pt = it.next();
          logger.debug("  Creating articles for RecurredOffer for ProductType class " + pt);

          articles = collected.get(pt);

          RecurringTradeProductTypeActionHandler handler = RecurringTradeProductTypeActionHandler.getRecurringTradeProductTypeActionHandler(pm, pt);
          if (handler == null)
            throw new IllegalStateException("Could not find a " + RecurringTradeProductTypeActionHandler.class.getName() +
                " for the ProductType class " + pt);
          logger.debug("  Found handler " + handler.getClass().getName() + " ProductType class " + pt);

          Map<Article, Article> recurredArticles = handler.createArticles(recurredOffer, articles, segment);

          if(recurredArticles.size() != articles.size())
            throw new IllegalStateException(
                "RecurringTradeProductTypeActionHandler " + handler.getClass().getName() +
                " created " + recurredArticles.size() + " recurred articles for " + articles.size() +
                " template/recurring articles");

          for (Map.Entry<Article, Article> articleEntry : recurredArticles.entrySet()) {
            //  Compare Prices to check if they the Differ
            Price recurringPrice = articleEntry.getValue().getPrice();
            Price recurredPrice = articleEntry.getKey().getPrice();
            // if amount or currency differs
            if (recurredPrice.getAmount() != recurringPrice.getAmount() || !recurredPrice.getCurrency().equals(recurringPrice.getCurrency()))
              priceDiffer = true;

            if (logger.isDebugEnabled()) {
              if (!articleEntry.getValue().isAllocated()) {
                logger.debug("    An Article was created which was NOT allocated: " + JDOHelper.getObjectId(articleEntry.getValue()));
              } else {
                logger.debug("    An allocated Article was created: " + JDOHelper.getObjectId(articleEntry.getValue()));
              }

              logger.debug("  Finished creatingArticles");
            }

          }
        }
      }
    }
    // TODO: Check/Compare article prices from RecurringOffer and crated RecurredOffer
    /* Depending on the configuration of the RecurringOffer the following strageties should be supported:
     * * Always use offered prices (Meaning that the process will enforce the
     *   old prices for the newly created RecurredOffer)
     * * Use offered prices but don't finalize (Meaning that the old prices will
     *   be used, but the new offer will not be finalized, it would be best if this
     *   could somehow notify the user then, but this for later)
     * * Use current prices (Meaning that the process will always take the
     *   current prices for the new offers, this is what currently happens)
     * * Use current prices but don't finalize (Meaning that the new prices will
     *   be used, but the new offer will not be finalized)
     *   How to enforce old prices is not absolutely clear to me now, but I know
     *   that it's possible somehow
     *
     * Alex
     */
    // finished creating articles

    if(!priceDiffer)
    {
      // For now, as long as the different strategies are not present, we directly accept the offer.
      trader.acceptOfferImplicitely(recurredOffer);

      if(recurringOffer.getRecurringOfferConfiguration().isCreateInvoice()) {
        // If the configuration says so, automatically create an invoice
        logger.debug("Creating invoice for new RecurredOffer");

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.