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