Exemplo n.º 1
0
 private static void findFromDb() throws Exception {
   Date now = TimeServer.now();
   Date date0 = TimeUtils.truncateTime(now);
   List<TopDatum> all = TopDatum.findAllByDate(date0);
   for (TopDatum d : all) {
     System.out.println(d);
   }
 }
Exemplo n.º 2
0
  public static List<TopDatum> parse(JSONArray a) throws JSONException {
    List<TopDatum> list = new ArrayList();
    DateFormat df = new SimpleDateFormat("HH:mm:ss");
    for (int i = 0; i < a.length(); i++) {
      JSONObject o = a.getJSONObject(i);
      TopDatum d = new TopDatum();
      d.setSymbol(new Symbol(o.getString("symbol")));
      d.setName(o.getString("name"));
      d.setLast(new BigDecimal(o.getString("trade")));
      d.setBuy(new BigDecimal(o.getString("buy")));
      d.setSell(new BigDecimal(o.getString("sell")));
      d.setPrevClose(new BigDecimal(o.getString("settlement")));
      d.setChange(new BigDecimal(o.getString("changepercent")));
      d.setAmount(new BigDecimal(o.getString("amount")));
      d.setOpen(new BigDecimal(o.getString("open")));
      try {
        Date t = df.parse(o.getString("ticktime"));
        Date date = TimeServer.now();
        MarketCalendar mc = Calendars.get(d.getSymbol().getMarket());
        if (!mc.isTradingDate(date)) {
          date = mc.previousTradingDate(date);
        } else {
          Date biddingStartTime = mc.getOpenBiddingStartTime(date);
          if (date.before(biddingStartTime)) {
            logger.info(
                "Using the previous date as the current time is before the bidding start time");
            date = mc.previousTradingDate(date);
          }
        }
        d.setTime(TimeUtils.merge(date, t));
      } catch (ParseException ex) {
        Logger.getLogger(TopFetcher.class.getName()).log(Level.SEVERE, null, ex);
        continue;
      }
      d.setVolume(o.getLong("volume"));
      d.setHigh(new BigDecimal(o.getString("high")));
      d.setLow(new BigDecimal(o.getString("low")));
      d.setMarketCapital(new BigDecimal(o.getString("mktcap")).multiply(new BigDecimal("10000")));
      d.setHandOff(new BigDecimal(o.getString("turnoverratio")));
      list.add(d);
    }
    Collections.sort(
        list,
        new Comparator<TopDatum>() {

          @Override
          public int compare(TopDatum o1, TopDatum o2) {
            return -o1.getChange().compareTo(o2.getChange());
          }
        });
    return list;
  }
Exemplo n.º 3
0
 public static void main(String... args) throws Exception {
   if (args.length == 0) {
     usage();
     return;
   }
   // check the first args
   if (!CMDS.contains(args[0])) {
     usage();
     return;
   }
   HistPriceDownloader d = new HistPriceDownloader();
   String startMsg = "Starting to {0} hist price data...";
   String endMsg = "{0} hist price data completed successfully.";
   for (int i = 0; i < args.length; i++) {
     String cmd = args[i];
     logger.log(Level.INFO, startMsg, cmd);
     if (cmd.equals("truncate")) {
       if (++i >= args.length) {
         usage();
         return;
       }
       Date date = TimeUtils.parseIsoDate(args[i]);
       d.truncate(date);
       break;
     }
     Set<Symbol> symbols = getSymbols(args, i);
     if (cmd.equals("clean")) {
       d.clean();
     } else if (cmd.equals("download")) {
       d.download(symbols);
     } else if (cmd.equals("load")) {
       d.load(symbols);
     } else if (cmd.equals("update")) {
       d.update(symbols);
     }
     i += symbols.size();
     logger.log(Level.INFO, endMsg, cmd);
   }
 }