Require this package with composer using the following command:
composer require butschster/kraken-api-client
If you're using Laravel 5.5 or above, the package will automatically register the Kraken provider and facade.
Add Butschster\Kraken\KrakenServiceProvider to the providers array in your config/app.php
:
'providers' => [
// Other service providers...
Butschster\Kraken\KrakenServiceProvider::class,
],
If you want to use the facade interface, you can use the facade class when needed:
use Butschster\Kraken\Facade\Kraken;
Or add an alias in your config/app.php
:
'aliases' => [
...
'Kraken' => Butschster\Kraken\Facade\Kraken::class,
],
You can update your .env file with the following:
KRAKEN_KEY=my_api_key
KRAKEN_SECRET=my_secret
KRAKEN_OTP=my_otp_key # if two-factor enabled, otherwise not required
By using facade
use Butschster\Kraken\Facade\Kraken;
$balances = Kraken::getAccountBalance();
// Will return Butschster\Kraken\Objects\BalanceCollection
foreach($balances as $balance) {
$currency = $balance->currency();
$amount = $balance->amount();
}
By using dependency injection
use Butschster\Kraken\Contracts\Client;
class BalanceConstroller extends Controller {
public function getBalance(Client $client)
{
$client->getAccountBalance();
...
}
}
See https://support.kraken.com/hc/en-us/articles/205893708-What-is-the-minimum-order-size-
$orderVolume = new \Butschster\Kraken\OrderVolume;
$pair = $client->getAssetPairs('EOSETH')->first();
$isValidSize = $orderVolume->checkMinimalSizeForPair($pair, 1.1);
$orderVolume = new \Butschster\Kraken\OrderVolume;
$isValidSize = $orderVolume->checkMinimalSizeForPair('EOS', 1.1);
$orderVolume = new \Butschster\Kraken\OrderVolume;
// Pair
$pair = $client->getAssetPairs('EOSETH')->first();
$minimalsize = $orderVolume->getMinimalSizeForPair($pair);
// Currency
$minimalsize = $orderVolume->getMinimalSize('EOS');
$client->request(string $method, array $parameters, bool $isPublic) : array;
// Public request
$trades = $client->request('Trades', ['pair' => 'BCHXBT']);
// Private request
$balance = $client->request('Balance', [], false);
If request return an error, will be thrown an exception Butschster\Kraken\Exceptions\KrakenApiErrorException
https://www.kraken.com/help/api#get-tradable-pairs
$pairs = $client->getAssetPairs(string|array $pair, string $info='all') : Butschster\Kraken\Objects\PairCollection;
foreach($pairs as $pair) {
$pair->name();
}
https://www.kraken.com/help/api#get-ticker-info
$pairs = $client->getTicker(string|array $pair) : Butschster\Kraken\Objects\TickerCollection;
foreach($pairs as $pair) {
$pair->name();
$pair->askPrice();
$pair->askWholeLotVolume();
$pair->askLotVolume();
$pair->askLotVolume();
...
}
https://www.kraken.com/help/api#get-account-balance
$balances = $client->getAccountBalance() : Butschster\Kraken\Objects\BalanceCollection;
foreach($balances as $balance) {
$currency = $balance->currency();
$amount = $balance->amount();
}
https://www.kraken.com/help/api#get-open-orders
$orders = $client->getOpenOrders(bool $trades = false) : Butschster\Kraken\Objects\OrdersCollection;
https://www.kraken.com/help/api#get-closed-orders
$orders = $client->getClosedOrders(bool $trades = false, Carbon\Carbon $start = null, Carbon\Carbon $end = null) : Butschster\Kraken\Objects\OrdersCollection;
https://www.kraken.com/help/api#add-standard-order
use Butschster\Kraken\Contracts\Order as OrderContract;
$order = new Butschster\Kraken\Order('BCHUSD', OrderContract::TYPE_BUY, OrderContract::ORDER_TYPE_MARKET, 20);
$orderStatus = $client->addOrder($order) : Butschster\Kraken\Objects\OrderStatus;
$txid = $orderStatus->getTransactionId();
$desciption = $orderStatus->getDescription() = Butschster\Kraken\Objects\OrderStatusDescription;
https://www.kraken.com/help/api#cancel-open-order
$client->cancelOrder(string $transactionId): array;