Bitcoin Forum

Other => Beginners & Help => Topic started by: BitvoinVender on May 22, 2013, 07:27:48 PM



Title: MTGOX api, send simple not working. [solved ]
Post by: BitvoinVender on May 22, 2013, 07:27:48 PM
I found a php script for mtgox's api that is working for me.

https://github.com/daftspunk/php-mtgox-v1


here is my script, some of the functions work, some dont...

Trying to get a send simple to a bitcoin address.


http://pastebin.com/wihZqAcW


Title: Re: MTGOX api, send simple not working. returns blank page
Post by: Navles on May 22, 2013, 07:40:08 PM
Hello,

Do you have OTP enabled for your account?

-Navles


Title: Re: MTGOX api, send simple not working. returns blank page
Post by: Navles on May 22, 2013, 07:42:49 PM
By the way,

I noticed MT. GOX changed their API URL from "https://mtgox.com/api/" to "https://data.mtgox.com/api/".

Try changing the API base url to "https://data.mtgox.com/api/" in mtgox_api_base.php  line 10.

Let me know if that works.

EDIT:

Also dont forget to enable 'withdraw' rights in the security center.

https://f.cloud.github.com/assets/738972/49695/9967f3ca-5976-11e2-903d-66674970cc0b.png

-Navles


Title: Re: MTGOX api, send simple not working. returns blank page
Post by: BitvoinVender on May 22, 2013, 08:03:22 PM
I just entered the data. and still returned a blank page.

tinkering


Title: Re: MTGOX api, send simple not working. returns blank page
Post by: BitvoinVender on May 22, 2013, 08:07:50 PM
actually adding data. breaks the get account info as well

const api_url = 'https://data.mtgox.com/api/'; FAILD

const api_url = 'https://mtgox.com/api/'; returns only on the get account into, not send simple


might this have something to do with the https?


Title: Re: MTGOX api, send simple not working. returns blank page
Post by: Navles on May 22, 2013, 08:43:52 PM
M... weird.

I'm setting up a test environment as we speak.

I will get back to you in a second.

-Navles


Title: Re: MTGOX api, send simple not working. returns blank page
Post by: Navles on May 22, 2013, 09:11:54 PM
I wrote some test code and got the following exception:

"Parameter amount_int or amount is required" - Which is the default exception if something is wrong. Currently i have no BTC in my account, so i suspect that's why i get this error. Can you please try with the following code?

START CODE
<?php
include 'mtgox_api_base.php';
include 'mtgox_private_api.php';

$private = new MtGox_Private_Api();
$private->set_currency('EUR'); // CHANGE TO USD IF YOU NEED USD!!
$private->set_authentication("KEY", "SECRET");
try{
    $send_simple = $private->withdraw_coins("BTC ADDRESS", "AMOUNT (eg. 0)");
    print_r($send_simple);
}catch(Exception $e) {
    print_r($e);
}

?>
END CODE

Please let me know if this works.

-Navles


Title: Re: MTGOX api, send simple not working. returns blank page
Post by: BitvoinVender on May 22, 2013, 10:53:41 PM
used your script and getting the following error as well. ( i do have btc in the account.)

