Author

Topic: Google Apps and MTGox Trade Data [resolved] (Read 1936 times)

legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
June 27, 2011, 02:50:39 AM
#7
Glad to see you got it solved. It had me stumped for a a while too. I have no idea why Mt. Gox have made it so hard to use their API.
member
Activity: 108
Merit: 10
Quick update: I lied - I didn't go to sleep, solved it using your useragent CURL idea, and used my own server as Google's data source.  I'll update the thread tomorrow with the breakdown and solution in case anyone else tries to do this.

Thanks a ton.
member
Activity: 108
Merit: 10
EDIT: I'm not sure what you're trying to do but you might want to check out this thread: http://forum.bitcoin.org/index.php?topic=22886

It's Google's App Scripting language - it's used to do fancy stuff to just about everything on their platform. I was specifically using it to import live JSON data into a spreadsheet.
member
Activity: 108
Merit: 10
That's a bit annoying - about to head off to bed.  Google Apps (from what I'm reading in the forums) doesn't allow you to set the USERAGENT, so I'll probably have to load a script up onto my server to mirror the MTGOX feed, and then try to load that in as a data source to Google Apps.

If I have time to do this tomorrow, I'll update the thread as to whether it works. I was having issues getting Curl to grab and mirror the data when using MTgox as a direct source, or using this as a source: http://btc.jalder.com/mtgox.php (which, theoretically, wouldn't be subject to the USERAGENT limitation).

Incidentally, I also had problems getting Google to not time out on the Jalder.com source as well. The only conclusion that I can reach is that Google hates MTgox.

That this is the only conclusion I can reach is a sure-fire sign I need some sleep. I'll attack it again in the morning.

Thanks for the pointers.

(incidentally, this is the simple Curl script I was using:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    //curl_setopt($ch, CURLOPT_URL, "http://btc.jalder.com/mtgox.php");
    curl_setopt($ch, CURLOPT_URL, "http://mtgox.com/code/data/ticker.php");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);
    echo $output;
?>


What you're saying is to simply add:

curl_setopt($ch, CURLOPT_USERAGENT, "php bot");

And I should be copacetic?)
legendary
Activity: 1536
Merit: 1000
electronic [r]evolution
EDIT: I'm not sure what you're trying to do but you might want to check out this thread: http://forum.bitcoin.org/index.php?topic=22886

Mt. Gox recently changed their API and it seems a user-agent now needs to be specified.
Try using cURL:

Code:
function mtgox_trade_data($json_url) {

  // Initializing curl
  $ch = curl_init();
  
  // Setting curl options
  curl_setopt($ch, CURLOPT_URL, $json_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_USERAGENT, "php bot");

  // Getting jSON result string
  $result = curl_exec($ch);
  
  // close curl and json file
  curl_close($ch);

  // return cURL result
  return $result;
  
}

Then you can save the result to an associative array like this:

Code:
$json_result = mtgox_trade_data($mtgox_ticker_url);

if (!empty($json_result)) {
  $mt_gox_ticker = json_decode($json_result, true);
}

// use array like this: $mt_gox_ticker['ticker']['sell'];
member
Activity: 108
Merit: 10
As a follow up - I went ahead and wrote functions for all the trade APIs I could find out there, and mtGox is the only one still not resolving. Did a bit more research, found some folks who said that the best way to retrieve data was thru the WS methods (which is quite a bit more complex than I wanted to make for a simple spreadsheet).

Any help is appreciated.
member
Activity: 108
Merit: 10
Update: Wasn't able to pull in mtgox trade data into Google App Scripts (so that it could be manipulated as live data in Google Spreadsheets), so I wound up making a mirror script on my personal domain. I had to use the Curl option to set the user agent (something you can't control, to the best of my knowledge, within Google). That, inelegantly, solved my problem.

tl;dr: Google App Scripting can't grab mtgox live trade data without going through an intermediary script. Solution is in this thread.


I'm trying to write a simple script to pull in the latest MTgox Trade Data into a spreadsheet.

Here's what my function looks like:

function mtGoxTradeData() {
  var jsondata = UrlFetchApp.fetch("https://mtgox.com/code/data/ticker.php");
  var object = Utilities.jsonParse(jsondata.getContentText());
  return object.ticker.last;
  
}


For some reason - retrieval of MTGox's API data always times out. When I do the same on ExchangeBitCoins, it gets the data flawlessly.

function exchangeBitCoinsTradeData() {
  var jsondata = UrlFetchApp.fetch("https://www.exchangebitcoins.com/data/ticker");
  var object = Utilities.jsonParse(jsondata.getContentText());
  return object.ticker.last;
  
}


Not sure what the deal is. Anyone experienced with Google's app platform?
Jump to: