Skip to content

Commit

Permalink
Added helper for checking minimal volume size
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Mar 5, 2018
1 parent beefc18 commit 45b0610
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,36 @@ class BalanceConstroller extends Controller {
}
```

### Checking minimal volume size

See https://support.kraken.com/hc/en-us/articles/205893708-What-is-the-minimum-order-size-

#### Check minimal order size for pair
```php
$orderVolume = new \Butschster\Kraken\OrderVolume;
$pair = $client->getAssetPairs('EOSETH')->first();
$isValidSize = $orderVolume->checkMinimalSizeForPair($pair, 1.1);
```

#### Check minimal order size for currency
```php
$orderVolume = new \Butschster\Kraken\OrderVolume;
$isValidSize = $orderVolume->checkMinimalSizeForPair('EOS', 1.1);
```

#### Get minimal order size
```php
$orderVolume = new \Butschster\Kraken\OrderVolume;

// Pair
$pair = $client->getAssetPairs('EOSETH')->first();
$minimalsize = $orderVolume->getMinimalSizeForPair($pair);

// Currency
$minimalsize = $orderVolume->getMinimalSize('EOS');
```


### API methods

#### Make request
Expand Down
20 changes: 20 additions & 0 deletions config/kraken.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,24 @@

// Two-factor password (if two-factor enabled, otherwise not required)
'otp' => env('KRAKEN_OTP'),

'minimal_volumes' => [
'XREP' => 0.3,
'XXBT' => 0.002,
'BCH' => 0.002,
'DASH' => 0.03,
'DOGE' => 3000,
'EOS' => 3,
'XETH' => 0.2,
'XETC' => 0.3,
'GNO' => 0.03,
'XICN' => 2,
'XLTC' => 0.1,
'XMLN' => 0.1,
'XXMR' => 0.1,
'XXRP' => 30,
'XXLM' => 30,
'XZEC' => 0.03,
'USDT' => 5
]
];
8 changes: 8 additions & 0 deletions src/Exceptions/MinimalVolumeSizeNotFound.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Butschster\Kraken\Exceptions;

class MinimalVolumeSizeNotFound extends \Exception
{

}
65 changes: 65 additions & 0 deletions src/OrderVolume.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Butschster\Kraken;

use Butschster\Kraken\Exceptions\MinimalVolumeSizeNotFound;
use Butschster\Kraken\Objects\Pair;

class OrderVolume
{
/**
* Check minimal volume size for selected pair
*
* @param Pair $pair
* @param float $volume
* @return bool
* @throws MinimalVolumeSizeNotFound
*/
public function checkMinimalSizeForPair(Pair $pair, float $volume): bool
{
return $this->getMinimalSizeForPair($pair) < $volume;
}

/**
* Check minimal volume size for selected currency
*
* @param string $currency
* @param float $volume
* @return bool
* @throws MinimalVolumeSizeNotFound
*/
public function checkMinimalSize(string $currency, float $volume): bool
{
return $this->getMinimalSize($currency) < $volume;
}

/**
* Get minimal volume size for selected pair
*
* @param Pair $pair
* @return mixed
* @throws MinimalVolumeSizeNotFound
*/
public function getMinimalSizeForPair(Pair $pair)
{
return $this->getMinimalSize($pair->base());
}

/**
* Get minimal volume size for selected currency
*
* @param string $currency
* @return mixed
* @throws MinimalVolumeSizeNotFound
*/
public function getMinimalSize(string $currency)
{
$minimalSize = config('kraken.minimal_volumes.'.$currency);

if (is_null($minimalSize)) {
throw new MinimalVolumeSizeNotFound("Minimal volume size for currency [{$currency}] not found.");
}

return $minimalSize;
}
}

0 comments on commit 45b0610

Please sign in to comment.