Пример #1
0
bool CSV::openDb (QString &path, QString &symbol, QString &type, bool tickFlag)
{
  if (db.open(path, chartIndex))
  {
    qDebug("CSV::openDb:can't open chart");
    QString ss("CSV::OpenDb:Could not open db.");
    printStatusLogMessage(ss);
    db.close();
    return TRUE;
  }

  QString s;
  DBIndexItem item;
  chartIndex->getIndexItem(symbol, item);
  item.getSymbol(s);
  if (! s.length())
  {
    if (! type.compare("Futures"))
    {
      db.setType(DbPlugin::Futures1);
      if (db.createNewFutures())
      {
        db.close();
        return TRUE;
      }
    }
    else
    {
      if(db.createNewStock())
      {
        db.close();
        return TRUE;
      }
    }

    item.setSymbol(symbol);
    item.setBarType(tickFlag);
    chartIndex->setIndexItem(symbol, item);
  }

  // verify if this chart can be updated by this plugin
  item.getQuotePlugin(s);
  if (! s.length())
  {
    item.setQuotePlugin(pluginName);
    chartIndex->setIndexItem(symbol, item);
  }
  else
  {
    if (s.compare(pluginName))
    {
      s = symbol + " - skipping update. Source does not match destination.";
      printStatusLogMessage(s);
      db.close();
      return TRUE;
    }
  }

  return FALSE;
}
Пример #2
0
void Yahoo::createAutoHistoryUrls (QString &path, QString &d)
{
  if (plug.open(path, chartIndex))
  {
    qDebug("Yahoo::createAutoHistoryUrls:could not open db");
    return;
  }

  QFileInfo fi(path);
  QString fn = fi.fileName();

  // verify if this chart can be updated by this plugin
  QString s;
  DBIndexItem item;
  chartIndex->getIndexItem(fn, item);
  item.getQuotePlugin(s);
  if (! s.length())
  {
    item.setQuotePlugin(pluginName);
    chartIndex->setIndexItem(fn, item);
  }
//  else
//  {
//    if (s.compare(pluginName))
//    {
//      qDebug("Yahoo::createAutoHistoryUrls:source not same as destination");
//      plug.close();
//      return;
//    }
//  }

  QDate edt = QDate::currentDate();
  if (edt.dayOfWeek() == 6)
    edt = edt.addDays(-1);
  else
  {
    if (edt.dayOfWeek() == 7)
      edt = edt.addDays(-2);
  }

  Bar bar;
  plug.getLastBar(bar);
  if (bar.getEmptyFlag())
  {
    QDate dt = edt;
    dt = dt.addDays(-365);
    s = dt.toString("yyyyMMdd000000");
    bar.setDate(s);
  }

  QDateTime dt;
  bar.getDate(dt);
  if (dt.date() == edt)
  {
//    qDebug("Yahoo::createAutoHistoryUrls:barDate == endDate");
    plug.close();
    return;
  }

  s = "http://table.finance.yahoo.com/table.csv?s=";
  s.append(d);
  s.append("&a=");
  s.append(QString::number(dt.date().month() - 1));
  s.append("&b=");
  s.append(dt.toString("dd"));
  s.append("&c=");
  s.append(dt.toString("yyyy"));
  s.append("&d=");
  s.append(QString::number(edt.month() - 1));
  s.append("&e=");
  s.append(edt.toString("dd"));
  s.append("&f=");
  s.append(edt.toString("yyyy"));
  s.append("&g=d&ignore=.csv");

  plug.close();

  Setting *set = new Setting;
  QString ts = "url";
  set->setData(ts, s);
  ts = "symbol";
  set->setData(ts, d);
  url.append(set);
}