예제 #1
0
void SpreadDialog::newSpread ()
{
  bool ok = FALSE;
  QString spread = QInputDialog::getText(QObject::tr("New Spread"),
                                         QObject::tr("Enter symbol name for the new Spread"),
                                         QLineEdit::Normal,
                                         QString::null,
                                         &ok,
                                         0);
  if (! spread.length() || ok == FALSE)
    return;

  QDir dir;
  Config config;
  QString s;
  config.getData(Config::DataPath, s);
  s.append("/Spread");
  if (! dir.exists(s))
  {
    if (! dir.mkdir(s, TRUE))
    {
      QMessageBox::information(0,
                               QObject::tr("Qtstalker: Error"),
                               QObject::tr("Could not create Spread directory."));
      return;
    }
  }
  
  s.append("/" + spread);
  if (dir.exists(s))
  {
    QMessageBox::information(0,
                             QObject::tr("Qtstalker: Error"),
                             QObject::tr("This Spread already exists."));
    return;
  }

  DbPlugin db;
  if (db.openChart(s))
  {
    QMessageBox::information(0,
                             QObject::tr("Qtstalker: Disk Error"),
                             QObject::tr("Cannot create chart."));
    db.close();
    return;
  }

  db.setHeaderField(DbPlugin::Symbol, spread);
  s = "Spread";
  db.setHeaderField(DbPlugin::Type, s);  
  db.setHeaderField(DbPlugin::Plugin, s);  
  db.setHeaderField(DbPlugin::Title, spread);
  db.close();
}
예제 #2
0
void Index::loadIndexData (QString &symbol, QDict<Bar> &lookup, QDateTime &startDate, float weight,
                           int barRange, BarData::BarLength barLength)
{
  DbPlugin db;
  if (db.openChart(symbol))
  {
    qDebug("DbPlugin::getIndexHistory: cannot open symbol chart");
    db.close();
    return;
  }

  BarData *bar = new BarData(symbol);
  bar->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar, startDate);
  db.close();
  
  int loop;
  for (loop = 0; loop < (int) bar->count(); loop++)
  {
    QDateTime dt;
    bar->getDate(loop, dt);
    QString s = dt.toString("yyyyMMddhhmmss");
    Bar *r = lookup.find(s);
    if (! r)
    {
      r = new Bar;
      r->setDate(dt);
      r->setOpen(bar->getOpen(loop) * weight);
      r->setHigh(bar->getHigh(loop) * weight);
      r->setLow(bar->getLow(loop) * weight);
      r->setClose(bar->getClose(loop) * weight);
      r->setOI(1);
      r->getDateTimeString(FALSE, s);
      lookup.insert(s, r);
    }
    else
    {
      r->setOpen(r->getOpen() + (bar->getOpen(loop) * weight));
      r->setHigh(r->getHigh() + (bar->getHigh(loop) * weight));
      r->setLow(r->getLow() + (bar->getLow(loop) * weight));
      r->setClose(r->getClose() + (bar->getClose(loop) * weight));
      r->setOI((int) r->getOI() + 1);
    }
  }

  delete bar;
  db.close();
}
예제 #3
0
void Spread::getHistory (BarData *barData, QDateTime &startDate, QString &fs, QString &ss,
                     int barRange, BarData::BarLength barLength)
{
  // get the first symbol bars
  QString s;
  DbPlugin db;
  if (db.openChart(fs))
  {
    qDebug("DbPlugin::getSpreadHistory: cannot open first symbol chart");
    db.close();
    return;
  }

  BarData *bar = new BarData(fs);
  bar->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar, startDate);
  db.close();

  // get the second symbol bars
  if (db.openChart(ss))
  {
    qDebug("DbPlugin::getSpreadHistory: cannot open second symbol chart");
    db.close();
    delete bar;
    return;
  }

  BarData *bar2 = new BarData(ss);
  bar2->setBarLength(barLength);
  db.setBarRange(barRange);
  db.getHistory(bar2, startDate);
  db.close();

  // create lookup dict for first symbol bars
  QDict<Bar> lookup;
  lookup.setAutoDelete(TRUE);
  int loop;
  for (loop = 0; loop < bar->count(); loop++)
  {
    Bar *r = new Bar;
    QDateTime dt;
    bar->getDate(loop, dt);
    r->setDate(dt);
    r->setClose(bar->getClose(loop));
    r->getDateTimeString(FALSE, s);
    lookup.insert(s, r);
  }

  // match all second symbol bars
  for (loop = bar2->count() - 1; loop > -1; loop--)
  {
    Bar r;
    QDateTime dt;
    bar2->getDate(loop, dt);
    s = dt.toString("yyyyMMddhhmmss");
    Bar *tr = lookup.find(s);
    if (tr)
    {
      double t = tr->getClose() - bar2->getClose(loop);
      r.setDate(dt);
      r.setOpen(t);
      r.setHigh(t);
      r.setLow(t);
      r.setClose(t);
      barData->prepend(r);
    }
  }

  delete bar;
  delete bar2;
}