1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace R3bers\BittrexApi\Api; |
6
|
|
|
|
7
|
|
|
use GuzzleHttp\Exception\GuzzleException; |
8
|
|
|
use R3bers\BittrexApi\Exception\TransformResponseException; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Market |
12
|
|
|
* @package R3bers\BittrexApi\Api |
13
|
|
|
*/ |
14
|
|
|
class Market extends Api |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $marketSymbol; |
20
|
|
|
/** |
21
|
|
|
* @var float |
22
|
|
|
*/ |
23
|
|
|
private $quantity; |
24
|
|
|
/** |
25
|
|
|
* @var float |
26
|
|
|
*/ |
27
|
|
|
private $limit; |
28
|
|
|
/** |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
private $useAwards; |
32
|
|
|
|
33
|
|
|
/** https://bittrex.github.io/api/v3#operation--orders-post |
34
|
|
|
* @param string $marketSymbol |
35
|
|
|
* @param float $quantity |
36
|
|
|
* @param float $limit |
37
|
|
|
* @param bool $useAwards |
38
|
|
|
* @return array |
39
|
|
|
* @throws GuzzleException|TransformResponseException |
40
|
|
|
*/ |
41
|
1 |
|
public function buyLimit(string $marketSymbol, float $quantity, float $limit, bool $useAwards = false): array |
42
|
|
|
{ |
43
|
1 |
|
$this->marketSymbol = $marketSymbol; |
44
|
1 |
|
$this->quantity = $quantity; |
45
|
1 |
|
$this->limit = $limit; |
46
|
1 |
|
$this->useAwards = $useAwards; |
47
|
1 |
|
$options = $this->limitOrder('BUY'); |
48
|
1 |
|
return $this->rest('POST', '/orders', $options); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** Helper function for order to prevent duplication |
52
|
|
|
* @param string $direction |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
2 |
|
private function limitOrder(string $direction): array |
56
|
|
|
{ |
57
|
|
|
$newOrder = [ |
58
|
2 |
|
'marketSymbol' => $this->marketSymbol, |
59
|
2 |
|
'direction' => 'BUY', |
60
|
2 |
|
'type' => $direction, |
61
|
2 |
|
'quantity' => $this->quantity, |
62
|
2 |
|
'limit' => $this->limit, |
63
|
2 |
|
'timeInForce' => 'GOOD_TIL_CANCELLED', |
64
|
2 |
|
'useAwards' => $this->useAwards |
65
|
|
|
|
66
|
|
|
]; |
67
|
2 |
|
return ['body' => json_encode($newOrder)]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** https://bittrex.github.io/api/v3#operation--orders-post |
71
|
|
|
* @param string $marketSymbol |
72
|
|
|
* @param float $quantity |
73
|
|
|
* @param float $limit |
74
|
|
|
* @param bool $useAwards |
75
|
|
|
* @return array |
76
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
77
|
|
|
* @throws \R3bers\BittrexApi\Exception\TransformResponseException |
78
|
|
|
*/ |
79
|
1 |
|
public function sellLimit(string $marketSymbol, float $quantity, float $limit, bool $useAwards = false): array |
80
|
|
|
{ |
81
|
1 |
|
$this->marketSymbol = $marketSymbol; |
82
|
1 |
|
$this->quantity = $quantity; |
83
|
1 |
|
$this->limit = $limit; |
84
|
1 |
|
$this->useAwards = $useAwards; |
85
|
1 |
|
$options = $this->limitOrder('SELL'); |
86
|
1 |
|
return $this->rest('POST', '/orders', $options); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** https://bittrex.github.io/api/v3#operation--orders--orderId--delete |
90
|
|
|
* @param string $uuid |
91
|
|
|
* @return array |
92
|
|
|
* @throws GuzzleException|TransformResponseException |
93
|
|
|
*/ |
94
|
1 |
|
public function cancel(string $uuid): array |
95
|
|
|
{ |
96
|
1 |
|
return $this->rest('DELETE', '/orders/' . $uuid); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** https://bittrex.github.io/api/v3#operation--orders-open-get |
100
|
|
|
* @param string|null $market |
101
|
|
|
* @param bool|null $needSequence if true additional member of array named Sequence added to return |
102
|
|
|
* @return array |
103
|
|
|
* @throws GuzzleException|TransformResponseException |
104
|
|
|
*/ |
105
|
2 |
|
public function getOpenOrders(?string $market = null, ?bool $needSequence = null): array |
106
|
|
|
{ |
107
|
2 |
|
$options = []; |
108
|
2 |
|
if (!is_null($market)) $options['query'] = ['marketSymbol' => $market]; |
109
|
|
|
|
110
|
2 |
|
return $this->rest('GET', '/orders/open', $options, ($needSequence)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** https://bittrex.github.io/api/v3#operation--orders-open-head |
114
|
|
|
* @return int Current Sequence of Orders |
115
|
|
|
* @throws GuzzleException |
116
|
|
|
* @throws TransformResponseException |
117
|
|
|
*/ |
118
|
1 |
|
public function headOpenOrders(): int |
119
|
|
|
{ |
120
|
1 |
|
$responseArray = $this->rest('HEAD', '/orders/open', [], true); |
121
|
1 |
|
return $responseArray['Sequence']; |
122
|
|
|
} |
123
|
|
|
} |