Bitcoin Forum
April 26, 2024, 02:46:11 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help with getting started with mtgox api request  (Read 2496 times)
bittencoin (OP)
Member
**
Offline Offline

Activity: 83
Merit: 10


View Profile
April 15, 2013, 02:13:19 AM
 #1

Hello,

I want to create a very simple php based interface to display data from Mtgox api.  I don't like their trading interface, so I want to create a web page to arrange the displays to my liking. 

The link for the unofficial api documentation https://bitbucket.org/nitrous/mtgox-api/overview

As of now, I am stuck at the very first step of being able to retrieve data and display the data using the available example php code.  The code is unable to retrieve a very basic data dump.  Could someone give an working example to get me started.  I am trying to implement mtgox api version 2.  The only code that I modified to the standard code example are the path and the base definitions (highlighted in bold in the code below)

Thank you

Code:
<?php
 
function mtgox_query($path, array $req = array()) {
// API settings
$key 'my valid key';
$secret 'my secret code';
 
// generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems
$mt explode(' 'microtime());
$req['nonce'] = $mt[1].substr($mt[0], 26);
 
// generate the POST data string
$post_data http_build_query($req'''&');
 
$prefix '';
if (substr($path02) == '2/') {
$prefix substr($path2)."\0";
}
 
// generate the extra headers
$headers = array(
'Rest-Key: '.$key,
'Rest-Sign: '.base64_encode(hash_hmac('sha512'$prefix.$post_database64_decode($secret), true)),
);
 
// our curl handle (initialize if required)
static $ch null;
if (is_null($ch)) {
$ch curl_init();
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_USERAGENT'Mozilla/4.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
}
curl_setopt($chCURLOPT_URL'https://data.mtgox.com/api/2/'.$path); //Base URL
curl_setopt($chCURLOPT_POSTFIELDS$post_data);
curl_setopt($chCURLOPT_HTTPHEADER$headers);
curl_setopt($chCURLOPT_SSL_VERIFYPEERFALSE);
 
// run the query
$res curl_exec($ch);
if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
$dec json_decode($restrue);
if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
return $dec;
}
 
// example 1: get infos about the account, plus the list of rights we have access to
var_dump(mtgox_query('BTCUSD/money/ticker'));// PATH
 
// old api (get funds)
//var_dump(mtgox_query('0/getFunds.php'));
 
// trade example
// var_dump(mtgox_query('0/buyBTC.php', array('amount' => 1, 'price' => 15)));

I run this code on a PC with xampp installed.  The output error is

Code:
array(3) { ["result"]=> string(5) "error" ["error"]=> string(45) "Identification required to access private API" ["token"]=> string(29) "login_error_invalid_rest_sign" }
"Bitcoin: the cutting edge of begging technology." -- Giraffe.BTC
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714142771
Hero Member
*
Offline Offline

Posts: 1714142771

View Profile Personal Message (Offline)

Ignore
1714142771
Reply with quote  #2

1714142771
Report to moderator
1714142771
Hero Member
*
Offline Offline

Posts: 1714142771

View Profile Personal Message (Offline)

Ignore
1714142771
Reply with quote  #2

1714142771
Report to moderator
1714142771
Hero Member
*
Offline Offline

Posts: 1714142771

View Profile Personal Message (Offline)

Ignore
1714142771
Reply with quote  #2

1714142771
Report to moderator
botsofbitcoin
Member
**
Offline Offline

Activity: 62
Merit: 10



View Profile WWW
April 15, 2013, 02:25:39 AM
 #2

I hope it's not this but I assume you're using a valid API key and code where it says to?

See my localbitcoins ads here: https://localbitcoins.com/accounts/profile/botsofbitcoin/?ch=2mk
Visit Bots of Bitcoin here: http://www.botsofbitcoin.com/
Follow on Twitter: @botsofbitcoin
bittencoin (OP)
Member
**
Offline Offline

Activity: 83
Merit: 10


View Profile
April 15, 2013, 05:57:38 AM
Last edit: April 15, 2013, 06:09:57 PM by bittencoin
 #3

I hope it's not this but I assume you're using a valid API key and code where it says to?

I use the API key and secret code created from my account, not shown here of course. And did just switch them around just to be sure after you raised that possibility.

UPDATE:

I found the error/fix here https://bitcointalk.org/index.php?topic=164404.msg1845894#msg1845894
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!