Ejemplo n.º 1
0
//--------------------------------------------------------------
void testApp::draw(){
	ofSetColor(0xffffff);

	string tstamp = getTimestampAsString();
	unsigned long epoch = parseTimestamp( tstamp );
	
	stringstream s;
	s << "tstamp " << tstamp << endl << "epoch " << epoch;
	ofDrawBitmapString( s.str(), 20, 20);	

	stringstream s2;
	s2 << "palette #1 no. colors " << p1.getColorCount() << endl << "pallete #2 no. colors: " << p2.getColorCount();
	ofDrawBitmapString( s2.str(), 20, 50);	
	
	drawPalette(p1, 10, 80);
	drawPalette(p3, 10, 100);
	drawPalette(p4, 10, 120);
	drawPalette(p2, 10, 160);
	
	if(last < epoch ) {
		last = epoch;
		p3.rotateRight(1);
		p4.rotateLeft(1);
	}
}
bool UserConfigStorageMysqlImpl::queryUserID(const ten_id_t& tenid,
        const string& token,
        uint32_t expire_timestamp,
        common::UserID* user_id,
        base::ErrorCode* ec)
{
    LOG(debug, "query user id: tenid=" << tenid << ", token=" << token);

    for ( ; ; )
    {
        mysql_connector_pool::MySQLScopedConnector conn(*pool_);
        conn.initConnection(ec);                                                                                                                                           
        RETURN_IF_ERROR_WITH(ec, false);
        try
        {
            auto_ptr<sql::PreparedStatement> sp_statement(conn->prepareStatement(
                        "SELECT * FROM "TB_APNS" WHERE token=?"));
            sp_statement->setString(1, token);
            auto_ptr<sql::ResultSet> sp_result(sp_statement->executeQuery());                                                                                                                                
            if (sp_result.get())
            {
                while (sp_result->next())
                {
                    string url = sp_result->getString("user_id");
                    user_id->parseFromString(url);
                    string time_str = sp_result->getString("timestamp");
                    time_t timestamp;

                    if (user_id->isLocalDomain() && getTenID(user_id->uid) == tenid &&
                            parseTimestamp(time_str, &timestamp) && timestamp < expire_timestamp)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        catch (sql::SQLException& e)
        {
            if (e.getErrorCode() != CR_SERVER_GONE_ERROR)
            {
                LOG(error,
                        e.what() << "(error code: " << e.getErrorCode() << ", state: " << e.getSQLState() << " )");
                RETURN_ERROR_WITH(ec,
                        (mysql_connector_pool::MySQLErrors)(e.getErrorCode() ? e.getErrorCode() : -1),
                        e.what(),
                        NULL);
            }                                                                                                                                                                                                    
        }
    }
    return false;
}
Ejemplo n.º 3
0
/**
 * Get the next line from a log file.
 * Return whether the seek actually occurred.
 */
bool LogFile::nextLine()
{
    bool rv=true;

    if(instream == NULL) {
        openLogfile();
        /* Recurse to skip a line */
        rv=nextLine();
        assert(rv);
    }

    std::getline(*instream, line);
    rv = !(instream->fail() || line.empty() || parseTimestamp() == -1);

    return rv;
}
Ejemplo n.º 4
0
    void DataLoader::run(const QString& fileName, const QString& symbol, int depth)
    {
        QFile file(fileName);
        if (!file.open(QIODevice::ReadOnly))
        {
            emit resultReady(true, file.errorString());
            return;
        }

        std::unique_ptr< BookData > d(new BookData);

        const int expectedSize{ 3 + depth * 6 };

        while (!file.atEnd())
        {
            auto fields(file.readLine().split(';'));
            if (fields.size() != expectedSize)
            {
                emit resultReady(true, "bad data");
                return ;
            }

            QString fSymbol(fields[2]);
            if (fSymbol.remove("\"") != symbol)
            {
                continue;
            }

            QString fTimestamp(fields[0]);
            uint64_t timestamp{ parseTimestamp(fTimestamp.remove("\"")) };
            if (timestamp == 0)
            {
                emit resultReady(true, "bad timestamp (" + fTimestamp + ")");
                return ;
            }

            d->push_back(std::make_pair(timestamp, DepthOfMarket()));
            auto& e(d->back().second);

            for (int level = 0; level < depth; ++level)
            {
                const size_t rindex(depth - level - 1 + 3);
                const size_t index(level + 3);

                const auto& bidP(fields[rindex]);
                if (!bidP.isEmpty())
                {
                    Level lvl;
                    lvl.price = bidP.toDouble();
                    lvl.volume = fields[rindex + depth * 2].toDouble();
                    e.side< Bid >().push_back(lvl);
                }

                const auto& askP(fields[index + depth]);
                if (!askP.isEmpty())
                {
                    Level lvl;
                    lvl.price = askP.toDouble();
                    lvl.volume = fields[index + depth * 3].toDouble();
                    e.side< Ask >().push_back(lvl);
                }
            }
        }

        {
            qDebug() << "data loaded " << d->size();

            QMutexLocker lock(&_dataMutex);
            _data = std::move(d);
        }

        emit resultReady();
    }
Ejemplo n.º 5
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int32_t OTTrade::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
    int32_t returnVal = 0;

    // Here we call the parent class first.
    // If the node is found there, or there is some error,
    // then we just return either way.  But if it comes back
    // as '0', then nothing happened, and we'll continue executing.
    //
    // -- Note you can choose not to call the parent if
    // you don't want to use any of those xml tags.
    // As I do below, in the case of OTAccount.
    //
    if (0 != (returnVal = ot_super::ProcessXMLNode(xml))) return returnVal;

    if (!strcmp("trade", xml->getNodeName())) {
        m_strVersion = xml->getAttributeValue("version");
        tradesAlreadyDone_ = atoi(xml->getAttributeValue("completedNoTrades"));

        SetTransactionNum(
            String::StringToLong(xml->getAttributeValue("transactionNum")));

        const std::string creationStr = xml->getAttributeValue("creationDate");
        const std::string validFromStr = xml->getAttributeValue("validFrom");
        const std::string validToStr = xml->getAttributeValue("validTo");

        int64_t creation = parseTimestamp(creationStr);
        int64_t validFrom = parseTimestamp(validFromStr);
        int64_t validTo = parseTimestamp(validToStr);

        SetCreationDate(OTTimeGetTimeFromSeconds(creation));
        SetValidFrom(OTTimeGetTimeFromSeconds(validFrom));
        SetValidTo(OTTimeGetTimeFromSeconds(validTo));

        String activated(xml->getAttributeValue("hasActivated"));

        if (activated.Compare("true"))
            hasTradeActivated_ = true;
        else
            hasTradeActivated_ = false;

        const String notaryID(xml->getAttributeValue("notaryID")),
            nymID(xml->getAttributeValue("nymID")),
            instrumentDefinitionID(
                xml->getAttributeValue("instrumentDefinitionID")),
            assetAcctID(xml->getAttributeValue("assetAcctID")),
            currencyTypeID(xml->getAttributeValue("currencyTypeID")),
            currencyAcctID(xml->getAttributeValue("currencyAcctID"));

        const Identifier NOTARY_ID(notaryID), NYM_ID(nymID),
            INSTRUMENT_DEFINITION_ID(instrumentDefinitionID),
            ASSET_ACCT_ID(assetAcctID), CURRENCY_TYPE_ID(currencyTypeID),
            CURRENCY_ACCT_ID(currencyAcctID);

        SetNotaryID(NOTARY_ID);
        SetSenderNymID(NYM_ID);
        SetInstrumentDefinitionID(INSTRUMENT_DEFINITION_ID);
        SetSenderAcctID(ASSET_ACCT_ID);
        SetCurrencyID(CURRENCY_TYPE_ID);
        SetCurrencyAcctID(CURRENCY_ACCT_ID);

        otLog3 << "\n\nTrade. Transaction Number: " << m_lTransactionNum
               << "   Completed # of Trades: " << tradesAlreadyDone_ << "\n";

        otWarn << " Creation Date: " << creation
               << "   Valid From: " << validFrom << "\n Valid To: " << validTo
               << "\n"
                  " instrumentDefinitionID: " << instrumentDefinitionID
               << "\n assetAcctID: " << assetAcctID << "\n"
                                                       " NotaryID: " << notaryID
               << "\n NymID: " << nymID << "\n "
                                           " currencyTypeID: " << currencyTypeID
               << "\n currencyAcctID: " << currencyAcctID << "\n ";

        returnVal = 1;
    }

    if (!strcmp("stopOrder", xml->getNodeName())) {
        String sign(xml->getAttributeValue("sign"));

        if (sign.Compare("0")) {
            stopSign_ = 0; // Zero means it isn't a stop order. So why is the
                           // tag in the file?
            otErr << "Strange: Stop order tag found in trade, but sign "
                     "character set to 0.\n"
                     "(Zero means: NOT a stop order.)\n";
            return (-1);
        }
        else if (sign.Compare("<"))
            stopSign_ = '<';
        else if (sign.Compare(">"))
            stopSign_ = '>';
        else {
            stopSign_ = 0;
            otErr << "Unexpected or nonexistent value in stop order sign: "
                  << sign << "\n";
            return (-1);
        }

        // Now we know the sign is properly formed, let's grab the price value.

        stopPrice_ = String::StringToLong(xml->getAttributeValue("price"));

        String activated(xml->getAttributeValue("hasActivated"));

        if (activated.Compare("true"))
            stopActivated_ = true;
        else
            stopActivated_ = false;

        otLog3 << "\n\nStop order -- "
               << (stopActivated_ ? "Already activated" : "Will activate")
               << " when price " << (stopActivated_ ? "was" : "reaches") << " "
               << (('<' == stopSign_) ? "LESS THAN" : "GREATER THAN") << ": "
               << stopPrice_ << ".\n";

        returnVal = 1;
    }
    else if (!strcmp("offer", xml->getNodeName())) {
        if (!Contract::LoadEncodedTextField(xml, marketOffer_)) {
            otErr << "Error in OTTrade::ProcessXMLNode: offer field without "
                     "value.\n";
            return (-1); // error condition
        }

        returnVal = 1;
    }

    return returnVal;
}
Ejemplo n.º 6
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int32_t OTOffer::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
    int32_t nReturnVal = 0;

    // Here we call the parent class first.
    // If the node is found there, or there is some error,
    // then we just return either way.  But if it comes back
    // as '0', then nothing happened, and we'll continue executing.
    //
    // -- Note you can choose not to call the parent if
    // you don't want to use any of those xml tags.
    // As I do below, in the case of OTAccount.
    // if (nReturnVal = Contract::ProcessXMLNode(xml))
    //    return nReturnVal;

    if (!strcmp("marketOffer", xml->getNodeName())) {
        m_strVersion = xml->getAttributeValue("version");

        String strIsSelling;
        strIsSelling = xml->getAttributeValue("isSelling");
        if (strIsSelling.Compare("true"))
            m_bSelling = true;
        else
            m_bSelling = false;

        m_strContractType.Set((m_bSelling ? "ASK" : "BID"));

        const String strNotaryID(xml->getAttributeValue("notaryID")),
            strInstrumentDefinitionID(
                xml->getAttributeValue("instrumentDefinitionID")),
            strCurrencyTypeID(xml->getAttributeValue("currencyTypeID"));

        const Identifier NOTARY_ID(strNotaryID),
            INSTRUMENT_DEFINITION_ID(strInstrumentDefinitionID),
            CURRENCY_TYPE_ID(strCurrencyTypeID);

        SetNotaryID(NOTARY_ID);
        SetInstrumentDefinitionID(INSTRUMENT_DEFINITION_ID);
        SetCurrencyID(CURRENCY_TYPE_ID);

        const String strScale = xml->getAttributeValue("marketScale");
        const int64_t lScale =
            strScale.Exists() ? strScale.ToLong() : 0; // if it doesn't exist,
                                                       // the 0 here causes the
                                                       // below error to fire.

        if (!isPowerOfTen(lScale)) {
            otOut << "OTOffer::ProcessXMLNode: Failure: marketScale *must* be "
                     "1, or a power of 10. Instead I got: " << lScale << ".\n";
            return (-1);
        }
        else
            SetScale(lScale);

        const String strPriceLimit = xml->getAttributeValue("priceLimit");
        const int64_t lPriceLimit = strPriceLimit.Exists()
                                        ? strPriceLimit.ToLong()
                                        : 0; // if it doesn't exist, the 0 here
                                             // causes the below error to fire.

        // NOTE: Market Orders (new) have a 0 price, so this error condition was
        // changed.
        if (!strPriceLimit.Exists())
        //      if (lPriceLimit < 1)
        {
            otOut << "OTOffer::ProcessXMLNode: Failure: priceLimit *must* be "
                     "provided(" << lPriceLimit << ").\n";
            return (-1);
        }
        else
            SetPriceLimit(lPriceLimit);

        const String strTotal = xml->getAttributeValue("totalAssetsOnOffer");
        const int64_t lTotal =
            strTotal.Exists() ? strTotal.ToLong() : 0; // if it doesn't exist,
                                                       // the 0 here causes the
                                                       // below error to fire.
        if (lTotal < 1) {
            otOut << "OTOffer::ProcessXMLNode: Failure: totalAssetsOnOffer "
                     "*must* be larger than 0. Instead I got: " << lTotal
                  << ".\n";
            return (-1);
        }
        else
            SetTotalAssetsOnOffer(lTotal);

        const String strFinished = xml->getAttributeValue("finishedSoFar");
        const int64_t lFinished = strFinished.Exists()
                                      ? strFinished.ToLong()
                                      : 0; // if it doesn't exist, the 0 here
                                           // causes the below error to fire.
        if (lFinished < 0) {
            otOut << "OTOffer::ProcessXMLNode: Failure: finishedSoFar *must* "
                     "be 0 or larger. Instead I got: " << lFinished << ".\n";
            return (-1);
        }
        else
            SetFinishedSoFar(lFinished);

        const String strMinInc = xml->getAttributeValue("minimumIncrement");
        // if it doesn't exist, the 0 here causes the below error to fire.
        const int64_t lMinInc = strMinInc.Exists() ? strMinInc.ToLong() : 0;

        if ((lMinInc < 1) || (lMinInc > lTotal)) // Minimum increment cannot
                                                 // logically be higher than the
                                                 // total assets on offer...
        {
            otOut << "OTOffer::ProcessXMLNode: Failure: minimumIncrement "
                     "*must* be 1 or larger, \n"
                     "and must also be less than the total assets on offer. "
                     "Instead I got: " << lMinInc << ".\n";
            return (-1);
        }
        else
            SetMinimumIncrement(lMinInc);

        const String strTransNum = xml->getAttributeValue("transactionNum");
        const int64_t lTransNum =
            strTransNum.Exists() ? strTransNum.ToLong() : 0;

        SetTransactionNum(lTransNum);

        const String str_valid_from = xml->getAttributeValue("validFrom");
        const String str_valid_to = xml->getAttributeValue("validTo");

        int64_t tValidFrom =
            str_valid_from.Exists() ? parseTimestamp(str_valid_from.Get()) : 0;
        int64_t tValidTo =
            str_valid_to.Exists() ? parseTimestamp(str_valid_to.Get()) : 0;

        if ((tValidTo < tValidFrom) && (tValidTo != 0)) {
            otOut << "OTOffer::" << __FUNCTION__ << ": Failure: validTo date ("
                  << tValidFrom << ") cannot be earlier than "
                                   "validFrom date (" << tValidTo << ").\n";
            return (-1);
        }

        SetValidFrom(OTTimeGetTimeFromSeconds(tValidFrom));
        SetValidTo(OTTimeGetTimeFromSeconds(tValidTo));

        otLog4 << "\n\nOffer. Transaction Number: " << m_lTransactionNum
               << "\n Valid From: " << tValidFrom << "\n Valid To: " << tValidTo
               << "\n"
                  " InstrumentDefinitionID: " << strInstrumentDefinitionID
               << "\n  CurrencyTypeID: " << strCurrencyTypeID
               << "\n NotaryID: " << strNotaryID
               << "\n"
                  " Price Limit: " << GetPriceLimit()
               << ",  Total Assets on Offer: " << GetTotalAssetsOnOffer()
               << ",  " << (m_bSelling ? "sold" : "bought")
               << " so far: " << GetFinishedSoFar() << "\n "
                                                       " Scale: " << GetScale()
               << ".   Minimum Increment: " << GetMinimumIncrement()
               << ".  This offer is a" << (m_bSelling ? "n ASK" : " BID")
               << ".\n";

        nReturnVal = 1;
    }

    return nReturnVal;
}
Ejemplo n.º 7
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int32_t Cheque::ProcessXMLNode(IrrXMLReader*& xml)
{
    int32_t nReturnVal = 0;

    // Here we call the parent class first.
    // If the node is found there, or there is some error,
    // then we just return either way.  But if it comes back
    // as '0', then nothing happened, and we'll continue executing.
    //
    // -- Note you can choose not to call the parent if
    // you don't want to use any of those xml tags.
    // As I do below, in the case of OTAccount.
    // if (nReturnVal = Contract::ProcessXMLNode(xml))
    //    return nReturnVal;

    if (!strcmp("cheque", xml->getNodeName())) {
        String strHasRecipient = xml->getAttributeValue("hasRecipient");
        m_bHasRecipient = strHasRecipient.Compare("true");

        String strHasRemitter = xml->getAttributeValue("hasRemitter");
        m_bHasRemitter = strHasRemitter.Compare("true");

        m_strVersion = xml->getAttributeValue("version");
        m_lAmount = String::StringToLong(xml->getAttributeValue("amount"));

        SetTransactionNum(
            String::StringToLong(xml->getAttributeValue("transactionNum")));

        const std::string str_valid_from = xml->getAttributeValue("validFrom");
        const std::string str_valid_to = xml->getAttributeValue("validTo");

        SetValidFrom(parseTimestamp(str_valid_from));
        SetValidTo(parseTimestamp(str_valid_to));

        String strInstrumentDefinitionID(
            xml->getAttributeValue("instrumentDefinitionID")),
            strNotaryID(xml->getAttributeValue("notaryID")),
            strSenderAcctID(xml->getAttributeValue("senderAcctID")),
            strSenderNymID(xml->getAttributeValue("senderNymID")),
            strRecipientNymID(xml->getAttributeValue("recipientNymID")),
            strRemitterNymID(xml->getAttributeValue("remitterNymID")),
            strRemitterAcctID(xml->getAttributeValue("remitterAcctID"));

        Identifier INSTRUMENT_DEFINITION_ID(strInstrumentDefinitionID),
            NOTARY_ID(strNotaryID), SENDER_ACCT_ID(strSenderAcctID),
            SENDER_NYM_ID(strSenderNymID);

        SetInstrumentDefinitionID(INSTRUMENT_DEFINITION_ID);
        SetNotaryID(NOTARY_ID);
        SetSenderAcctID(SENDER_ACCT_ID);
        SetSenderNymID(SENDER_NYM_ID);

        // Recipient ID
        if (m_bHasRecipient)
            m_RECIPIENT_NYM_ID.SetString(strRecipientNymID);
        else
            m_RECIPIENT_NYM_ID.Release();

        // Remitter ID (for vouchers)
        if (m_bHasRemitter) {
            m_REMITTER_NYM_ID.SetString(strRemitterNymID);
            m_REMITTER_ACCT_ID.SetString(strRemitterAcctID);
        }
        else {
            m_REMITTER_NYM_ID.Release();
            m_REMITTER_ACCT_ID.Release();
        }

        otInfo << "\n\nCheque Amount: " << m_lAmount
               << ".  Transaction Number: " << m_lTransactionNum
               << "\n Valid From: " << str_valid_from
               << "\n Valid To: " << str_valid_to
               << "\n InstrumentDefinitionID: " << strInstrumentDefinitionID
               << "\n NotaryID: " << strNotaryID
               << "\n"
                  " senderAcctID: " << strSenderAcctID
               << "\n senderNymID: " << strSenderNymID << "\n "
                                                          " Has Recipient? "
               << (m_bHasRecipient ? "Yes" : "No")
               << ". If yes, NymID of Recipient: " << strRecipientNymID
               << "\n"
                  " Has Remitter? " << (m_bHasRemitter ? "Yes" : "No")
               << ". If yes, NymID/Acct of Remitter: " << strRemitterNymID
               << " / " << strRemitterAcctID << "\n";

        nReturnVal = 1;
    }
    else if (!strcmp("memo", xml->getNodeName())) {
        if (!Contract::LoadEncodedTextField(xml, m_strMemo)) {
            otErr << "Error in OTCheque::ProcessXMLNode: memo field without "
                     "value.\n";
            return (-1); // error condition
        }

        return 1;
    }

    return nReturnVal;
}