Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit 3a94ab6

Browse files
committed
Init
0 parents  commit 3a94ab6

21 files changed

+975
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vendor
2+
composer.lock
3+
.idea
4+
build
5+
phpunit.xml

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2017, Vladymyr Svyryd
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# bitfinex-api
2+
A simple PHP wrapper for [Bitfinex API](https://docs.bitfinex.com/docs). [Bitfinex](https://www.bitfinex.com) The world's largest and most advanced cryptocurrency trading platform
3+
## Requirements
4+
5+
- PHP >= 7.1
6+
7+
## Installation
8+
9+
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
10+
11+
Either run
12+
13+
```bash
14+
$ composer require codenix-sv/bitfinex-api:~0.2
15+
```
16+
or add
17+
18+
```json
19+
"codenix-sv/bitfinex-api" : "~0.2"
20+
```
21+
22+
to the require section of your application's `composer.json` file.
23+
24+
## Basic usage
25+
26+
### Example
27+
```php
28+
use codenixsv\Bitfinex\BitfinexManager;
29+
30+
$manager = new BitfinexManager();
31+
$client = $manager->createClient();
32+
33+
$responce = $client->getTicker('btcusd');
34+
```
35+
### Available methods
36+
37+
#### Public API
38+
39+
##### Get ticker
40+
```php
41+
$responce = $client->getTicker('btcusd');
42+
```
43+
##### Various statistics about the requested pair.
44+
```php
45+
$responce = $client->getStats('btcusd');
46+
```
47+
##### Get the full margin funding book.
48+
```php
49+
$responce = $client->getFundingBook('usd');
50+
```
51+
##### Get the full order book..
52+
```php
53+
$responce = $client->getOrderBook('btcusd');
54+
```
55+
##### Get a list of the most recent trades for the given symbol.
56+
```php
57+
$responce = $client->getTrades('btcusd');
58+
```
59+
##### Get a list of the most recent funding data for the given currency: total amount provided and Flash Return Rate (in % by 365 days) over time.
60+
```php
61+
$responce = $client->getLends('usd');
62+
```
63+
##### Get a list of symbol names.
64+
```php
65+
$responce = $client->getSymbols();
66+
```
67+
##### Get a list of valid symbol IDs and the pair details.
68+
```php
69+
$responce = $client->getSymbolsDetails();
70+
```

composer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "codenix-sv/bitfinex-api",
3+
"description": "PHP client for the Bitfinex API",
4+
"keywords": [
5+
"bitfinex",
6+
"bitcoin",
7+
"btc",
8+
"bitfinex-api"
9+
],
10+
"type": "library",
11+
"license": "BSD-3-Clause",
12+
"support": {
13+
"issues": "https://github.com/codenix-sv/bitfinex-api/issues?state=open",
14+
"source": "https://github.com/codenix-sv/bitfinex-api"
15+
},
16+
"authors": [
17+
{
18+
"name": "Vladymyr Svyryd",
19+
"email": "codenix.sv@gmail.com",
20+
"role": "Developer"
21+
}
22+
],
23+
"require": {
24+
"php": ">=7.1"
25+
},
26+
"require-dev": {
27+
"phpunit/phpunit": "~6.0"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"codenixsv\\Bitfinex\\": "src/"
32+
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"codenixsv\\B itfinex\\": "tests/"
37+
}
38+
}
39+
}

phpunit.xml.dist

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Bitfinex API Unit Test Suite">
14+
<directory>./tests/unit</directory>
15+
</testsuite>
16+
<testsuite name="Bitfinex API Functional Test Suite">
17+
<directory>./tests/functional</directory>
18+
</testsuite>
19+
</testsuites>
20+
<filter>
21+
<whitelist>
22+
<directory suffix=".php">./src/</directory>
23+
</whitelist>
24+
</filter>
25+
<logging>
26+
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
27+
<log type="coverage-text" target="build/coverage.txt"/>
28+
<log type="coverage-clover" target="build/logs/clover.xml"/>
29+
</logging>
30+
</phpunit>

src/BitfinexManager.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @link https://github.com/codenix-sv/bitfinex-api
5+
* @copyright Copyright (c) 2018 codenix-sv
6+
* @license https://github.com/codenix-sv/bitfinex-api/blob/master/LICENSE
7+
*/
8+
9+
namespace codenixsv\Bitfinex;
10+
11+
use codenixsv\Bitfinex\Clients\BitfinexClient;
12+
use codenixsv\Bitfinex\Http\CurlHttpClient;
13+
use codenixsv\Bitfinex\Requests\Managers\PublicBitfinexRequestManager;
14+
15+
/**
16+
* Class BitfinexManager
17+
* @package codenixsv\Bitfinex
18+
*/
19+
class BitfinexManager
20+
{
21+
/**
22+
* @return BitfinexClient
23+
*/
24+
public function createClient(): BitfinexClient
25+
{
26+
$httpClient = new CurlHttpClient();
27+
$publicRequestManager = new PublicBitfinexRequestManager();
28+
29+
return new BitfinexClient($httpClient, $publicRequestManager);
30+
}
31+
}

