Skip to content

Commit

Permalink
Implements get Order details end point
Browse files Browse the repository at this point in the history
  • Loading branch information
dve committed Feb 25, 2018
1 parent 99990be commit 39e8b25
Show file tree
Hide file tree
Showing 4 changed files with 540 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use DVE\CEXApiClient\Definition\Request\BalanceRequest;
use DVE\CEXApiClient\Definition\Request\LastPriceRequest;
use DVE\CEXApiClient\Definition\Request\OrderBookRequest;
use DVE\CEXApiClient\Definition\Request\OrderDetailsRequest;
use DVE\CEXApiClient\Definition\Request\PlaceLimitOrderRequest;
use DVE\CEXApiClient\Definition\Request\PlaceMarketOrderRequest;
use DVE\CEXApiClient\Definition\Request\RequestInterface;
use DVE\CEXApiClient\Definition\Request\Traits\SignatureTrait;
use DVE\CEXApiClient\Definition\Response\BalanceResponse;
use DVE\CEXApiClient\Definition\Response\LastPriceResponse;
use DVE\CEXApiClient\Definition\Response\OrderBookResponse;
use DVE\CEXApiClient\Definition\Response\OrderDetailsResponse;
use DVE\CEXApiClient\Definition\Response\PlaceLimitOrderResponse;
use DVE\CEXApiClient\Definition\Response\PlaceMarketOrderResponse;
use DVE\CEXApiClient\Definition\Response\Property\BalanceCurrencyProperty;
Expand Down Expand Up @@ -285,6 +287,49 @@ public function lastPrice($symbol1, $symbol2): LastPriceResponse
return $response;
}

/**
* @param string $orderId
* @return OrderDetailsResponse
*/
public function getOrderDetails(string $orderId): OrderDetailsResponse
{
$orderDetails = (new OrderDetailsRequest())
->setId($orderId)
;

$data = $this->request($orderDetails);

$response = (new OrderDetailsResponse())
->setId($data->get('id'))
->setOrderId($data->get('orderId'))
->setUser($data->get('user'))
->setSymbol1($data->get('symbol1'))
->setSymbol2($data->get('symbol2'))
->setStatus($data->get('status'))
->setLastTx($data->get('lastTx'))
->setType($data->get('type'))
->setTime($data->get('time'))
->setAmount((float)$data->get('amount'))
->setPrice((float)$data->get('price'))
->setRemains((float)$data->get('price'))
->setPos($data->get('pos'))
->setTradingFeeMaker((float)$data->get('tradingFeeMaker'))
->setTradingFeeTaker((float)$data->get('tradingFeeTaker'))
->setTradingFeeStrategy($data->get('tradingFeeStrategy'))
->setTradingFeeUserVolumeAmount($data->get('tradingFeeUserVolumeAmount'))
;

// Handle lastTxTime both formats
$lastTxTime = $data->get('lastTxTime');
if(is_numeric($lastTxTime)) {
$response->setLastTxTime($this->getDateTimeFromMicroTime($lastTxTime / 10000));
} else {
$response->setLastTxTime(new \DateTime($lastTxTime));
}

return $response;
}

/**
* @param RequestInterface $request
* @return ArrayFinder
Expand Down Expand Up @@ -338,4 +383,13 @@ private function request(RequestInterface $request): ArrayFinder

return new ArrayFinder($data);
}

/**
* @param float $microtime
* @return \DateTime
*/
protected function getDateTimeFromMicroTime(float $microtime): \DateTime
{
return \DateTime::createFromFormat('U.u', $microtime);
}
}
11 changes: 11 additions & 0 deletions src/ConstantHelper/OrderStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace DVE\CEXApiClient\ConstantHelper;

class OrderStatus
{
const ACTIVE = 'a';
const CANCELED = 'c';
const CANCEL_DONE = 'cd';
const DONE = 'd';
}
55 changes: 55 additions & 0 deletions src/Definition/Request/OrderDetailsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace DVE\CEXApiClient\Definition\Request;

class OrderDetailsRequest extends PrivateRequestAbstract
{
/**
* @var string
*/
private $id;

/**
* @return string
*/
public function getUri(): string
{
return '/get_order';
}

/**
* @return string
*/
public function getMethod(): string
{
return 'POST';
}

/**
* @return array
*/
public function getBodyParams(): array
{
return parent::getBodyParams() + [
'id' => $this->id
];
}

/**
* @return string
*/
public function getId(): string
{
return $this->id;
}

/**
* @param string $id
* @return OrderDetailsRequest
*/
public function setId(string $id): OrderDetailsRequest
{
$this->id = $id;
return $this;
}
}
Loading

0 comments on commit 39e8b25

Please sign in to comment.