Exception Object ( [message:protected] => Parameter amount_int or amount is required [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/admin/atm/mtgox_api_base.php [line:protected] => 79 [trace:Exception:private] => Array (
  • => Array ( [file] => /var/www/admin/atm/mtgox_api_base.php [line] => 70 [function] => process_api_response [class] => MtGox_Api_Base [type] => -> [args] => Array (
  • => Array ( [result] => error [error] => Parameter amount_int or amount is required [token] => unknown_error ) ) ) [1] => Array ( [file] => /var/www/admin/atm/mtgox_private_api.php [line] => 46 [function] => send_request [class] => MtGox_Api_Base [type] => -> [args] => Array (
  • => 1/generic/bitcoin/send_simple ) ) [2] => Array ( [file] => /var/www/admin/atm/history.php [line] => 13 [function] => withdraw_coins [class] => MtGox_Private_Api [type] => -> [args] => Array (
  • => 14XnxAbrNZkkXRX76MS2S5JnJ1hUbgCs1Y [1] => 1 ) ) ) [previous:Exception:private] => )


post an address and I can send some btc for testing.


Title: Re: MTGOX api, send simple not working. returns blank page
Post by: BitvoinVender on May 22, 2013, 11:04:19 PM
if I use https://data.mtgox.com/api/

I get the following error;

Exception Object ( [message:protected] => Could not get reply: Unknown SSL protocol error in connection to data.mtgox.com:443 [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/admin/atm/mtgox_api_base.php [line:protected] => 111 [trace:Exception:private] => Array (
  • => Array ( [file] => /var/www/admin/atm/mtgox_api_base.php [line] => 69 [function] => post_api_request [class] => MtGox_Api_Base [type] => -> [args] => Array (
  • => 1/generic/bitcoin/send_simple [1] => Array ( ) ) ) [1] => Array ( [file] => /var/www/admin/atm/mtgox_private_api.php [line] => 46 [function] => send_request [class] => MtGox_Api_Base [type] => -> [args] => Array (
  • => 1/generic/bitcoin/send_simple ) ) [2] => Array ( [file] => /var/www/admin/atm/history.php [line] => 13 [function] => withdraw_coins [class] => MtGox_Private_Api [type] => -> [args] => Array (
  • => 14XnxAbrNZkkXRX76MS2S5JnJ1hUbgCs1Y [1] => 1 ) ) ) [previous:Exception:private] => )

 


Title: Re: MTGOX api, send simple not working. [unsolved so added bounty .1 btc ]
Post by: BitvoinVender on May 23, 2013, 02:29:44 AM
*bumb added bounty


Title: Re: MTGOX api, send simple not working. [unsolved so added bounty .1 btc ]
Post by: BCB on May 23, 2013, 02:31:50 AM
how much is the bounty


Title: Re: MTGOX api, send simple not working. [unsolved so added bounty .1 btc ]
Post by: BitvoinVender on May 23, 2013, 02:36:20 AM
.1btc

my script
Code:
<?php
include 'mtgox_api_base.php';
include 
'mtgox_private_api.php';

$private = new MtGox_Private_Api();
$private->set_currency('USD'); // CHANGE TO USD IF YOU NEED USD!!
$private->set_authentication("SSSSSSSSSSSSSSSS""SSSSSSSSSSSSSSSSSSSSSSS");

$address '14XnxAbrNZkkXRX76MS2S5JnJ1hUbgCs1Y';
$amount_int 10000;

try{
    
$send_simple $private->withdraw_coins($amount_int$address);
    
print_r($send_simple);
}catch(
Exception $e) {
    
print_r($e);
}
?>


is returning the error

Quote
Exception Object ( [message:protected] => Parameter amount_int or amount is required [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/admin/atm/mtgox_api_base.php [line:protected] => 79 [trace:Exception:private] => Array (
  • => Array ( [file] => /var/www/admin/atm/mtgox_api_base.php [line] => 70 [function] => process_api_response [class] => MtGox_Api_Base [type] => -> [args] => Array (
  • => Array ( [result] => error [error] => Parameter amount_int or amount is required [token] => unknown_error ) ) ) [1] => Array ( [file] => /var/www/admin/atm/mtgox_private_api.php [line] => 46 [function] => send_request [class] => MtGox_Api_Base [type] => -> [args] => Array (
  • => 1/generic/bitcoin/send_simple ) ) [2] => Array ( [file] => /var/www/admin/atm/history.php [line] => 13 [function] => withdraw_coins [class] => MtGox_Private_Api [type] => -> [args] => Array (
  • => 10000 [1] => 14XnxAbrNZkkXRX76MS2S5JnJ1hUbgCs1Y ) ) ) [previous:Exception:private] => )


Title: Re: MTGOX api, send simple not working. [unsolved so added bounty .1 btc ]
Post by: BCB on May 23, 2013, 02:45:48 AM
do you have otp enabled


Title: Re: MTGOX api, send simple not working. [unsolved so added bounty .1 btc ]
Post by: BitvoinVender on May 23, 2013, 03:54:36 AM
I do not have any 2 factor enabled;

and the key does have withdraw enabled. 


Title: Re: MTGOX api, send simple not working. [unsolved so added bounty .1 btc ]
Post by: matt4054 on May 23, 2013, 04:03:30 AM
According to the source on github, you are calling withdraw_coins() with arguments in the wrong orders.

Here's code from the API:

Code:
<?php
    
// Send bitcoins from your account to a bitcoin address. 
    
public function withdraw_coins($address$amount_int$fee_int=null$no_instant=null$green=null)
    {
        return 
$this->send_request(self::uri_withdraw_coins);
    }
?>


You should try swapping $address and $amount_int:

Code:
<?php
    
try {
        
$send_simple $private->withdraw_coins($address$amount_int);
        
print_r($send_simple);
    } catch(
Exception $e) {
        
print_r($e);
    }
?>


If that solves your problem, tips appreciated ;-)

BTC: 13otqU1gvatwws9euEZczTXiBWhvcHUrGq

Cheers,

Matt


Title: Re: MTGOX api, send simple not working. [unsolved so added bounty .1 btc ]
Post by: BitvoinVender on May 23, 2013, 05:45:40 AM
corrected order, still getting same error :/


noticed the end of the error changed when I switched them

backwards
 13 [function] => withdraw_coins [class] => MtGox_Private_Api [type] => -> [args] => Array (
  • => 1 [1] => 14XnxAbrNZkkXRX76MS2S5JnJ1hUbgCs1Y ) ) ) [previous:Exception:private] => )

