Bitcoin Forum
November 15, 2024, 04:11:20 PM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: I need a line of C code  (Read 4498 times)
cdnbcguy (OP)
Full Member
***
Offline Offline

Activity: 128
Merit: 100


View Profile WWW
July 23, 2011, 02:28:15 AM
 #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?

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
Hero Member
*****
Offline Offline

Activity: 588
Merit: 500



View Profile
July 23, 2011, 04:47:42 AM
 #2

It'll take quite a bit more than one line of code.

3KzNGwzRZ6SimWuFAgh4TnXzHpruHMZmV8
wumpus
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1022

No Maps for These Territories


View Profile
July 24, 2011, 12:49:21 AM
 #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...

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 FileBackup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
martin
Full Member
***
Offline Offline

Activity: 150
Merit: 100



View Profile WWW
July 24, 2011, 02:29:23 PM
 #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.
Pieter Wuille
Legendary
*
Offline Offline

Activity: 1072
Merit: 1181


View Profile WWW
July 24, 2011, 02:53:46 PM
 #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.

I do Bitcoin stuff.
wumpus
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1022

No Maps for These Territories


View Profile
July 24, 2011, 05: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.



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 FileBackup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
wumpus
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1022

No Maps for These Territories


View Profile
July 26, 2011, 06: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...

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 FileBackup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
TYDIRocks
Full Member
***
Offline Offline

Activity: 213
Merit: 100


View Profile
July 29, 2011, 03:44:33 AM
 #8

You could make a simple webpage that has the prices from various places and have the client just grab it from there.

Import new address/private keys with ease: https://bitcointalk.org/index.php?topic=101161
wumpus
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1022

No Maps for These Territories


View Profile
July 31, 2011, 05: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?

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 FileBackup Wallet to an external storage or the (encrypted!) cloud. Use a separate offline wallet for storing larger amounts.
cdnbcguy (OP)
Full Member
***
Offline Offline

Activity: 128
Merit: 100


View Profile WWW
July 31, 2011, 07:09:16 PM
 #10

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.
vector76
Member
**
Offline Offline

Activity: 70
Merit: 18


View Profile
August 03, 2011, 10: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.

cdnbcguy (OP)
Full Member
***
Offline Offline

Activity: 128
Merit: 100


View Profile WWW
August 12, 2011, 12:51:05 PM
 #12

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
Sr. Member
****
Offline Offline

Activity: 352
Merit: 250

Firstbits: 1m8xa


View Profile WWW
August 21, 2011, 01:56:25 PM
 #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);
}


BTC : 1CcpmVDLvR7DgA5deFGScoNhiEtiJnh6H4 - LTC : LYTnoXAHNsemMB2jhCSi1znQqnfupdRkSy
Bitcoin-otc
BitBin - earn bitcoins with your pastes!
antares
Hero Member
*****
Offline Offline

Activity: 518
Merit: 500


View Profile
January 16, 2012, 11: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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!