Bitcoin Forum
December 04, 2016, 08:25:46 AM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Google Apps and MTGox Trade Data [resolved]  (Read 1637 times)
rizzn
Member
**
Offline Offline

Activity: 106



View Profile WWW
June 27, 2011, 05:16:53 AM
 #1

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?

founding editor for the SiliconANGLE network.
Bitrated user: rizzn.
1480839946
Hero Member
*
Offline Offline

Posts: 1480839946

View Profile Personal Message (Offline)

Ignore
1480839946
Reply with quote  #2

1480839946
Report to moderator
1480839946
Hero Member
*
Offline Offline

Posts: 1480839946

View Profile Personal Message (Offline)

Ignore
1480839946
Reply with quote  #2

1480839946
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1480839946
Hero Member
*
Offline Offline

Posts: 1480839946

View Profile Personal Message (Offline)

Ignore
1480839946
Reply with quote  #2

1480839946
Report to moderator
1480839946
Hero Member
*
Offline Offline

Posts: 1480839946

View Profile Personal Message (Offline)

Ignore
1480839946
Reply with quote  #2

1480839946
Report to moderator
1480839946
Hero Member
*
Offline Offline

Posts: 1480839946

View Profile Personal Message (Offline)

Ignore
1480839946
Reply with quote  #2

1480839946
Report to moderator
rizzn
Member
**
Offline Offline

Activity: 106



View Profile WWW
June 27, 2011, 05:54:16 AM
 #2

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.

founding editor for the SiliconANGLE network.
Bitrated user: rizzn.
bitfreak!
Legendary
*
Offline Offline

Activity: 1514


electronic [r]evolution


View Profile WWW
June 27, 2011, 07:02:28 AM
 #3

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'];

XCN: CYsvPpb2YuyAib5ay9GJXU8j3nwohbttTz | BTC: 18MWPVJA9mFLPFT3zht5twuNQmZBDzHoWF
Cryptonite - 1st mini-blockchain altcoin | BitShop - digital shop script
Web Developer - PHP, SQL, JS, AJAX, JSON, XML, RSS, HTML, CSS
rizzn
Member
**
Offline Offline

Activity: 106



View Profile WWW
June 27, 2011, 07:05:56 AM
 #4

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:

<?php
    $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?)

founding editor for the SiliconANGLE network.
Bitrated user: rizzn.
rizzn
Member
**
Offline Offline

Activity: 106



View Profile WWW
June 27, 2011, 07:13:22 AM
 #5

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.

founding editor for the SiliconANGLE network.
Bitrated user: rizzn.
rizzn
Member
**
Offline Offline

Activity: 106



View Profile WWW
June 27, 2011, 07:19:50 AM
 #6

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.

founding editor for the SiliconANGLE network.
Bitrated user: rizzn.
bitfreak!
Legendary
*
Offline Offline

Activity: 1514


electronic [r]evolution


View Profile WWW
June 27, 2011, 07: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.

XCN: CYsvPpb2YuyAib5ay9GJXU8j3nwohbttTz | BTC: 18MWPVJA9mFLPFT3zht5twuNQmZBDzHoWF
Cryptonite - 1st mini-blockchain altcoin | BitShop - digital shop script
Web Developer - PHP, SQL, JS, AJAX, JSON, XML, RSS, HTML, CSS
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!