Package models.data

Examples of models.data.Stock


        return stockListJson;
    }

    public static ArrayNode getPrices(Game game, String ticker) {
        ArrayNode stockPricesJson = Json.newObject().arrayNode();
        Stock stock = Stock.find
                .where()
                .eq("ticker", ticker)
                .findUnique();
        if (stock != null) {
            DateTime dt = new DateTime(game.getVirtualCurrentDate());
View Full Code Here


      if (stockExistInSystem(ticker)) {
            return false;
        }

        if (stockExist(ticker)) {
            Stock stock = new Stock();
            stock.setAddedOn(new Timestamp(new Date().getTime()));
            stock.setCompanyName(companyName);
            stock.setIsEnabled(isEnabled);
            stock.setLastUpdated(GameUtil.getCurrentTimeStamp());
            stock.setTicker(ticker);

            ICsvBeanReader beanReader = setup(ticker, null, null);
            if (beanReader == null) {
                play.Logger.warn("bean reader null");
            }

            List<StockPrice> stockPrices = parseCSV(beanReader);

            stock.setPrices(stockPrices);
            stock.save();
            return true;
        }
        return false;
    }
View Full Code Here

     */
    public boolean deleteStock(String ticker) throws IOException {

        if (stockExist(ticker)) {

            Stock stock = Stock.find.where().eq("ticker", ticker).findUnique();

            if (stock != null) {
                int stock_id = Stock.find.where().eq("ticker", ticker).findUnique().getId();
                Stock.find.ref(Integer.toString(stock_id)).delete();
                return true;
View Full Code Here

     * stock is disabled after the method call
     */
    public int flipEnableStock(String ticker) throws IOException {
        int final_state = 2;
        if (stockExist(ticker)) {
            Stock stock = Stock.find.where().eq("ticker", ticker).findUnique();
            if (stock != null) {
                int stock_id = Stock.find.where().eq("ticker", ticker).findUnique().getId();
                Integer currentStatus = stock.getIsEnabled();
                if (currentStatus == 1) {
                    stock.setIsEnabled(ApplicationConstants.FALSE);
                    final_state = ApplicationConstants.FALSE;
                } else {
                    stock.setIsEnabled(ApplicationConstants.TRUE);
        final_state = ApplicationConstants.TRUE;
                }
                stock.save();
            }
        }
        return final_state;
    }
View Full Code Here

     *
     * @param ticker
     * @return
     */
    public boolean stockExistInSystem(String ticker) {
        Stock stock = Stock.find.where().eq("ticker", ticker).findUnique();
        return stock != null;
    }
View Full Code Here

     * @throws java.io.IOException
     */
    public StockPrice getStockPrice(String ticker, Timestamp virtualDate) throws IOException {
        virtualDate = util.TimeKeeper.round_to_day(virtualDate);

        Stock stock = Stock.find.where().eq("ticker", ticker).findUnique();
        List<StockPrice> stockPrices = StockPrice.find.filter().eq("Date", virtualDate).filter(stock.getPrices());
        //parse file to get updated info
        //if (false) {
        if (stockPrices == null || stockPrices.isEmpty()) {
            //just do a week at a time for performance reasons, hence 7 meaning 7 days
            DateTime fromDt = new DateTime(virtualDate.getTime());
            DateTime toDt = fromDt.plusDays(7);

            ICsvBeanReader beanReader = setup(ticker, fromDt, toDt);
            List<StockPrice> newStockPrices = parseCSV(beanReader);
            stock.getPrices().addAll(newStockPrices);
            stock.update();
            stockPrices = StockPrice.find.filter().eq("Date", virtualDate).filter(stock.getPrices());
        }

        return stockPrices.isEmpty() ? null : stockPrices.get(0);
    }
View Full Code Here

          GameManager gameManager = new GameManager();
          if (Stock.findAll().isEmpty()) // Insert player first
          {
            List<Object> stocks = all.get("stocks");
            for (Object stockObj : stocks) {
              Stock stock = (Stock) stockObj;
              gameManager.addStock(stock.getTicker(),
                  stock.getCompanyName(),ApplicationConstants.TRUE);
            }

          }
        }
      } catch (IOException ioe) {
View Full Code Here

TOP

Related Classes of models.data.Stock

Copyright © 2018 www.massapicom. 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.