Exemple #1
0
bool DlgMarkets::LowLevelLoadMarketList(QString qstrServerID, QString qstrNymID, mapIDName & the_map)
{
    if (qstrServerID.isEmpty() || qstrNymID.isEmpty())
        return false;
    // -----------------------------------
    OTDB::MarketList * pMarketList = LoadMarketListForServer(qstrServerID.toStdString());
    OTCleanup<OTDB::MarketList> theAngel(pMarketList);

    if (NULL != pMarketList)
    {
        size_t nMarketDataCount = pMarketList->GetMarketDataCount();

        for (size_t ii = 0; ii < nMarketDataCount; ++ii)
        {
            OTDB::MarketData * pMarketData = pMarketList->GetMarketData(ii);

            if (NULL == pMarketData) // Should never happen.
                continue;
            // -----------------------------------------------------------------------
            QString qstrMarketID    = QString::fromStdString(pMarketData->market_id);
            QString qstrScale       = QString::fromStdString(pMarketData->scale);
            // -----------------------------------------------------------------------
            QString qstrCompositeID = QString("%1,%2").arg(qstrMarketID).arg(qstrScale);
            // -----------------------------------------------------------------------
            // This multimap will have multiple markets of the same key (from
            // different servers.)
            //
            m_mapMarkets.insertMulti(qstrCompositeID, VPtr<OTDB::MarketData>::asQVariant(pMarketData->clone()));
            // -----------------------------------------------------------------------
            // Whereas this map will only have a single entry for each key. (Thus
            // we only add it here if it's not already present.)
            //
            mapIDName::iterator it_map = the_map.find(qstrCompositeID);

            if (the_map.end() == it_map)
            {
                const std::string str_asset_name    = OTAPI_Wrap::GetAssetType_Name(pMarketData->asset_type_id);
                const std::string str_currency_name = OTAPI_Wrap::GetAssetType_Name(pMarketData->currency_type_id);
                // --------------------------
                QString qstrMarketName = QString("%1 for %2").
                        arg(QString::fromStdString(str_asset_name)).
                        arg(QString::fromStdString(str_currency_name));
                // ---------------------------
                the_map.insert(qstrCompositeID, qstrMarketName);
            }
            // ---------------------------
        } // for
    }
    // -----------------------------------
    return true;
}
Exemple #2
0
int32_t CmdShowMarkets::run(string server)
{
    if (!checkServer("server", server)) {
        return -1;
    }

    OTDB::MarketList* marketList = loadMarketList(server);
    if (nullptr == marketList) {
        otOut << "Error: cannot load market list.\n";
        return -1;
    }

    int32_t items = marketList->GetMarketDataCount();
    if (0 > items) {
        otOut << "Error: cannot load market list item count.\n";
        return -1;
    }

    if (0 == items) {
        otOut << "The market list is empty.\n";
        return 0;
    }

    cout << "Index\tScale\tMarket\t\t\t\t\t\tAsset\t\t\t\t\t\tCurrency\n";

    for (int32_t i = 0; i < items; i++) {
        OTDB::MarketData* marketData = marketList->GetMarketData(i);
        if (nullptr == marketData) {
            otOut << "Error: cannot load market data at index " << i << ".\n";
            return -1;
        }

        cout << i << "\t" << marketData->scale << "\tM "
             << marketData->market_id << "\tA "
             << marketData->instrument_definition_id << "\tC "
             << marketData->currency_type_id << "\n";
    }

    return 1;
}