Bitcoin Forum

Other => Beginners & Help => Topic started by: BitvoinVender on April 15, 2013, 07:59:58 PM



Title: newbi mtgox API help, basic php
Post by: BitvoinVender on April 15, 2013, 07:59:58 PM
just started accepting btc donations on my site.

right now its just getting stored on mtgox so It can keep a portion in dollars.

I want to set up a "getinfo" so I can see how much is in my account. And Eventually set up an automated monthly withdrawl of bitcoin to a offline wallet.

I found a github of what looks like a simple php mtgox api class

https://github.com/Someguy123/MtGOX-PHP-API


here is my code so far

Code:
<?php
$gox 
= new Gox('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS');


include (
"gox.class.php");
echo 
"test";
$info->getinfo($gox);
var_dump ($info);
?>


for refece the function im trying to call too is

Code:
function getInfo() {
        $info = $this->mtgox_query('0/info.php');
        $this->info = $info; // Hold it in a variable for easy access
        return $info;
    }

thanks


Title: Re: newbi mtgox API help, basic php
Post by: cmp on April 15, 2013, 08:03:03 PM
Look at the API code here: https://en.bitcoin.it/wiki/MtGox/API/HTTP#PHP

I think it's easier to understand. The Gox.class is using this code.


Title: Re: newbi mtgox API help, basic php
Post by: BitvoinVender on April 15, 2013, 08:07:28 PM
ohh wow, yea that worked much better. just entered my API info and got my var_dump


Im going to be trying to set up a withdrawal now and see If I run into any trouble.


Title: Re: newbi mtgox API help, basic php
Post by: BitvoinVender on April 15, 2013, 09:24:55 PM
im stuck!

I take it this is an old API

Code:
// 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 found a new class for v1

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


this is what I got so far.

Code:
<?php
include ("mtgox_private_api.php");
include (
"mtgox_api_base.php");
include (
"mtgox_api_objects.php");
 
 
$api = new MtGox_Private_Api();
$api->set_currency('USD');
$api->set_authentication('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS');
 
 
$history $api->get_wallet_history('USD');
print_r($history);
 
 
//withdrawl sample 1btc
$address "1PetPrN5xDimsYENtJNW6gBUbmjZ5H9xdm";
$amount_int "100000000";
$fee_int".0005";
 
$withdrawl $api->withdraw_coins($address$amount_int$fee_int=null$no_instant=null$green=null);
 
//print recipt?
var_dump ($this);
 
echo 
"test";
 
?>




http://25.media.tumblr.com/tumblr_lsxtglsUrC1qmhv2lo1_500.jpg


Title: Re: newbi mtgox API help, basic php
Post by: BitvoinVender on April 16, 2013, 03:54:44 AM
bump :-[


Title: Re: newbi mtgox API help, basic php
Post by: OdinHephaestus on April 16, 2013, 03:57:44 AM
Code:
<?php
include ("gox.class.php");

$gox = new Gox('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS');

echo 
"test";
$info->getinfo($gox);
var_dump ($info);
?>

You need to include the file, before you can call the class.


Title: Re: newbi mtgox API help, basic php
Post by: BitvoinVender on April 16, 2013, 06:19:52 AM
im useing the newer API v1 then that original post.

this is an example useing the class

https://github.com/daftspunk/php-mtgox-v1/blob/master/examples/dirty_daytrader.php

why I tried the 3 includes

include '../mtgox_api_base.php';
include '../mtgox_private_api.php';
include '../mtgox_public_api.php';

not a withdrawl in their :/


simply trying to call to this function

Code:
// 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);
    }


Title: Re: newbi mtgox API help, basic php
Post by: BitvoinVender on April 16, 2013, 07:31:09 AM
I got it to connect;

Code:
$history = $api->get_wallet_history('USD');
print_r($history);

dumps my history

yet, still trying to figure out withdrawls

Code:
include ("mtgox_api_base.php");
include ("mtgox_private_api.php");
include ("mtgox_public_api.php");

//include ("mtgox_api_objects.php");

echo "test";

$api = new MtGox_Private_Api();
$api->set_currency('USD');
$api->set_authentication('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS');



$history = $api->get_wallet_history('USD');
print_r($history);





//withdrawl sample 1btc
$address = "1PetPrN5xDimsYENtJNW6gBUbmjZ5H9xdm";
$amount_int = "90000000";
$fee_int= "000000000";

$withdrawl = $api->withdraw_coins($address, $amount_int, $fee_int=null, $no_instant=null, $green=null);

//print recipt?
print_r ($withdrawl);

echo "test";

assume amount is in satoshi?
Im not even getting an error or anything, just a white page with the "test" showing