コード例 #1
0
ファイル: dbservice.cpp プロジェクト: mailtostanley/bftrader
void DbService::batchWriteTicks()
{
    g_sm->checkCurrentOn(ServiceMgr::DB);

    if( tickCount_ == 0 ){
        return;
    }

    leveldb::WriteOptions options;
    leveldb::WriteBatch batch;
    for (int i = 0; i < tickCount_; i++) {
        void* curTick = tickArray[i].curTick;
        void* preTick = tickArray[i].preTick;

        BfTickData bfItem;
        CtpUtils::translateTick(curTick, preTick, &bfItem);

        // tick里面的exchange不一定有=
        QString exchange = bfItem.exchange().c_str();
        if (exchange.trimmed().length() == 0) {
            void* contract = g_sm->ctpMgr()->getContract(bfItem.symbol().c_str());
            exchange = CtpUtils::getExchangeFromContract(contract);
            bfItem.set_exchange(exchange.toStdString());
        }

        // key: tick.exchange.symbol.actiondata.ticktime
        std::string key = QString().sprintf("tick.%s.%s.%s.%s", bfItem.exchange().c_str(), bfItem.symbol().c_str(), bfItem.actiondate().c_str(), bfItem.ticktime().c_str()).toStdString();
        std::string val = bfItem.SerializeAsString();

        batch.Put(key, val);
    }
    db_->Write(options, &batch);

    tickCount_ = 0;
}
コード例 #2
0
ファイル: pushservice.cpp プロジェクト: aha100trader/bftrader
void PushService::onGotTick(void* curTick, void* preTick)
{
    g_sm->checkCurrentOn(ServiceMgr::PUSH);

    BfTickData data;
    CtpUtils::translateTick(curTick, preTick, &data);

    // tick里面的exchange不一定有=
    QString exchange = data.exchange().c_str();
    if (exchange.trimmed().length() == 0) {
        void* contract = g_sm->gatewayMgr()->getContract(data.symbol().c_str());
        exchange = CtpUtils::getExchangeFromContract(contract);
        data.set_exchange(exchange.toStdString());
    }

    for (auto client : clients_) {
        if (client->tickHandler() && client->subscribled(data.symbol(), data.exchange())) {
            client->OnTick(data);
        }
    }
}