src/Clients/BitfinexClient.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @link https://github.com/codenix-sv/bitfinex-api
5+
* @copyright Copyright (c) 2018 codenix-sv
6+
* @license https://github.com/codenix-sv/bitfinex-api/blob/master/LICENSE
7+
*/
8+
9+
namespace codenixsv\Bitfinex\Clients;
10+
11+
use codenixsv\Bitfinex\Http\HttpClient;
12+
use codenixsv\Bitfinex\Requests\Managers\RequestManager;
13+
14+
/**
15+
* Class BitfinexClient
16+
* @package codenixsv\Bitfinex\Clients
17+
*/
18+
class BitfinexClient extends Client
19+
{
20+
/**
21+
* @var RequestManager
22+
*/
23+
private $publicRequestManager;
24+
25+
/**
26+
* BitfinexClient constructor.
27+
* @param HttpClient $httpClient
28+
* @param RequestManager $publicRequestManager
29+
*/
30+
public function __construct(
31+
HttpClient $httpClient,
32+
RequestManager $publicRequestManager
33+
) {
34+
parent::__construct($httpClient);
35+
36+
$this->publicRequestManager = $publicRequestManager;
37+
}
38+
39+
/*
40+
*************************** Public API **************************
41+
*/
42+
43+
/**
44+
* @param string $symbol
45+
* @return mixed
46+
* @see https://bitfinex.readme.io/v1/reference#rest-public-ticker
47+
*/
48+
public function getTicker(string $symbol)
49+
{
50+
$request = $this->publicRequestManager->createGetRequest('/pubticker/' . $symbol);
51+
52+
return $this->get($request);
53+
}
54+
55+
/**
56+
* Various statistics about the requested pair.
57+
* @param string $symbol
58+
* @return mixed
59+
* @see https://bitfinex.readme.io/v1/reference#rest-public-stats
60+
*/
61+
public function getStats(string $symbol)
62+
{
63+
$request = $this->publicRequestManager->createGetRequest('/stats/' . $symbol);
64+
65+
return $this->get($request);
66+
}
67+
68+
/**
69+
* Get the full margin funding book
70+
* @param string $currency
71+
* @return mixed
72+
* @see https://bitfinex.readme.io/v1/reference#rest-public-fundingbook
73+
*/
74+
public function getFundingBook(string $currency)
75+
{
76+
$request = $this->publicRequestManager->createGetRequest('/lendbook/' . $currency);
77+
78+
return $this->get($request);
79+
}
80+
81+
/**
82+
* Get the full order book
83+
* @param string $symbol
84+
* @return mixed
85+
* @see https://bitfinex.readme.io/v1/reference#rest-public-orderbook
86+
*/
87+
public function getOrderBook(string $symbol)
88+
{
89+
$request = $this->publicRequestManager->createGetRequest('/book/' . $symbol);
90+
91+
return $this->get($request);
92+
}
93+
94+
/**
95+
* Get a list of the most recent trades for the given symbol.
96+
* @param string $symbol
97+
* @return mixed
98+
* @see https://bitfinex.readme.io/v1/reference#rest-public-trades
99+
*/
100+
public function getTrades(string $symbol)
101+
{
102+
$request = $this->publicRequestManager->createGetRequest('/trades/' . $symbol);
103+
104+
return $this->get($request);
105+
}
106+
107+
/**
108+
* Get a list of the most recent funding data for the given currency: total amount provided and
109+
* Flash Return Rate (in % by 365 days) over time.
110+
* @param string $currency
111+
* @return mixed
112+
* @see https://bitfinex.readme.io/v1/reference#rest-public-lends
113+
*/
114+
public function getLends(string $currency)
115+
{
116+
$request = $this->publicRequestManager->createGetRequest('/lends/' . $currency);
117+
118+
return $this->get($request);
119+
}
120+
121+
/**
122+
* A list of symbol names.
123+
* @return mixed
124+
* @see https://bitfinex.readme.io/v1/reference#rest-public-symbols
125+
*/
126+
public function getSymbols()
127+
{
128+
$request = $this->publicRequestManager->createGetRequest('/symbols');
129+
130+
return $this->get($request);
131+
}
132+
133+
/**
134+
* Get a list of valid symbol IDs and the pair details.
135+
* @return mixed
136+
* @see https://bitfinex.readme.io/v1/reference#rest-public-symbol-details
137+
*/
138+
public function getSymbolsDetails()
139+
{
140+
$request = $this->publicRequestManager->createGetRequest('/symbols_details');
141+
142+
return $this->get($request);
143+
}
144+
}

0 commit comments

Comments
 (0)