Skip to content

Commit

Permalink
Implements OpenOrders end-point.
Browse files Browse the repository at this point in the history
  • Loading branch information
dve committed Aug 19, 2017
1 parent d9a1208 commit 39b1210
Show file tree
Hide file tree
Showing 6 changed files with 521 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ An easy to use kraken client
- [ ] public function publicSpread()
- [x] public function privateBalance()
- [ ] public function privateTradeBalance()
- [ ] public function privateOpenOrders()
- [x] public function privateOpenOrders()
- [ ] public function privateClosedOrders()
- [x] public function privateQueryOrders()
- [ ] public function privateTradesHistory()
Expand Down
6 changes: 5 additions & 1 deletion src/KrakenClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DVE\KrakenClient\Model\Request\PrivateAddOrderRequestModel;
use DVE\KrakenClient\Model\Request\PrivateBalanceRequestModel;
use DVE\KrakenClient\Model\Request\PrivateCancelOrderRequestModel;
use DVE\KrakenClient\Model\Request\PrivateOpenOrdersRequestModel;
use DVE\KrakenClient\Model\Request\PrivateQueryOrdersRequestModel;
use DVE\KrakenClient\Model\Request\PublicDepthRequestModel;
use DVE\KrakenClient\Model\Request\PublicTimeRequestModel;
Expand Down Expand Up @@ -109,9 +110,12 @@ public function privateTradeBalance()
throw new \BadMethodCallException(__METHOD__ . ' not yet implemented');
}

/**
* @return PrivateOpenOrdersRequestModel
*/
public function privateOpenOrders()
{
throw new \BadMethodCallException(__METHOD__ . ' not yet implemented');
return new PrivateOpenOrdersRequestModel($this->krakenAPI, $this->logger);
}

public function privateClosedOrders()
Expand Down
74 changes: 74 additions & 0 deletions src/Model/Request/PrivateOpenOrdersRequestModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace DVE\KrakenClient\Model\Request;

use DVE\KrakenClient\Constant\ApiMethodAccessType;
use DVE\KrakenClient\Model\Response\PrivateOpenOrdersResponseModel;
use Shudrum\Component\ArrayFinder\ArrayFinder;

class PrivateOpenOrdersRequestModel extends RequestModel
{
/**
* @var bool
*/
private $trades;

/**
* @var int
*/
private $userref;

/**
* @param bool $trades
* @return PrivateQueryOrdersRequestModel
*/
public function setTrades($trades)
{
$this->trades = (bool)$trades;
return $this;
}

/**
* @param int $userref
* @return PrivateQueryOrdersRequestModel
*/
public function setUserRef($userref)
{
$this->userref = $userref;
return $this;
}

/**
* @return string
*/
public function getEndPointName()
{
return 'OpenOrders';
}

/**
* @return array
*/
public function buildRequest()
{
$requestData = [];

if($this->trades) {
$requestData['trades'] = $this->trades;
}

if($this->userref) {
$requestData['userref'] = $this->userref;
}

return $requestData;
}

public function send()
{
return new PrivateOpenOrdersResponseModel(
$this->callApi(ApiMethodAccessType::PRIVATE_METHOD),
new ArrayFinder([])
);
}
}
120 changes: 120 additions & 0 deletions src/Model/Response/PrivateOpenOrdersElementDescrResponseModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace DVE\KrakenClient\Model\Response;

use Shudrum\Component\ArrayFinder\ArrayFinder;

class PrivateOpenOrdersElementDescrResponseModel extends ResponseModel
{
/**
* @var string
*/
private $pair;

/**
* @var string
*/
private $type;

/**
* @var string
*/
private $ordertype;

/**
* @var float
*/
private $price;

/**
* @var float
*/
private $price2;

/**
* @var int
*/
private $leverage;

/**
* @var string
*/
private $order;

/**
* @return string
*/
public function getPair()
{
return $this->pair;
}

/**
* @return string
*/
public function getType()
{
return $this->type;
}

/**
* @return string
*/
public function getOrdertype()
{
return $this->ordertype;
}

/**
* @return float
*/
public function getPrice()
{
return $this->price;
}

/**
* @return float
*/
public function getPrice2()
{
return $this->price2;
}

/**
* @return int
*/
public function getLeverage()
{
return $this->leverage;
}

/**
* @return string
*/
public function getOrder()
{
return $this->order;
}

/**
* @param ArrayFinder $results
* @param ArrayFinder $params
*/
protected function hydrate(ArrayFinder $results, ArrayFinder $params)
{
$leverage = $results->get('leverage');

if($leverage === 'none') {
$leverage = 0;
}

$this->pair = (string)$results->get('pair');
$this->type = (string)$results->get('type');
$this->ordertype = (string)$results->get('ordertype');
$this->price = (float)$results->get('price');
$this->price2 = (float)$results->get('price2');
$this->leverage = (int)$leverage;
$this->order = (string)$results->get('order');
}
}
Loading

0 comments on commit 39b1210

Please sign in to comment.