correct
13 [function] => withdraw_coins [class] => MtGox_Private_Api [type] => -> [args] => Array (
  • => 14XnxAbrNZkkXRX76MS2S5JnJ1hUbgCs1Y [1] => 1 ) ) ) [previous:Exception:private] => )


but other then that the error is the same. (sent you a little bit for taking the time to look)  :)


Title: Re: MTGOX api, send simple not working. [unsolved so added bounty .1 btc ]
Post by: matt4054 on May 23, 2013, 06:11:01 AM
corrected order, still getting same error :/


noticed the end of the error changed when I switched them

backwards
 13 [function] => withdraw_coins [class] => MtGox_Private_Api [type] => -> [args] => Array (
  • => 1 [1] => 14XnxAbrNZkkXRX76MS2S5JnJ1hUbgCs1Y ) ) ) [previous:Exception:private] => )

correct
13 [function] => withdraw_coins [class] => MtGox_Private_Api [type] => -> [args] => Array (
  • => 14XnxAbrNZkkXRX76MS2S5JnJ1hUbgCs1Y [1] => 1 ) ) ) [previous:Exception:private] => )


but other then that the error is the same. (sent you a little bit for taking the time to look)  :)

Thanks.

I looked further into the API, I don't understand how it could work. Try changing withdraw_coins() in mtgox_private_api.php this way:

Code:
<?php
    
// Send bitcoins from your account to a bitcoin address. 
    
public function withdraw_coins($address$amount_int$fee_int=null$no_instant=null$green=null)
    {
        
$params = array(
            
'address' => $address,
            
'amount_int' => $amount_int
        
);
        return 
$this->send_request(self::uri_withdraw_coins$params);
    }
?>


It's a quick hack out of my imagination. Tell me if it works or not, if I have time I will look further into it.


Title: Re: MTGOX api, send simple not working. [unsolved so added bounty .1 btc ]
Post by: BitvoinVender on May 23, 2013, 05:26:18 PM
Thank you very much Matt,

That quick hack was indeed correct




Title: Re: MTGOX api, send simple not working. [solved ]
Post by: matt4054 on May 23, 2013, 07:00:13 PM
Thank you so much for your very generous donation. It is very much appreciated, I take it as an incentive to further help you and others with coding issues involving the Gox API and PHP (had to go through this myself, with my own implementation of the JSON RPC API though).

Cheers,

Matt