PHP code example of linwj / kraken

1. Go to this page and download the library: Download linwj/kraken library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

linwj / kraken example snippets


$kraken=new kraken();

//You can set special needs
$kraken->setOptions([
    //Set the request timeout to 60 seconds by default
    'timeout'=>10,
    
    //If you are developing locally and need an agent, you can set this
    //'proxy'=>true,
    //More flexible Settings
    /* 'proxy'=>[
     'http'  => 'http://127.0.0.1:12333',
     'https' => 'http://127.0.0.1:12333',
     'no'    =>  ['.cn']
     ], */
    //Close the certificate
    //'verify'=>false,
]);

$kraken=new Kraken();

try {
    $result=$kraken->market()->time();
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

try {
    $result=$kraken->market()->assets();
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

try {
    $result=$kraken->market()->assetPairs();
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

try {
    $result=$kraken->market()->depth([
        'pair'=>'XXBTZUSD',
        'count'=>10,
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

$kraken=new Kraken($key,$secret);

//bargaining transaction
try {
    $result=$kraken->userTrade()->addOrder([
        //'userref'=>'xxxxx'  //Custom ID
        'pair' => 'XXBTZUSD',
        'type' => 'buy',
        'ordertype' => 'limit',
        'price' => '7000',
        'volume' => '1.123'
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

//track the order
try {
    $result=$kraken->user()->queryOrders([
        //'userref'=>'xxxxx'  //Custom ID
        'txid'=>'xxxxxx,xxxxxxx,xxxxxxx',
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

//cancellation of order
try {
    $result=$kraken->userTrade()->cancelOrder([
        //'userref'=>'xxxxx'  //Custom ID
        'txid'=>'xxxxxx,xxxxxxx,xxxxxxx',
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

$kraken=new Kraken($key,$secret);

try {
    $result=$kraken->user()->balance();
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

try {
    $result=$kraken->user()->tradeBalance();
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

try {
    $result=$kraken->user()->openOrders();
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

try {
    $result=$kraken->user()->queryOrders();
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}