Skip to content

Commit

Permalink
add market data and user funding requests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrederoos committed May 25, 2021
1 parent 8f62d9c commit fda3520
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class Message
abstract public function generateRequest(): Request;

/**
* @param bool $exendedResponse
* @param string $version
*/
public function __construct(string $version = '0')
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace KrakenClient\message;
namespace KrakenClient\message\data;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace KrakenClient\message;
namespace KrakenClient\message\data;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
Expand All @@ -18,6 +19,7 @@ class MessageGetTradeBalances extends Message
private const FIELD_ASSET = 'asset';

/**
* @param string $asset
* @param string $version
*/
public function __construct(string $asset = 'ZUSD', string $version = '0')
Expand Down
41 changes: 41 additions & 0 deletions src/message/funding/MessageGetDepositMethods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
namespace KrakenClient\message\funding;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
* Retrieve methods available for depositing a particular asset.
*/
class MessageGetDepositMethods extends Message
{
/**
* Message path.
*/
public const PATH_DEPOSIT_METHODS = '/%s/private/DepositMethods';

/**
* Field constants.
*/
private const FIELD_ASSET = 'asset';

/**
* @param bool $exendedResponse
*/
public function __construct(string $asset, string $version = '0')
{
parent::__construct($version);

$this->body[self::FIELD_ASSET] = $asset;
$this->body[self::FIELD_NONCE] = $this->generateNonce();
}

/**
* @return Request
*/
public function generateRequest(): Request
{
return new Request(HttpMethod::POST, vsprintf(self::PATH_DEPOSIT_METHODS, [$this->version]) . $this->generateQueryParameters(), [], http_build_query($this->body, '', '&'));
}
}
40 changes: 40 additions & 0 deletions src/message/market/MessageGetAssetInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace KrakenClient\message\market;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
* Get information about the assets that are available for deposit, withdrawal, trading and staking.
*/
class MessageGetAssetInfo extends Message
{
/**
* Message path.
*/
public const PATH_ASSET_INFO = '/%s/public/Assets';

/** */
private const FIELD_ASSET = 'asset';
private const FIELD_ASSET_CLASS = 'aclass';

/**
* @param string $version
*/
public function __construct(string $asset = 'all', string $assetClass = 'currency', string $version = '0')
{
parent::__construct($version);

$this->body[self::FIELD_ASSET] = $asset;
$this->body[self::FIELD_ASSET_CLASS] = $assetClass;
}

/**
* @return Request
*/
public function generateRequest(): Request
{
return new Request(HttpMethod::GET, vsprintf(self::PATH_ASSET_INFO, [$this->version]) . $this->generateQueryParameters(), [], http_build_query($this->body, '', '&'));
}
}
42 changes: 42 additions & 0 deletions src/message/market/MessageGetOrderBook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace KrakenClient\message\market;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
* Get Order Book.
*/
class MessageGetOrderBook extends Message
{
/**
* Message path.
*/
public const PATH_ORDER_BOOK = '/%s/public/Depth';

/** */
private const FIELD_PAIR = 'pair';
private const FIELD_COUNT = 'count';

/**
* @param string $pair
* @param int $count
* @param string $version
*/
public function __construct(string $pair, int $count = 100, string $version = '0')
{
parent::__construct($version);

$this->body[self::FIELD_PAIR] = $pair;
$this->body[self::FIELD_COUNT] = $count;
}

/**
* @return Request
*/
public function generateRequest(): Request
{
return new Request(HttpMethod::GET, vsprintf(self::PATH_ORDER_BOOK, [$this->version]) . $this->generateQueryParameters(), [], http_build_query($this->body, '', '&'));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace KrakenClient\message;
namespace KrakenClient\message\market;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
Expand Down
45 changes: 45 additions & 0 deletions src/message/market/MessageGetSpreads.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
namespace KrakenClient\message\market;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
* Get Recent Spreads.
*/
class MessageGetSpreads extends Message
{
/**
* Message path.
*/
public const PATH_SPREAD = '/%s/public/Spread';

/** */
private const FIELD_PAIR = 'pair';
private const FIELD_SINCE = 'since';

/**
* @param string $pair
* @param string $since
* @param string $version
*/
public function __construct(string $pair, string $since = null, string $version = '0')
{
parent::__construct($version);

$this->body[self::FIELD_PAIR] = $pair;

if (!is_null($since)) {
$this->body[self::FIELD_SINCE] = $since;
}
}

/**
* @return Request
*/
public function generateRequest(): Request
{
return new Request(HttpMethod::GET, vsprintf(self::PATH_SPREAD, [$this->version]) . $this->generateQueryParameters(), [], http_build_query($this->body, '', '&'));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace KrakenClient\message;
namespace KrakenClient\message\market;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
Expand Down
40 changes: 40 additions & 0 deletions src/message/market/MessageGetTicker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace KrakenClient\message\market;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
* Get Ticker Information
* Note: Today's prices start at midnight UTC
*/
class MessageGetTicker extends Message
{
/**
* Message path.
*/
public const PATH_TICKER = '/%s/public/Ticker';

/** */
private const FIELD_PAIR = 'pair';

/**
* @param string $pair
* @param string $version
*/
public function __construct(string $pair, string $version = '0')
{
parent::__construct($version);

$this->body[self::FIELD_PAIR] = $pair;
}

/**
* @return Request
*/
public function generateRequest(): Request
{
return new Request(HttpMethod::GET, vsprintf(self::PATH_TICKER, [$this->version]) . $this->generateQueryParameters(), [], http_build_query($this->body, '', '&'));
}
}
42 changes: 42 additions & 0 deletions src/message/market/MessageGetTradableAssetPairs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
namespace KrakenClient\message\market;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
* Get tradable asset pairs.
*/
class MessageGetTradableAssetPairs extends Message
{
/**
* Message path.
*/
public const PATH_TRADABLE_ASSET = '/%s/public/AssetPairs';

/** */
private const FIELD_PAIR = 'pair';
private const FIELD_INFO = 'info';

/**
* @param string $pair
* @param string $info
* @param string $version
*/
public function __construct(string $pair, string $info = 'info', string $version = '0')
{
parent::__construct($version);

$this->body[self::FIELD_PAIR] = $pair;
$this->body[self::FIELD_INFO] = $info;
}

/**
* @return Request
*/
public function generateRequest(): Request
{
return new Request(HttpMethod::GET, vsprintf(self::PATH_TRADABLE_ASSET, [$this->version]) . $this->generateQueryParameters(), [], http_build_query($this->body, '', '&'));
}
}
46 changes: 46 additions & 0 deletions src/message/market/MessageGetTrades.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace KrakenClient\message\market;

use GuzzleHttp\Psr7\Request;
use KrakenClient\message\Message;
use KrakenClient\object\HttpMethod;

/**
* Get Recent Trades.
* Note: Returns the last 1000 trades by default
*/
class MessageGetTrades extends Message
{
/**
* Message path.
*/
public const PATH_TRADES = '/%s/public/Trades';

/** */
private const FIELD_PAIR = 'pair';
private const FIELD_SINCE = 'since';

/**
* @param string $pair
* @param string $since
* @param string $version
*/
public function __construct(string $pair, string $since = null, string $version = '0')
{
parent::__construct($version);

$this->body[self::FIELD_PAIR] = $pair;

if (!is_null($since)) {
$this->body[self::FIELD_SINCE] = $since;
}
}

/**
* @return Request
*/
public function generateRequest(): Request
{
return new Request(HttpMethod::GET, vsprintf(self::PATH_TRADES, [$this->version]) . $this->generateQueryParameters(), [], http_build_query($this->body, '', '&'));
}
}
Loading

0 comments on commit fda3520

Please sign in to comment.