Esempio n. 1
0
  public void update(Set<Symbol> symbols) {
    if (symbols == null || symbols.isEmpty()) {
      symbols = getAllSymbols();
    }

    for (Symbol s : symbols) {
      try {
        Date from = null;
        Date to = TimeServer.now();
        HistPriceDatum last = getLastInFile(s);
        MarketCalendar cal = Calendars.get(s.getMarket());
        if (last == null) {
          logger.log(
              Level.WARNING,
              "{0}: not found data file, will use the default 'start date' to download the all data.",
              s);
          from = cal.timeAdd(to, -DAYS * cal.getDailyTradingTime());
        } else {
          from = last.getTime();
          if (cal.isInSameDate(from, to)) {
            logger.log(
                Level.INFO,
                "{0}: all data are up to date, no need to download",
                new Object[] {s, from, to});
            continue; // no need to download since all data are in file
          }
          from = cal.timeAdd(from, cal.getDailyTradingTime()); // a day ahead
        }
        logger.log(
            Level.INFO, "{0}: downloading price data from {1} to {2}", new Object[] {s, from, to});
        download(s, from, to);
        logger.log(
            Level.INFO, "{0}: Downloaded price data from {1} to {2}", new Object[] {s, from, to});
      } catch (Exception ex) {
        logger.log(Level.WARNING, s + ": ignored to download/update the hist price", ex);
      }
    }
  }
Esempio n. 2
0
 public void download(Set<Symbol> symbols) {
   if (symbols == null || symbols.isEmpty()) {
     symbols = getAllSymbols();
   }
   logger.log(Level.INFO, "Total {0} to be downloaded.", symbols.size());
   MarketCalendar cal = Calendars.get(symbols.iterator().next().getMarket());
   Date to = TimeServer.now();
   Date from = cal.timeAdd(to, -DAYS * cal.getDailyTradingTime());
   long used = 0;
   int i = 0;
   for (Symbol s : symbols) {
     if (checkDataFileExists(s)) {
       logger.log(Level.INFO, "{0}: Data file exists, will not download again.", s);
       continue;
     }
     logger.log(Level.INFO, "{0}: Downloading hist price data for...", s);
     long start = System.currentTimeMillis();
     try {
       download(s, from, to);
     } catch (Exception ex) {
       logger.log(Level.WARNING, s + ": failed to download hist price data", ex);
     }
     used += System.currentTimeMillis() - start;
     if (i > 0 && i % 10 == 0) {
       long avgUsed = used / 10;
       used = 0;
       long willUsed = (symbols.size() - i) * avgUsed / Interval.M1;
       logger.log(
           Level.INFO,
           "Total {0} of {1} symbols are completed, estimated the remaining will need {2} minutes to complete.",
           new Object[] {i, symbols.size(), willUsed});
     }
     try {
       Thread.sleep(SLEEP_TIME);
     } catch (Exception ex) {
     }
     i++;
   }
 }