plugins/quote/CME/CME.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include "CME.h"
00023 #include "Bar.h"
00024 #include "DBIndexItem.h"
00025 #include "Exchange.h"
00026 #include <qfile.h>
00027 #include <qtextstream.h>
00028 #include <qnetwork.h>
00029 #include <qdir.h>
00030 #include <qstringlist.h>
00031 #include <stdlib.h>
00032 #include <qsettings.h>
00033 #include <qfileinfo.h>
00034 #include <qlabel.h>
00035 
00036 
00037 CME::CME ()
00038 {
00039   pluginName = "CME";
00040   symbolCombo = 0;
00041   helpFile = "cme.html";
00042   downloadIndex = 0;
00043   cancelFlag = FALSE;
00044   
00045   fd.getCMESymbolList(symbolList);
00046   
00047   connect(this, SIGNAL(signalCopyFileDone(QString)), this, SLOT(fileDone(QString)));
00048   connect(this, SIGNAL(signalTimeout()), this, SLOT(timeoutError()));
00049   
00050   config.getData(Config::Home, file);
00051   file.append("/download");
00052   
00053   qInitNetworkProtocols();
00054   buildGui();
00055   loadSettings();
00056 
00057   resize(400, 400);
00058 }
00059 
00060 CME::~CME ()
00061 {
00062   plug.close();
00063   saveSettings();
00064 }
00065 
00066 void CME::update ()
00067 {
00068   plug.close();
00069   urlList.clear();
00070   symbolLoop = 0;
00071   errorLoop = 0;
00072 
00073   if (! methodCombo->currentText().compare("Today"))
00074   {
00075     urlList.append("ftp://ftp.cme.com//pub/settle/stlags");
00076     urlList.append("ftp://ftp.cme.com//pub/settle/stlcur");
00077     urlList.append("ftp://ftp.cme.com//pub/settle/stleqt");
00078     urlList.append("ftp://ftp.cme.com//pub/settle/stlint");
00079   }
00080   else
00081   {
00082     downloadIndex = 0;
00083     QString s;
00084     config.getData(Config::Home, s);
00085   
00086     // remove any old files
00087     QDir dir(s);
00088     int loop;
00089     for (loop = 2; loop < (int) dir.count(); loop++)
00090     {
00091       QString t = dir.absPath() + "/" + dir[loop];
00092       QFileInfo fi(t);
00093       if (fi.isDir())
00094         continue;
00095       
00096       if (! fi.extension(TRUE).compare("zip"))
00097       {
00098         dir.remove(fi.absFilePath());
00099         continue;
00100       }
00101     
00102       if (! fi.extension(TRUE).compare("eod"))
00103         dir.remove(fi.absFilePath());
00104     }
00105 
00106     file2 = s;
00107     s.append("/download.zip");
00108     file = s;
00109 
00110     s = "ftp://ftp.cme.com//pub/hist_eod/";
00111     s.append(symbolCombo->currentText().lower());
00112     s.append("ytd.zip");
00113     urlList.append(s);
00114   }
00115 
00116   startDownload();
00117 }
00118 
00119 void CME::startDownload ()
00120 {
00121   QString s = tr("Downloading ");
00122   s.append(urlList[symbolLoop]);
00123   printStatusLogMessage(s);
00124 
00125   copyFile(urlList[symbolLoop], file);
00126 }
00127 
00128 void CME::fileDone (QString d)
00129 {
00130   if (d.length())
00131   {
00132     qDebug(d.latin1());
00133     printStatusLogMessage(d);
00134     printStatusLogMessage(stringDone);
00135     downloadComplete();
00136     return;
00137   }
00138 
00139   if (! methodCombo->currentText().compare("Today"))
00140   {
00141     parseToday();
00142     
00143     symbolLoop++;
00144     
00145     if (symbolLoop >= (int) urlList.count())
00146     {
00147       printStatusLogMessage(stringDone);
00148       downloadComplete();
00149       return;
00150     }
00151 
00152     startDownload();    
00153   }
00154   else
00155   {
00156     parseHistory();
00157     printStatusLogMessage(stringDone);
00158     downloadComplete();
00159   }
00160 }
00161 
00162 void CME::timeoutError ()
00163 {
00164   errorLoop++;
00165   if (errorLoop == retrySpin->value())
00166   {
00167     QString s(tr("Timeout: retry limit skipping file"));
00168     printStatusLogMessage(s);
00169   
00170     errorLoop = 0;
00171     
00172     if (! methodCombo->currentText().compare("Today"))
00173     {
00174       symbolLoop++;
00175       if (symbolLoop >= (int) urlList.count())
00176       {
00177         printStatusLogMessage(stringDone);
00178         downloadComplete();
00179         return;
00180       }
00181 
00182       startDownload();
00183     }
00184   }
00185   else
00186   {
00187     QString s = tr("Timeout: retry ") + QString::number(errorLoop + 1);
00188     printStatusLogMessage(s);
00189     startDownload();
00190   }
00191 }
00192 
00193 void CME::parseToday ()
00194 {
00195   QFile f(file);
00196   if (! f.open(IO_ReadOnly))
00197     return;
00198   QTextStream stream(&f);
00199 
00200   QString s = stream.readLine();
00201   s = s.stripWhiteSpace();
00202   QString s2 = "PRICES AS OF ";
00203   int p = s.contains(s2);
00204   s.remove(0, p + s2.length() - 1);
00205   QString date = s.left(8);
00206   QStringList dl = QStringList::split("/", date, FALSE);
00207   date = "20";
00208   date.append(dl[2]);
00209   date.append(dl[0]);
00210   date.append(dl[1]);
00211 
00212   while(stream.atEnd() == 0)
00213   {
00214     s = stream.readLine();
00215     s = s.stripWhiteSpace();
00216 
00217     if (s.contains("FC CME FEEDER CATTLE"))
00218     {
00219       while(stream.atEnd() == 0)
00220       {
00221         s = stream.readLine();
00222         s = s.stripWhiteSpace();
00223 
00224         if (s.contains("TOTAL"))
00225           break;
00226 
00227         QStringList l = QStringList::split(" ", s, FALSE);
00228         if (l.count() != 11)
00229           continue;
00230 
00231         l.prepend(date);
00232         l.prepend("FC");
00233         saveTodayData(l);
00234       }
00235 
00236       continue;
00237     }
00238 
00239     if (s.contains("LB CME LUMBER FUTURES"))
00240     {
00241       while(stream.atEnd() == 0)
00242       {
00243         s = stream.readLine();
00244         s = s.stripWhiteSpace();
00245 
00246         if (s.contains("TOTAL"))
00247           break;
00248 
00249         QStringList l = QStringList::split(" ", s, FALSE);
00250         if (l.count() != 11)
00251           continue;
00252 
00253         l.prepend(date);
00254         l.prepend("LB");
00255         saveTodayData(l);
00256       }
00257 
00258       continue;
00259     }
00260 
00261     if (s.contains("LC CME LIVE CATTLE FUTURES"))
00262     {
00263       while(stream.atEnd() == 0)
00264       {
00265         s = stream.readLine();
00266         s = s.stripWhiteSpace();
00267 
00268         if (s.contains("TOTAL"))
00269           break;
00270 
00271         QStringList l = QStringList::split(" ", s, FALSE);
00272         if (l.count() != 11)
00273           continue;
00274 
00275         l.prepend(date);
00276         l.prepend("LC");
00277         saveTodayData(l);
00278       }
00279 
00280       continue;
00281     }
00282 
00283     if (s.contains("LH CME LEAN HOG FUTURES"))
00284     {
00285       while(stream.atEnd() == 0)
00286       {
00287         s = stream.readLine();
00288         s = s.stripWhiteSpace();
00289 
00290         if (s.contains("TOTAL"))
00291           break;
00292 
00293         QStringList l = QStringList::split(" ", s, FALSE);
00294         if (l.count() != 11)
00295           continue;
00296 
00297         l.prepend(date);
00298         l.prepend("LN");
00299         saveTodayData(l);
00300       }
00301 
00302       continue;
00303     }
00304 
00305     if (s.contains("PB CME FROZEN PORK BELLY FUTURES"))
00306     {
00307       while(stream.atEnd() == 0)
00308       {
00309         s = stream.readLine();
00310         s = s.stripWhiteSpace();
00311 
00312         if (s.contains("TOTAL"))
00313           break;
00314 
00315         QStringList l = QStringList::split(" ", s, FALSE);
00316         if (l.count() != 11)
00317           continue;
00318 
00319         l.prepend(date);
00320         l.prepend("PB");
00321         saveTodayData(l);
00322       }
00323 
00324       continue;
00325     }
00326 
00327     if (s.contains("AD CME AUSTRALIAN DOLLAR FUTURES"))
00328     {
00329       while(stream.atEnd() == 0)
00330       {
00331         s = stream.readLine();
00332         s = s.stripWhiteSpace();
00333 
00334         if (s.contains("TOTAL"))
00335           break;
00336 
00337         QStringList l = QStringList::split(" ", s, FALSE);
00338         if (l.count() != 11)
00339           continue;
00340 
00341         l.prepend(date);
00342         l.prepend("AD");
00343         saveTodayData(l);
00344       }
00345 
00346       continue;
00347     }
00348 
00349     if (s.contains("NB CME BRITISH POUND FUTURES"))
00350     {
00351       while(stream.atEnd() == 0)
00352       {
00353         s = stream.readLine();
00354         s = s.stripWhiteSpace();
00355 
00356         if (s.contains("TOTAL"))
00357           break;
00358 
00359         QStringList l = QStringList::split(" ", s, FALSE);
00360         if (l.count() != 11)
00361           continue;
00362 
00363         l.prepend(date);
00364         l.prepend("NB");
00365         saveTodayData(l);
00366       }
00367 
00368       continue;
00369     }
00370 
00371     if (s.contains("CD CME CANADIAN DOLLAR FUTURES"))
00372     {
00373       while(stream.atEnd() == 0)
00374       {
00375         s = stream.readLine();
00376         s = s.stripWhiteSpace();
00377 
00378         if (s.contains("TOTAL"))
00379           break;
00380 
00381         QStringList l = QStringList::split(" ", s, FALSE);
00382         if (l.count() != 11)
00383           continue;
00384 
00385         l.prepend(date);
00386         l.prepend("CD");
00387         saveTodayData(l);
00388       }
00389 
00390       continue;
00391     }
00392 
00393     if (s.contains("EC CME EURO FX FUTURES"))
00394     {
00395       while(stream.atEnd() == 0)
00396       {
00397         s = stream.readLine();
00398         s = s.stripWhiteSpace();
00399 
00400         if (s.contains("TOTAL"))
00401           break;
00402 
00403         QStringList l = QStringList::split(" ", s, FALSE);
00404         if (l.count() != 11)
00405           continue;
00406 
00407         l.prepend(date);
00408         l.prepend("EC");
00409         saveTodayData(l);
00410       }
00411 
00412       continue;
00413     }
00414 
00415     if (s.contains("JY CME JAPANESE YEN FUTURES"))
00416     {
00417       while(stream.atEnd() == 0)
00418       {
00419         s = stream.readLine();
00420         s = s.stripWhiteSpace();
00421 
00422         if (s.contains("TOTAL"))
00423           break;
00424 
00425         QStringList l = QStringList::split(" ", s, FALSE);
00426         if (l.count() != 11)
00427           continue;
00428 
00429         l.prepend(date);
00430         l.prepend("JY");
00431         saveTodayData(l);
00432       }
00433 
00434       continue;
00435     }
00436 
00437     if (s.contains("SF CME SWISS FRANC FUTURES"))
00438     {
00439       while(stream.atEnd() == 0)
00440       {
00441         s = stream.readLine();
00442         s = s.stripWhiteSpace();
00443 
00444         if (s.contains("TOTAL"))
00445           break;
00446 
00447         QStringList l = QStringList::split(" ", s, FALSE);
00448         if (l.count() != 11)
00449           continue;
00450 
00451         l.prepend(date);
00452         l.prepend("SF");
00453         saveTodayData(l);
00454       }
00455 
00456       continue;
00457     }
00458 
00459     if (s.contains("ES CME E-MINI S&P 500 FUTURES"))
00460     {
00461       while(stream.atEnd() == 0)
00462       {
00463         s = stream.readLine();
00464         s = s.stripWhiteSpace();
00465 
00466         if (s.contains("TOTAL"))
00467           break;
00468 
00469         QStringList l = QStringList::split(" ", s, FALSE);
00470         if (l.count() != 11)
00471           continue;
00472 
00473         l.prepend(date);
00474         l.prepend("ES");
00475         saveTodayData(l);
00476       }
00477 
00478       continue;
00479     }
00480 
00481     if (s.contains("GI CME GSCI FUTURES"))
00482     {
00483       while(stream.atEnd() == 0)
00484       {
00485         s = stream.readLine();
00486         s = s.stripWhiteSpace();
00487 
00488         if (s.contains("TOTAL"))
00489           break;
00490 
00491         QStringList l = QStringList::split(" ", s, FALSE);
00492         if (l.count() != 11)
00493           continue;
00494 
00495         l.prepend(date);
00496         l.prepend("GI");
00497         saveTodayData(l);
00498       }
00499 
00500       continue;
00501     }
00502 
00503     if (s.contains("ND CME NASDAQ-100 FUTURES"))
00504     {
00505       while(stream.atEnd() == 0)
00506       {
00507         s = stream.readLine();
00508         s = s.stripWhiteSpace();
00509 
00510         if (s.contains("TOTAL"))
00511           break;
00512 
00513         QStringList l = QStringList::split(" ", s, FALSE);
00514         if (l.count() != 11)
00515           continue;
00516 
00517         l.prepend(date);
00518         l.prepend("ND");
00519         saveTodayData(l);
00520       }
00521 
00522       continue;
00523     }
00524 
00525     if (s.contains("NQ CME E-MINI NASDAQ-100 FUTURES"))
00526     {
00527       while(stream.atEnd() == 0)
00528       {
00529         s = stream.readLine();
00530         s = s.stripWhiteSpace();
00531 
00532         if (s.contains("TOTAL"))
00533           break;
00534 
00535         QStringList l = QStringList::split(" ", s, FALSE);
00536         if (l.count() != 11)
00537           continue;
00538 
00539         l.prepend(date);
00540         l.prepend("NQ");
00541         saveTodayData(l);
00542       }
00543 
00544       continue;
00545     }
00546 
00547     if (s.contains("SP CME S&P 500 FUTURES"))
00548     {
00549       while(stream.atEnd() == 0)
00550       {
00551         s = stream.readLine();
00552         s = s.stripWhiteSpace();
00553 
00554         if (s.contains("TOTAL"))
00555           break;
00556 
00557         QStringList l = QStringList::split(" ", s, FALSE);
00558         if (l.count() != 11)
00559           continue;
00560 
00561         l.prepend(date);
00562         l.prepend("SP");
00563         saveTodayData(l);
00564       }
00565 
00566       continue;
00567     }
00568 
00569     if (s.contains("ED CME EURODOLLAR FUTURES"))
00570     {
00571       while(stream.atEnd() == 0)
00572       {
00573         s = stream.readLine();
00574         s = s.stripWhiteSpace();
00575 
00576         if (s.contains("TOTAL"))
00577           break;
00578 
00579         QStringList l = QStringList::split(" ", s, FALSE);
00580         if (l.count() != 11)
00581           continue;
00582 
00583         l.prepend(date);
00584         l.prepend("ED");
00585         saveTodayData(l);
00586       }
00587     }
00588   }
00589 
00590   f.close();
00591 }
00592 
00593 void CME::parseHistory ()
00594 {
00595   QString s2 = file2;
00596   s2.append("/");
00597   s2.append(symbolCombo->currentText().lower());
00598   s2.append("ytd.eod");
00599   QDir dir(s2);
00600   dir.remove(s2);
00601 
00602   QString s = "unzip ";
00603   s.append(file);
00604   s.append(" -d ");
00605   s.append(file2);
00606   if (system(s))
00607     return;
00608 
00609   QFile f(s2);
00610   if (! f.open(IO_ReadOnly))
00611   {
00612     QString s(tr("could not open parse history file"));
00613     printStatusLogMessage(s);
00614     return;
00615   }
00616   QTextStream stream(&f);
00617   
00618   while(stream.atEnd() == 0)
00619   {
00620     s = stream.readLine();
00621     s = s.stripWhiteSpace();
00622     if (! s.length())
00623       continue;
00624 
00625     Setting set;
00626 
00627     // date
00628     s2 = s.mid(31, 6);
00629     s2.prepend("20");
00630     s2.append("000000");
00631     QString ts = "Date";
00632     set.setData(ts, s2);
00633 
00634     // csymbol
00635     s2 = s.mid(37, 2);
00636     ts = "CSymbol";
00637     set.setData(ts, s2);
00638 
00639     // symbol
00640     s2 = s.mid(37, 2);
00641     s2.append("20");
00642     s2.append(s.mid(41, 2));
00643 
00644     QString month = s.mid(43, 2);
00645     switch (month.toInt())
00646     {
00647       case 1:
00648         month = "F";
00649         break;
00650       case 2:
00651         month = "G";
00652         break;
00653       case 3:
00654         month = "H";
00655         break;
00656       case 4:
00657         month = "J";
00658         break;
00659       case 5:
00660         month = "K";
00661         break;
00662       case 6:
00663         month = "M";
00664         break;
00665       case 7:
00666         month = "N";
00667         break;
00668       case 8:
00669         month = "Q";
00670         break;
00671       case 9:
00672         month = "U";
00673         break;
00674       case 10:
00675         month = "V";
00676         break;
00677       case 11:
00678         month = "X";
00679         break;
00680       default:
00681         month = "Z";
00682         break;
00683     }
00684     s2.append(month);
00685     ts = "Symbol";
00686     set.setData(ts, s2);
00687 
00688     ts = "Month";
00689     set.setData(ts, month);
00690 
00691     QString dec = s.mid(30, 1);
00692     
00693     // fix decimal for JY
00694     ts = "CSymbol";
00695     set.getData(ts, s2);
00696     if (! s2.compare("JY"))
00697       dec = QString::number(dec.toInt() - 2);
00698 
00699     // open
00700     s2 = s.mid(53, 9);
00701     s2 = s2.insert(s2.length() - dec.toInt(), ".");
00702     ts = "Open";
00703     set.setData(ts, s2);
00704 
00705     // high
00706     s2 = s.mid(73, 9);
00707     s2 = s2.insert(s2.length() - dec.toInt(), ".");
00708     ts = "High";
00709     set.setData(ts, s2);
00710 
00711     // low
00712     s2 = s.mid(83, 9);
00713     s2 = s2.insert(s2.length() - dec.toInt(), ".");
00714     ts = "Low";
00715     set.setData(ts, s2);
00716 
00717     // close
00718     s2 = s.mid(113, 9);
00719     s2 = s2.insert(s2.length() - dec.toInt(), ".");
00720     ts = "Close";
00721     set.setData(ts, s2);
00722 
00723     // volume
00724     s2 = s.mid(122, 7);
00725     ts = "Volume";
00726     set.setData(ts, s2);
00727 
00728     // oi
00729     s2 = s.mid(136, 7);
00730     ts = "OI";
00731     set.setData(ts, s2);
00732 
00733     parse(set);
00734   }
00735 
00736   f.close();
00737 }
00738 
00739 void CME::saveTodayData (QStringList &l)
00740 {
00741   Setting set;
00742 
00743   QString symbol = l[0];
00744   symbol.append("20");
00745   QString s = l[2];
00746   s.remove(0, 3);
00747   symbol.append(s);
00748 
00749   s = l[2];
00750   s.truncate(3);
00751   QString month;
00752   while (1)
00753   {
00754     if (! s.compare("JAN"))
00755     {
00756       month = "F";
00757       break;
00758     }
00759 
00760     if (! s.compare("FEB"))
00761     {
00762       month = "G";
00763       break;
00764     }
00765 
00766     if (! s.compare("MAR"))
00767     {
00768       month = "H";
00769       break;
00770     }
00771 
00772     if (! s.compare("APR"))
00773     {
00774       month = "J";
00775       break;
00776     }
00777 
00778     if (! s.compare("MAY"))
00779     {
00780       month = "K";
00781       break;
00782     }
00783 
00784     if (! s.compare("JUN"))
00785     {
00786       month = "M";
00787       break;
00788     }
00789 
00790     if (! s.compare("JLY"))
00791     {
00792       month = "N";
00793       break;
00794     }
00795 
00796     if (! s.compare("AUG"))
00797     {
00798       month = "Q";
00799       break;
00800     }
00801 
00802     if (! s.compare("SEP"))
00803     {
00804       month = "U";
00805       break;
00806     }
00807 
00808     if (! s.compare("OCT"))
00809     {
00810       month = "V";
00811       break;
00812     }
00813 
00814     if (! s.compare("NOV"))
00815     {
00816       month = "X";
00817       break;
00818     }
00819 
00820     month = "Z";
00821 
00822     break;
00823   }
00824   symbol.append(month);
00825 
00826   QString ts = "CSymbol";
00827   set.setData(ts, l[0]);
00828   ts = "Symbol";
00829   set.setData(ts, symbol);
00830 
00831   s = l[1];
00832   s.append("000000");
00833   ts = "Date";
00834   set.setData(ts, s);
00835 
00836   ts = "Month";
00837   set.setData(ts, month);
00838   
00839   QString open = l[3];
00840   QString high = l[4];
00841   QString low = l[5];
00842   QString close = l[7];
00843   QString volume = l[9];
00844   QString oi = l[12];
00845 
00846   s = l[0];
00847   if (! s.compare("JY"))
00848   {
00849     setTFloat(open, FALSE);
00850     open = QString::number(tfloat);
00851     if (open.toFloat() > 9999)
00852       open.insert(1, ".");
00853     else
00854       open.prepend(".");
00855 
00856     setTFloat(high, FALSE);
00857     high = QString::number(tfloat);
00858     if (high.toFloat() > 9999)
00859       high.insert(1, ".");
00860     else
00861       high.prepend(".");
00862 
00863     setTFloat(low, FALSE);
00864     low = QString::number(tfloat);
00865     if (low.toFloat() > 9999)
00866       low.insert(1, ".");
00867     else
00868       low.prepend(".");
00869 
00870     setTFloat(close, FALSE);
00871     close = QString::number(tfloat);
00872     if (close.toFloat() > 9999)
00873       close.insert(1, ".");
00874     else
00875       close.prepend(".");
00876   }
00877 
00878   ts = "Open";
00879   set.setData(ts, open);
00880   ts = "High";
00881   set.setData(ts, high);
00882   ts = "Low";
00883   set.setData(ts, low);
00884   ts = "Close";
00885   set.setData(ts, close);
00886   ts = "Volume";
00887   set.setData(ts, volume);
00888   ts = "OI";
00889   set.setData(ts, oi);
00890 
00891   parse(set);
00892 }
00893 
00894 void CME::parse (Setting &data)
00895 {
00896   QString s;
00897   QString ts = "CSymbol";
00898   data.getData(ts, s);
00899   if (fd.setSymbol(s))
00900     return;
00901 
00902   Bar bar;
00903   ts = "Date";
00904   data.getData(ts, s);
00905   if (bar.setDate(s))
00906   {
00907     QString ss = "Bad date " + s;
00908     printStatusLogMessage(ss);
00909     return;
00910   }
00911 
00912   // open
00913   ts = "Open";
00914   data.getData(ts, s);
00915   if (setTFloat(s, FALSE))
00916     return;
00917   else
00918     bar.setOpen(tfloat);
00919 
00920   // high
00921   ts = "High";
00922   data.getData(ts, s);
00923   if (setTFloat(s, FALSE))
00924     return;
00925   else
00926     bar.setHigh(tfloat);
00927 
00928   // low
00929   ts = "Low";
00930   data.getData(ts, s);
00931   if (setTFloat(s, FALSE))
00932     return;
00933   else
00934     bar.setLow(tfloat);
00935 
00936   // close
00937   ts = "Close";
00938   data.getData(ts, s);
00939   if (setTFloat(s, FALSE))
00940     return;
00941   else
00942     bar.setClose(tfloat);
00943 
00944   // volume
00945   ts = "Volume";
00946   data.getData(ts, s);
00947   if (setTFloat(s, FALSE))
00948     return;
00949   else
00950     bar.setVolume(tfloat);
00951 
00952   // oi
00953   ts = "OI";
00954   data.getData(ts, s);
00955   if (setTFloat(s, FALSE))
00956     return;
00957   else
00958     bar.setOI((int) tfloat);
00959 
00960   if (bar.verify())
00961     return;
00962 
00963   QString s2;
00964   fd.getSymbol(s2);
00965   s = "Futures/CME/" + s2;
00966   QString path;
00967   createDirectory(s, path);
00968   if (! path.length())
00969   {
00970     QString ss(tr("Unable to create futures directory"));
00971     printStatusLogMessage(ss);
00972     return;
00973   }
00974 
00975   ts = "Symbol";
00976   QString ts2;
00977   data.getData(ts, ts2);
00978 //  s = tr("Updating ") + ts2;
00979 //  printStatusLogMessage(s);
00980 
00981   data.getData(ts, ts2);
00982   s = path + "/" + ts2;
00983   if (plug.open(s, chartIndex))
00984   {
00985     QString ss(tr("Could not open db."));
00986     printStatusLogMessage(ss);
00987     return;
00988   }
00989 
00990   QFileInfo fi(s);
00991   QString fn = fi.fileName();
00992 
00993   DBIndexItem item;
00994   chartIndex->getIndexItem(fn, item);
00995   item.getSymbol(s);      
00996   if (! s.length())
00997   {
00998     if (plug.createNewFutures())
00999       return;
01000 
01001     chartIndex->getIndexItem(fn, item);
01002 
01003     s = QString::number(Exchange::CME);
01004     item.setExchange(s);
01005 
01006     item.setQuotePlugin(pluginName);
01007 
01008     chartIndex->setIndexItem(fn, item);
01009   }
01010 
01011   plug.setBar(bar);
01012              
01013   plug.close();
01014 
01015   emit signalWakeup();
01016 }
01017 
01018 void CME::cancelUpdate ()
01019 {
01020   if (op)
01021   {
01022     timer->stop();
01023     op->stop();
01024   }
01025   
01026   downloadComplete();
01027   printStatusLogMessage(stringCanceled);
01028 }
01029 
01030 void CME::buildGui ()
01031 {
01032   setCaption(tr("CME Prefs"));
01033   
01034   methodList.append("Today");
01035   methodList.append("History");
01036 
01037   QLabel *label = new QLabel(tr("Method"), baseWidget);
01038   grid->addWidget(label, 0, 0);
01039   
01040   methodCombo = new QComboBox(baseWidget);
01041   methodCombo->insertStringList(methodList, -1);
01042   QObject::connect(methodCombo, SIGNAL(activated(const QString &)), this, SLOT(methodChanged(const QString &)));
01043   grid->addWidget(methodCombo, 0, 1);
01044 
01045   label = new QLabel(tr("Symbol"), baseWidget);
01046   grid->addWidget(label, 1, 0);
01047 
01048   symbolCombo = new QComboBox(baseWidget);
01049   symbolCombo->insertStringList(symbolList, -1);
01050   grid->addWidget(symbolCombo, 1, 1);
01051 
01052   methodChanged(methodCombo->currentText());
01053 }
01054 
01055 void CME::loadSettings ()
01056 {
01057   QSettings settings;
01058   settings.beginGroup("/Qtstalker/CME plugin");
01059 
01060   QString s = settings.readEntry("/Method", "Today");
01061   methodCombo->setCurrentItem(methodList.findIndex(s));
01062 
01063   s = settings.readEntry("/Symbol", "AD");
01064   symbolCombo->setCurrentItem(symbolList.findIndex(s));
01065   
01066   s = settings.readEntry("/Retry", "3");
01067   retrySpin->setValue(s.toInt());
01068   
01069   s = settings.readEntry("/Timeout", "15");
01070   timeoutSpin->setValue(s.toInt());
01071   
01072   settings.endGroup();
01073 
01074   methodChanged(methodCombo->currentText());
01075 }
01076 
01077 void CME::saveSettings ()
01078 {
01079   QSettings settings;
01080   settings.beginGroup("/Qtstalker/CME plugin");
01081   
01082   settings.writeEntry("/Method", methodCombo->currentText());
01083   settings.writeEntry("/Symbol", symbolCombo->currentText());
01084   settings.writeEntry("/Retry", retrySpin->text());
01085   settings.writeEntry("/Timeout", timeoutSpin->text());
01086   
01087   settings.endGroup();
01088 }
01089 
01090 void CME::methodChanged (const QString & d)
01091 {
01092   if (! d.compare("Today"))
01093     symbolCombo->setEnabled(FALSE);
01094   else
01095     symbolCombo->setEnabled(TRUE);
01096 }
01097 
01098 //*************************************************************
01099 //*************************************************************
01100 //*************************************************************
01101 
01102 QuotePlugin * createQuotePlugin ()
01103 {
01104   CME *o = new CME;
01105   return ((QuotePlugin *) o);
01106 }
01107