Passed
Branch master (0e771b)
by Vladislav
07:54
created

BybitAPI::market()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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\MarketV5\MarketAPI;
0 ignored issues
show
Bug introduced by
The type Carpenstar\ByBitAPI\MarketV5\MarketAPI was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Carpenstar\ByBitAPI\WebSocketsV5\SocketAPI;
0 ignored issues
show
Bug introduced by
The type Carpenstar\ByBitAPI\WebSocketsV5\SocketAPI was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
class BybitAPI
16
{
17
    /**
18
     * Параметры подключения к ByBit
19
     *
20
     * @var Credentials
21
     */
22
    protected Credentials $credentials;
23
24
    /**
25
     * Конструктор приложения.
26
     *
27
     * @param string|null $host
28
     */
29
    public function __construct(string $host = null)
30
    {
31
        $this->credentials = new Credentials();
32
        $this->credentials->setHost($host);
0 ignored issues
show
Bug introduced by
It seems like $host can also be of type null; however, parameter $host of Carpenstar\ByBitAPI\Core...\Credentials::setHost() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        $this->credentials->setHost(/** @scrutinizer ignore-type */ $host);
Loading history...
33
    }
34
35
    /**
36
     * @param string $host
37
     * @param string $apiKey
38
     * @param string $secret
39
     * @return $this
40
     */
41
    public function setCredentials(string $host, string $apiKey = '', string $secret = ''): self
42
    {
43
        $this->credentials = (new Credentials())
44
            ->setHost($host)
45
            ->setApiKey($apiKey)
46
            ->setSecret($secret);
47
48
        return $this;
49
    }
50
51
    /**
52
     * @param string $host
53
     * @return $this
54
     */
55
    public function setHost(string $host): self
56
    {
57
        $this->credentials->setHost($host);
58
        return $this;
59
    }
60
61
    /**
62
     * @param string $apiKey
63
     * @return $this
64
     */
65
    public function setApiKey(string $apiKey): self
66
    {
67
        $this->setApiKey($apiKey);
68
        return $this;
69
    }
70
71
    /**
72
     * @param string $secret
73
     * @return $this
74
     */
75
    public function setSecret(string $secret): self
76
    {
77
        $this->credentials->setSecret($secret);
78
        return $this;
79
    }
80
81
    /**
82
     * Модуль для подключения к сокет-соединениям
83
     *
84
     * @return SocketAPI
85
     * @throws SDKException
86
     */
87
    public function websockets(): SocketAPI
88
    {
89
        return new SocketAPI($this->credentials);
90
    }
91
92
    /**
93
     * Модуль для получения публичных рыночных данных
94
     *
95
     * @return MarketAPI
96
     */
97
    public function market(): MarketAPI
98
    {
99
        return new MarketAPI($this->credentials);
100
    }
101
}
102