-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3a94ab6
Showing
21 changed files
with
975 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
vendor | ||
composer.lock | ||
.idea | ||
build | ||
phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2017, Vladymyr Svyryd | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# bitfinex-api | ||
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 | ||
## Requirements | ||
|
||
- PHP >= 7.1 | ||
|
||
## Installation | ||
|
||
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). | ||
|
||
Either run | ||
|
||
```bash | ||
$ composer require codenix-sv/bitfinex-api:~0.2 | ||
``` | ||
or add | ||
|
||
```json | ||
"codenix-sv/bitfinex-api" : "~0.2" | ||
``` | ||
|
||
to the require section of your application's `composer.json` file. | ||
|
||
## Basic usage | ||
|
||
### Example | ||
```php | ||
use codenixsv\Bitfinex\BitfinexManager; | ||
|
||
$manager = new BitfinexManager(); | ||
$client = $manager->createClient(); | ||
|
||
$responce = $client->getTicker('btcusd'); | ||
``` | ||
### Available methods | ||
|
||
#### Public API | ||
|
||
##### Get ticker | ||
```php | ||
$responce = $client->getTicker('btcusd'); | ||
``` | ||
##### Various statistics about the requested pair. | ||
```php | ||
$responce = $client->getStats('btcusd'); | ||
``` | ||
##### Get the full margin funding book. | ||
```php | ||
$responce = $client->getFundingBook('usd'); | ||
``` | ||
##### Get the full order book.. | ||
```php | ||
$responce = $client->getOrderBook('btcusd'); | ||
``` | ||
##### Get a list of the most recent trades for the given symbol. | ||
```php | ||
$responce = $client->getTrades('btcusd'); | ||
``` | ||
##### 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. | ||
```php | ||
$responce = $client->getLends('usd'); | ||
``` | ||
##### Get a list of symbol names. | ||
```php | ||
$responce = $client->getSymbols(); | ||
``` | ||
##### Get a list of valid symbol IDs and the pair details. | ||
```php | ||
$responce = $client->getSymbolsDetails(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "codenix-sv/bitfinex-api", | ||
"description": "PHP client for the Bitfinex API", | ||
"keywords": [ | ||
"bitfinex", | ||
"bitcoin", | ||
"btc", | ||
"bitfinex-api" | ||
], | ||
"type": "library", | ||
"license": "BSD-3-Clause", | ||
"support": { | ||
"issues": "https://github.com/codenix-sv/bitfinex-api/issues?state=open", | ||
"source": "https://github.com/codenix-sv/bitfinex-api" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Vladymyr Svyryd", | ||
"email": "codenix.sv@gmail.com", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "~6.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"codenixsv\\Bitfinex\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"codenixsv\\B itfinex\\": "tests/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Bitfinex API Unit Test Suite"> | ||
<directory>./tests/unit</directory> | ||
</testsuite> | ||
<testsuite name="Bitfinex API Functional Test Suite"> | ||
<directory>./tests/functional</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">./src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/> | ||
<log type="coverage-text" target="build/coverage.txt"/> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* @link https://github.com/codenix-sv/bitfinex-api | ||
* @copyright Copyright (c) 2018 codenix-sv | ||
* @license https://github.com/codenix-sv/bitfinex-api/blob/master/LICENSE | ||
*/ | ||
|
||
namespace codenixsv\Bitfinex; | ||
|
||
use codenixsv\Bitfinex\Clients\BitfinexClient; | ||
use codenixsv\Bitfinex\Http\CurlHttpClient; | ||
use codenixsv\Bitfinex\Requests\Managers\PublicBitfinexRequestManager; | ||
|
||
/** | ||
* Class BitfinexManager | ||
* @package codenixsv\Bitfinex | ||
*/ | ||
class BitfinexManager | ||
{ | ||
/** | ||
* @return BitfinexClient | ||
*/ | ||
public function createClient(): BitfinexClient | ||
{ | ||
$httpClient = new CurlHttpClient(); | ||
$publicRequestManager = new PublicBitfinexRequestManager(); | ||
|
||
return new BitfinexClient($httpClient, $publicRequestManager); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* @link https://github.com/codenix-sv/bitfinex-api | ||
* @copyright Copyright (c) 2018 codenix-sv | ||
* @license https://github.com/codenix-sv/bitfinex-api/blob/master/LICENSE | ||
*/ | ||
|
||
namespace codenixsv\Bitfinex\Clients; | ||
|
||
use codenixsv\Bitfinex\Http\HttpClient; | ||
use codenixsv\Bitfinex\Requests\Managers\RequestManager; | ||
|
||
/** | ||
* Class BitfinexClient | ||
* @package codenixsv\Bitfinex\Clients | ||
*/ | ||
class BitfinexClient extends Client | ||
{ | ||
/** | ||
* @var RequestManager | ||
*/ | ||
private $publicRequestManager; | ||
|
||
/** | ||
* BitfinexClient constructor. | ||
* @param HttpClient $httpClient | ||
* @param RequestManager $publicRequestManager | ||
*/ | ||
public function __construct( | ||
HttpClient $httpClient, | ||
RequestManager $publicRequestManager | ||
) { | ||
parent::__construct($httpClient); | ||
|
||
$this->publicRequestManager = $publicRequestManager; | ||
} | ||
|
||
/* | ||
*************************** Public API ************************** | ||
*/ | ||
|
||
/** | ||
* @param string $symbol | ||
* @return mixed | ||
* @see https://bitfinex.readme.io/v1/reference#rest-public-ticker | ||
*/ | ||
public function getTicker(string $symbol) | ||
{ | ||
$request = $this->publicRequestManager->createGetRequest('/pubticker/' . $symbol); | ||
|
||
return $this->get($request); | ||
} | ||
|
||
/** | ||
* Various statistics about the requested pair. | ||
* @param string $symbol | ||
* @return mixed | ||
* @see https://bitfinex.readme.io/v1/reference#rest-public-stats | ||
*/ | ||
public function getStats(string $symbol) | ||
{ | ||
$request = $this->publicRequestManager->createGetRequest('/stats/' . $symbol); | ||
|
||
return $this->get($request); | ||
} | ||
|
||
/** | ||
* Get the full margin funding book | ||
* @param string $currency | ||
* @return mixed | ||
* @see https://bitfinex.readme.io/v1/reference#rest-public-fundingbook | ||
*/ | ||
public function getFundingBook(string $currency) | ||
{ | ||
$request = $this->publicRequestManager->createGetRequest('/lendbook/' . $currency); | ||
|
||
return $this->get($request); | ||
} | ||
|
||
/** | ||
* Get the full order book | ||
* @param string $symbol | ||
* @return mixed | ||
* @see https://bitfinex.readme.io/v1/reference#rest-public-orderbook | ||
*/ | ||
public function getOrderBook(string $symbol) | ||
{ | ||
$request = $this->publicRequestManager->createGetRequest('/book/' . $symbol); | ||
|
||
return $this->get($request); | ||
} | ||
|
||
/** | ||
* Get a list of the most recent trades for the given symbol. | ||
* @param string $symbol | ||
* @return mixed | ||
* @see https://bitfinex.readme.io/v1/reference#rest-public-trades | ||
*/ | ||
public function getTrades(string $symbol) | ||
{ | ||
$request = $this->publicRequestManager->createGetRequest('/trades/' . $symbol); | ||
|
||
return $this->get($request); | ||
} | ||
|
||
/** | ||
* 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. | ||
* @param string $currency | ||
* @return mixed | ||
* @see https://bitfinex.readme.io/v1/reference#rest-public-lends | ||
*/ | ||
public function getLends(string $currency) | ||
{ | ||
$request = $this->publicRequestManager->createGetRequest('/lends/' . $currency); | ||
|
||
return $this->get($request); | ||
} | ||
|
||
/** | ||
* A list of symbol names. | ||
* @return mixed | ||
* @see https://bitfinex.readme.io/v1/reference#rest-public-symbols | ||
*/ | ||
public function getSymbols() | ||
{ | ||
$request = $this->publicRequestManager->createGetRequest('/symbols'); | ||
|
||
return $this->get($request); | ||
} | ||
|
||
/** | ||
* Get a list of valid symbol IDs and the pair details. | ||
* @return mixed | ||
* @see https://bitfinex.readme.io/v1/reference#rest-public-symbol-details | ||
*/ | ||
public function getSymbolsDetails() | ||
{ | ||
$request = $this->publicRequestManager->createGetRequest('/symbols_details'); | ||
|
||
return $this->get($request); | ||
} | ||
} |
Oops, something went wrong.