#include "../data_framework/GenericTosData.h" #include "ReportAlertsThread.h" #include "TestAlerts.h" ///////////////////////////////////////////////////////////////////// // TestAlert ///////////////////////////////////////////////////////////////////// class TestAlert : public DataNode { private: const std::string _symbol; GenericTosDataNode *_tosData; time_t _blackout; void onWakeup(int msgId); TestAlert(DataNodeArgument const &args); friend class DataNode; public: static DataNodeLink *find(std::string const &symbol); }; DataNodeLink *TestAlert::find(std::string const &symbol) { TestAlert *node; return findHelper(NULL, 0, node, symbol); } TestAlert::TestAlert(DataNodeArgument const &args) : _symbol(args.getStringValue()), _blackout(0) { addAutoLink(GenericTosDataNode::find(this, 0, _tosData, _symbol)); } void TestAlert::onWakeup(int msgId) { const time_t now = time(NULL); if ((now > _blackout) && _tosData->getValid() && (_tosData->getLast().newPrint)) { // $time goes off once per minute. but we can't be sure about round off // error, so we say anything after 59 seconds is good. We could skip the // _blackout period for $time, but we want other symbols to go off at // about the same rate. Note, since most stocks do not trade every // second, the actual period may be larger than expected, even for high // volume stocks. _blackout = now + 59; static const std::string category = "BRAD-qqqq"; std::string info = "symbol="; info += urlEncode(_symbol); info += "&w_id=100"; ReportAlertsThread::getInstance()->reportAlert(category, info); } } static std::vector< DataNodeLink * > cleanup; void initTestAlerts() { cleanup.push_back(TestAlert::find("$TIME")); // As of 3/26/2011 MSFT trades more times per day than any other NASDAQ // stock. cleanup.push_back(TestAlert::find("MSFT")); // Same for C on the NYSE. cleanup.push_back(TestAlert::find("C")); }