cdnbcguy (OP)
|
|
July 23, 2011, 02:28:15 AM |
|
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?
|
Annona ad! Please keep in mind that there is nothing wrong with Bitcoin itself. All it's scandals are caused by wonky websites and sleazy people exploiting it. The light attracts bugs. When all this bullshit drys up and blows away, Bitcoin will be stronger than ever.
|
|
|
error
|
|
July 23, 2011, 04:47:42 AM |
|
It'll take quite a bit more than one line of code.
|
3KzNGwzRZ6SimWuFAgh4TnXzHpruHMZmV8
|
|
|
wumpus
|
|
July 24, 2011, 12:49:21 AM |
|
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...
|
Bitcoin Core developer [PGP] Warning: For most, coin loss is a larger risk than coin theft. A disk can die any time. Regularly back up your wallet through File → Backup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
|
|
|
martin
|
|
July 24, 2011, 02:29:23 PM |
|
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.
|
|
|
|
Pieter Wuille
Legendary
Offline
Activity: 1072
Merit: 1181
|
|
July 24, 2011, 02:53:46 PM |
|
Maybe you could follow this idea: http://forum.bitcoin.org/index.php?topic=8773.0In 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.
|
I do Bitcoin stuff.
|
|
|
wumpus
|
|
July 24, 2011, 05:22:43 PM |
|
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.0In 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.
|
Bitcoin Core developer [PGP] Warning: For most, coin loss is a larger risk than coin theft. A disk can die any time. Regularly back up your wallet through File → Backup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
|
|
|
wumpus
|
|
July 26, 2011, 06:54:49 AM |
|
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...
|
Bitcoin Core developer [PGP] Warning: For most, coin loss is a larger risk than coin theft. A disk can die any time. Regularly back up your wallet through File → Backup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
|
|
|
TYDIRocks
|
|
July 29, 2011, 03:44:33 AM |
|
You could make a simple webpage that has the prices from various places and have the client just grab it from there.
|
|
|
|
wumpus
|
|
July 31, 2011, 05:57:33 PM |
|
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?
|
Bitcoin Core developer [PGP] Warning: For most, coin loss is a larger risk than coin theft. A disk can die any time. Regularly back up your wallet through File → Backup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
|
|
|
cdnbcguy (OP)
|
|
July 31, 2011, 07:09:16 PM |
|
I only actually wanted to get the price every hour or so...
|
Annona ad! Please keep in mind that there is nothing wrong with Bitcoin itself. All it's scandals are caused by wonky websites and sleazy people exploiting it. The light attracts bugs. When all this bullshit drys up and blows away, Bitcoin will be stronger than ever.
|
|
|
|
cdnbcguy (OP)
|
|
August 12, 2011, 12:51:05 PM |
|
It'll take quite a bit more than one line of code.
Point. Ruby has spoiled me.
|
Annona ad! Please keep in mind that there is nothing wrong with Bitcoin itself. All it's scandals are caused by wonky websites and sleazy people exploiting it. The light attracts bugs. When all this bullshit drys up and blows away, Bitcoin will be stronger than ever.
|
|
|
Matoking
|
|
August 21, 2011, 01:56:25 PM |
|
I use this library to parse JSON : http://ereilin.tumblr.com/post/6857765046/lightweight-json-parser-serializer-class-for-qtDump 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) 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); }
|
|
|
|
antares
|
|
January 16, 2012, 11:22:20 PM |
|
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.
|
|
|
|
|