Author

Topic: I need a line of C code (Read 4498 times)

hero member
Activity: 518
Merit: 500
January 16, 2012, 06:22:20 PM
#14
why bother with the traffic or DDos?
MtGox maintains channels on Freenode, namely #mtgox-live which could be fetched. IRC is already implemented within bitcoin, so this would probably require even less code than fetching mtgox api(as mtgox api uses ssl, which makes the thing take that much code in the first place)

EDIT: I will make this patch later tonight and post it here, however youll have to wait since I'm still at work.
sr. member
Activity: 352
Merit: 250
Firstbits: 1m8xa
August 21, 2011, 08:56:25 AM
#13
I use this library to parse JSON :
http://ereilin.tumblr.com/post/6857765046/lightweight-json-parser-serializer-class-for-qt

Dump it and include it into your project like any other .cpp or .h file and use Json::parse() to do the parsing magic.

And before that I use QNetworkAccessManager to retrieve market data from Mt. Gox which I then parse using the above library.

This is how I parsed the ticker data in my cuteCoin application (it looks a bit crappy but works)

Code:
void Networking::updateTradeData()
{
    networkManager->get(QNetworkRequest(QUrl("https://mtgox.com/api/0/data/ticker.php")))->ignoreSslErrors();
    qDebug("GET https://mtgox.com/api/0/data/ticker.php");

    connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(tradeDataLoaded(QNetworkReply*)));
}

...

void Networking::tradeDataLoaded(QNetworkReply *reply)
{
    QByteArray replyBytes = reply->readAll();
    QString replyString = QString::fromUtf8(replyBytes);

    QString lastPrice;
    QString highPrice;
    QString lowPrice;

    qDebug("GET https://mtgox.com/api/0/data/ticker.php DONE!");

    bool parseSuccess;
    QVariantMap tradeData = Json::parse(replyString, parseSuccess).toMap();

    if (!parseSuccess) {
        qDebug("Failed to parse trade data");
        qDebug(QString("Returned : %1").arg(replyString).toAscii());
        return;
    }

    QVariantMap tickerData;
    tickerData = tradeData.value("ticker").toMap();

    lastPrice = tickerData.value("last").toString();
    highPrice = tickerData.value("high").toString();
    lowPrice = tickerData.value("low").toString();

    reply->deleteLater();

    disconnect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(tradeDataLoaded(QNetworkReply*)));

    tradeDataParsed(lastPrice, highPrice, lowPrice);
}

full member
Activity: 128
Merit: 100
August 12, 2011, 07:51:05 AM
#12
It'll take quite a bit more than one line of code.

Point. Ruby has spoiled me.
member
Activity: 70
Merit: 18
August 03, 2011, 05:21:01 AM
#11
Use curl to fetch a page into memory, as demonstrated here: http://curl.haxx.se/libcurl/c/getinmemory.html

Then point it at this url which has time-weighted prices: http://bitcoincharts.com/t/weighted_prices.json

Then write some code to parse out the currency and interval you want, or use a json library to do the parsing for you.

full member
Activity: 128
Merit: 100
July 31, 2011, 02:09:16 PM
#10
I only actually wanted to get the price every hour or so...
hero member
Activity: 812
Merit: 1022
No Maps for These Territories
July 31, 2011, 12:57:33 PM
#9
You could make a simple webpage that has the prices from various places and have the client just grab it from there.
And who pays for the bandwidth?
full member
Activity: 213
Merit: 100
July 28, 2011, 10:44:33 PM
#8
You could make a simple webpage that has the prices from various places and have the client just grab it from there.
hero member
Activity: 812
Merit: 1022
No Maps for These Territories
July 26, 2011, 01:54:49 AM
#7
Would XMPP be suitable for net-wide distribution of small messages such as exchange rate prices?

I'm afraid it needs an account per client though, which isn't very handy...
hero member
Activity: 812
Merit: 1022
No Maps for These Territories
July 24, 2011, 12:22:43 PM
#6
Exchanges could broadcast a message to the network, signed with their private key to ensure authenticity.
Incredible idea! That way, the exchange rates could be published through the network itself, instead of having to rely on centralized auxiliary sources.

Maybe you could follow this idea: http://forum.bitcoin.org/index.php?topic=8773.0

In short: allow anyone to publish an time-dependent exchange rate to another currency through https, and map changes in the exchange rate to virtual "interest" transactions in the client view.

Yes, I think this would be similar to my idea; at the time of a transaction coming in, attach the current exchange rates  to it as client metadata. There'd be some problems with this approach, though, for example what if you don't run the client for a while. You'd need historical exchange data to reconstruct the exchange rate at the time of the transaction... unless you really embed the exchange rates in the block chain, but that might be overkill and a waste of space.


legendary
Activity: 1072
Merit: 1181
July 24, 2011, 09:53:46 AM
#5
Maybe you could follow this idea: http://forum.bitcoin.org/index.php?topic=8773.0

In short: allow anyone to publish an time-dependent exchange rate to another currency through https, and map changes in the exchange rate to virtual "interest" transactions in the client view.
full member
Activity: 150
Merit: 100
July 24, 2011, 09:29:23 AM
#4
I wonder if there is some more efficient way of distributing the exchange real-time quote information that doesn't involve polling all of them all the time...

Exchanges could broadcast a message to the network, signed with their private key to ensure authenticity. That way clients which are interested just listen for broadcast messages and display the values contained within, if I remember correctly there is already support within the protocol for broadcasts but only the dev team can send them, so with only a little modification it should be possible to modify it so that anyone can send them.
hero member
Activity: 812
Merit: 1022
No Maps for These Territories
July 23, 2011, 07:49:21 PM
#3
Yes, it'd take somewhat more than one line of C++ code, at least to do it right. the biggest problem I see is that all clients would be requesting the MtGox API data all the time, resulting in possible DDoS. Also, it should be an option, because not everyone might want reveal to MtGox that they are running bitcoin...

Also, MtGox is only one of the exchanges, and people will probably want quotes for other currencies than the USD as well.

I wonder if there is some more efficient way of distributing the exchange real-time quote information that doesn't involve polling all of them all the time...
hero member
Activity: 588
Merit: 500
July 22, 2011, 11:47:42 PM
#2
It'll take quite a bit more than one line of code.
full member
Activity: 128
Merit: 100
July 22, 2011, 09:28:15 PM
#1
I am adding a few things to the excellent QT bitcoin client and I need a line of C code that will get me the price of BTC in USD from Mt Gox.

I'm kind of new to working with APIs (yes I know, no excuse, really...)

Can anyone help me with this, please?
Jump to: