1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI; |
4
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Auth\Credentials; |
6
|
|
|
use Carpenstar\ByBitAPI\Core\Builders\RestBuilder; |
7
|
|
|
use Carpenstar\ByBitAPI\Core\Exceptions\SDKException; |
8
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\AbstractParameters; |
9
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IEndpointInterface; |
10
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseInterface; |
11
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IParametersInterface; |
12
|
|
|
use Carpenstar\ByBitAPI\WebSocketsV5\SocketAPI; |
|
|
|
|
13
|
|
|
|
14
|
|
|
class BybitAPI |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Параметры подключения к ByBit |
18
|
|
|
* |
19
|
|
|
* @var Credentials |
20
|
|
|
*/ |
21
|
|
|
protected Credentials $credentials; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Конструктор приложения. |
25
|
|
|
* |
26
|
|
|
* @param string|null $host |
27
|
|
|
*/ |
28
|
|
|
public function __construct(string $host = null) |
29
|
|
|
{ |
30
|
|
|
$this->credentials = new Credentials(); |
31
|
|
|
$this->credentials->setHost($host); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $host |
36
|
|
|
* @param string $apiKey |
37
|
|
|
* @param string $secret |
38
|
|
|
* @return $this |
39
|
|
|
*/ |
40
|
|
|
public function setCredentials(string $host, string $apiKey = '', string $secret = ''): self |
41
|
|
|
{ |
42
|
|
|
$this->credentials = (new Credentials()) |
43
|
|
|
->setHost($host) |
44
|
|
|
->setApiKey($apiKey) |
45
|
|
|
->setSecret($secret); |
46
|
|
|
|
47
|
|
|
return $this; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $host |
52
|
|
|
* @return $this |
53
|
|
|
*/ |
54
|
|
|
public function setHost(string $host): self |
55
|
|
|
{ |
56
|
|
|
$this->credentials->setHost($host); |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param string $apiKey |
62
|
|
|
* @return $this |
63
|
|
|
*/ |
64
|
|
|
public function setApiKey(string $apiKey): self |
65
|
|
|
{ |
66
|
|
|
$this->setApiKey($apiKey); |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $secret |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function setSecret(string $secret): self |
75
|
|
|
{ |
76
|
|
|
$this->credentials->setSecret($secret); |
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Модуль для подключения к сокет-соединениям |
82
|
|
|
* |
83
|
|
|
* @return SocketAPI |
84
|
|
|
* @throws SDKException |
85
|
|
|
*/ |
86
|
|
|
public function websockets(): SocketAPI |
87
|
|
|
{ |
88
|
|
|
return new SocketAPI($this->credentials); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
// TODO publicEndpoint, privateEndpoint, endpoint отделить в модуль rest |
93
|
|
|
/** |
94
|
|
|
* @param string $endpointClassName |
95
|
|
|
* @param IParametersInterface|null $parameters |
96
|
|
|
* @return IResponseInterface |
97
|
|
|
* @throws SDKException |
98
|
|
|
*/ |
99
|
|
|
public function publicEndpoint(string $endpointClassName, ?IParametersInterface $parameters = null): IEndpointInterface |
100
|
|
|
{ |
101
|
|
|
if (empty($this->credentials->getHost())) { |
102
|
|
|
throw new SDKException("Host must be specified"); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $this->endpoint($endpointClassName, $parameters); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param string $endpointClassName |
110
|
|
|
* @param IParametersInterface|null $parameters |
111
|
|
|
* @return IResponseInterface |
112
|
|
|
* @throws SDKException |
113
|
|
|
*/ |
114
|
|
|
public function privateEndpoint(string $endpointClassName, ?IParametersInterface $parameters = null): IEndpointInterface |
115
|
|
|
{ |
116
|
|
|
if (empty($this->credentials->getHost())) { |
117
|
|
|
throw new SDKException("Host must be specified"); |
118
|
|
|
} |
119
|
|
|
if (empty($this->credentials->getApiKey())) { |
120
|
|
|
throw new SDKException("Api key must be specified"); |
121
|
|
|
} |
122
|
|
|
if (empty($this->credentials->getSecret())) { |
123
|
|
|
throw new SDKException("Client secret must be specified"); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $this->endpoint($endpointClassName, $parameters); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $endpointClassName |
131
|
|
|
* @param AbstractParameters $params |
132
|
|
|
* @return IEndpointInterface |
133
|
|
|
* @throws \Exception |
134
|
|
|
*/ |
135
|
|
|
private function endpoint(string $endpointClassName, AbstractParameters $parameters = null): IEndpointInterface |
136
|
|
|
{ |
137
|
|
|
return RestBuilder::make($endpointClassName, $this->credentials, $parameters); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths