|
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
|
|
|
* @param string $market |
|
18
|
|
|
* @param float $quantity |
|
19
|
|
|
* @param float $rate |
|
20
|
|
|
* @param bool $useAwards |
|
21
|
|
|
* @return array |
|
22
|
|
|
* @throws GuzzleException|TransformResponseException |
|
23
|
|
|
*/ |
|
24
|
1 |
|
public function buyLimit(string $market, float $quantity, float $rate, $useAwards = false): array |
|
25
|
|
|
{ |
|
26
|
|
|
$newOrder = [ |
|
27
|
1 |
|
'marketSymbol' => $market, |
|
28
|
1 |
|
'direction' => 'BUY', |
|
29
|
1 |
|
'type' => 'LIMIT', |
|
30
|
1 |
|
'quantity' => $quantity, |
|
31
|
1 |
|
'limit' => $rate, |
|
32
|
1 |
|
'timeInForce' => 'GOOD_TIL_CANCELLED', |
|
33
|
1 |
|
'useAwards' => $useAwards |
|
34
|
|
|
|
|
35
|
|
|
]; |
|
36
|
1 |
|
$options = ['body' => json_encode($newOrder)]; |
|
37
|
|
|
|
|
38
|
1 |
|
return $this->rest('POST', '/orders', $options); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $market |
|
43
|
|
|
* @param float $quantity |
|
44
|
|
|
* @param float $rate |
|
45
|
|
|
* @param bool $useAwards |
|
46
|
|
|
* @return array |
|
47
|
|
|
* @throws GuzzleException|TransformResponseException |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function sellLimit(string $market, float $quantity, float $rate, $useAwards = false): array |
|
50
|
|
|
{ |
|
51
|
|
|
$newOrder = [ |
|
52
|
1 |
|
'marketSymbol' => $market, |
|
53
|
1 |
|
'direction' => 'SELL', |
|
54
|
1 |
|
'type' => 'LIMIT', |
|
55
|
1 |
|
'quantity' => $quantity, |
|
56
|
1 |
|
'limit' => $rate, |
|
57
|
1 |
|
'timeInForce' => 'GOOD_TIL_CANCELLED', |
|
58
|
1 |
|
'useAwards' => $useAwards |
|
59
|
|
|
|
|
60
|
|
|
]; |
|
61
|
1 |
|
$options = ['body' => json_encode($newOrder)]; |
|
62
|
|
|
|
|
63
|
1 |
|
return $this->rest('POST', '/orders', $options); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $uuid |
|
68
|
|
|
* @return array |
|
69
|
|
|
* @throws GuzzleException|TransformResponseException |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function cancel(string $uuid): array |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->rest('DELETE', '/orders/' . $uuid); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param string|null $market |
|
78
|
|
|
* @param bool|null $needSequence if true additional member of array named Sequence added to return |
|
79
|
|
|
* @return array |
|
80
|
|
|
* @throws GuzzleException|TransformResponseException |
|
81
|
|
|
*/ |
|
82
|
2 |
|
public function getOpenOrders(?string $market = null, ?bool $needSequence = null): array |
|
83
|
|
|
{ |
|
84
|
2 |
|
$options = []; |
|
85
|
2 |
|
if (!is_null($market)) $options['query'] = ['marketSymbol' => $market]; |
|
86
|
|
|
|
|
87
|
2 |
|
return $this->rest('GET', '/orders/open', $options, ($needSequence)); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return int Current Sequence of Orders |
|
92
|
|
|
* @throws GuzzleException |
|
93
|
|
|
* @throws TransformResponseException |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function headOpenOrders(): int |
|
96
|
|
|
{ |
|
97
|
1 |
|
$responseArray = $this->rest('HEAD', '/orders/open', [], true); |
|
98
|
1 |
|
return $responseArray['Sequence']; |
|
99
|
|
|
} |
|
100
|
|
|
} |