Exemplo n.º 1
0
void NYBOT::parse ()
{
  if (cancelFlag)
    return;
  
  QFile f(file);
  if (! f.open(IO_ReadOnly))
    return;
  QTextStream stream(&f);
    
  QString ts = stream.readLine();
  QString s;
  stripJunk(ts, s);
  QStringList keys = QStringList::split(",", s, FALSE);

  while(stream.atEnd() == 0)
  {
    ts = stream.readLine();
    stripJunk(ts, s);

    QStringList l = QStringList::split(",", s, FALSE);

    if (l.count() != keys.count())
      continue;

    Setting data;
    int loop2;
    for (loop2 = 0; loop2 < (int) keys.count(); loop2++)
      data.setData(keys[loop2], l[loop2]);

    // symbol
    QString symbol;
    QString ts = "commoditySymbol";
    data.getData(ts, symbol);
    symbol = symbol.stripWhiteSpace();
    if (symbol.length() == 0)
      continue;

    if (! symbol.compare("CC") || ! symbol.compare("CR") || ! symbol.compare("CT") ||
        ! symbol.compare("DX") || ! symbol.compare("KC") || ! symbol.compare("OJ") ||
	! symbol.compare("SB") || ! symbol.compare("YX"))
    {
    }
    else
      continue;

    // date
    QString date;
    ts = "tradeDate";
    data.getData(ts, date);
    date.append("000000");

    Bar bar;
    if (bar.setDate(date))
    {
      QString ss = tr("Bad date") + " " + date;
      printStatusLogMessage(ss);
      continue;
    }

    ts = "dailyOpenPrice1";
    data.getData(ts, s);
    if (s.toFloat() == 0)
    {
      ts = "dailyOpenPrice2";
      data.getData(ts, s);
    }
    if (setTFloat(s, FALSE))
      continue;
    else
      bar.setOpen(tfloat);

    ts = "dailyHigh";
    data.getData(ts, s);
    if (setTFloat(s, FALSE))
      continue;
    else
      bar.setHigh(tfloat);

    ts = "dailyLow";
    data.getData(ts, s);
    if (setTFloat(s, FALSE))
      continue;
    else
      bar.setLow(tfloat);

    ts = "settlementPrice";
    data.getData(ts, s);
    if (setTFloat(s, FALSE))
      continue;
    else
      bar.setClose(tfloat);

    ts = "tradeVolume";
    data.getData(ts, s);
    if (setTFloat(s, FALSE))
      continue;
    else
      bar.setVolume(tfloat);

    ts = "openInterest";
    data.getData(ts, s);
    if (setTFloat(s, FALSE))
      continue;
    else
      bar.setOI((int) tfloat);

    if (symbol.compare("CC"))
    {
      bar.setOpen(bar.getOpen() / 100);
      bar.setHigh(bar.getHigh() / 100);
      bar.setLow(bar.getLow() / 100);
      bar.setClose(bar.getClose() / 100);
    }

    if (bar.verify())
      continue;

    //futures month
    ts = "contractMonth";
    data.getData(ts, s);
    QString year = s.left(4);
    QString month = s.right(2);
    QString fmonth;

    switch (month.toInt())
    {
      case 1:
        fmonth = "F";
        break;
      case 2:
        fmonth = "G";
        break;
      case 3:
        fmonth = "H";
        break;
      case 4:
        fmonth = "J";
        break;
      case 5:
        fmonth = "K";
        break;
      case 6:
        fmonth = "M";
        break;
      case 7:
        fmonth = "N";
        break;
      case 8:
        fmonth = "Q";
        break;
      case 9:
        fmonth = "U";
        break;
      case 10:
        fmonth = "V";
        break;
      case 11:
        fmonth = "X";
        break;
      case 12:
        fmonth = "Z";
        break;
      default:
        break;
    }

    if (fd.setSymbol(symbol))
      continue;

    if (year.length())
    {
      symbol.append(year);

      if (fmonth.length())
        symbol.append(fmonth);
      else
        continue;
    }
    else
      continue;

    s = "Futures/";
    QString s2;
    fd.getExchange(s2);
    s.append(s2 + "/");
    fd.getSymbol(s2);
    s.append(s2);
    QString path;
    createDirectory(s, path);
    if (! path.length())
    {
      QString ss(tr("Unable to create futures directory"));
      printStatusLogMessage(ss);
      return;
    }
	
    s = path + "/" + symbol;
    if (plug.open(s, chartIndex))
    {
      QString ss(tr("Could not open db"));
      printStatusLogMessage(ss);
      return;
    }

    DBIndexItem item;
    chartIndex->getIndexItem(symbol, item);
    item.getSymbol(s);
    if (! s.length())
    {
      if (plug.createNewFutures())
        return;

      chartIndex->getIndexItem(symbol, item);

      s = QString::number(Exchange::NYBOT);
      item.setExchange(s);

      item.setQuotePlugin(pluginName);

      chartIndex->setIndexItem(symbol, item);
    }

    plug.setBar(bar);
		 
    plug.close();

    emit signalWakeup();
  }

  f.close();

  downloadComplete();
  if (cancelFlag)
  {
    cancelFlag = FALSE;
    QString ss(tr("Update cancelled"));
    printStatusLogMessage(ss);
  }
  else
  {
    QString ss(tr("Done"));
    printStatusLogMessage(ss);
  }
}
Exemplo n.º 2
0
void Yahoo::newStock ()
{
  bool ok = FALSE;
  QString symbols = QInputDialog::getText(tr("New Yahoo Symbols"),
                                          tr("Enter symbols to add. Note: separate symbols with a space"),
				          QLineEdit::Normal,
				          QString::null,
				          &ok,
				          this);
  if (! symbols.length())
    return;

  QStringList l = QStringList::split(" ", symbols, FALSE);

  QString s;
  config.getData(Config::DataPath, s);
  s.append("/Stocks");
  QDir dir(s);
  if (! dir.exists(s))
  {
    if (! dir.mkdir(s))
    {
      qDebug("YahooDialog::newStock: Unable to create %s directory", s.latin1());
      return;
    }
  }

  if (! dir.exists(dataPath))
  {
    if (! dir.mkdir(dataPath))
    {
      qDebug("YahooDialog::newStock: Unable to create %s directory", dataPath.latin1());
      return;
    }
  }

  QStringList n;
  int loop;
  for (loop = 0; loop < (int) l.count(); loop++)
  {
    QString exchange;
    QString s = dataPath + "/";
    QFileInfo fi(l[loop]);

    if (fi.extension(FALSE).length())
    {
      exchange = fi.extension(FALSE).upper();
      s.append(fi.extension(FALSE).upper());
    }
    else
      s.append("US");

    if (! dir.exists(s))
      {
      if (! dir.mkdir(s))
      {
        qDebug("YahooDialog::newStock: Unable to create %s directory", s.latin1());
        continue;
      }
    }
    
    s.append("/");
    s.append(l[loop]);
    if (dir.exists(s))
      continue;

    if (plug.open(s, chartIndex))
    {
      qDebug("YahooDialog::newStock: could not open db %s", s.latin1());
      plug.close();
      continue;
    }

    n.append(s);
    plug.createNewStock();

    QFileInfo fi2(s);
    QString fn = fi2.fileName();
    DBIndexItem item;
    chartIndex->getIndexItem(fn, item);
    getExchange(exchange, s);
    item.setExchange(s);
    chartIndex->setIndexItem(fn, item);

    plug.close();
  }

  list->setFile(n);
  allSymbols->setCheckState(Qt::Unchecked);
  method->setCurrentIndex(0);
  methodChanged(0);
}