https://github.com/xrplwin/xrpl-orderbook-reader
Parse XRPL Order Book results into effective liquidity based exchange prices
https://github.com/xrplwin/xrpl-orderbook-reader
Last synced: 11 months ago
JSON representation
Parse XRPL Order Book results into effective liquidity based exchange prices
- Host: GitHub
- URL: https://github.com/xrplwin/xrpl-orderbook-reader
- Owner: XRPLWin
- License: mit
- Created: 2022-03-25T07:39:23.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-01T21:02:44.000Z (about 3 years ago)
- Last Synced: 2025-07-21T12:55:43.237Z (11 months ago)
- Language: PHP
- Size: 47.9 KB
- Stars: 2
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/XRPLWin/XRPL-Orderbook-Reader/actions/workflows/main.yml)
[](https://github.com/XRPLWin/XRPL-Orderbook-Reader/blob/main/LICENSE)
[](https://packagist.org/packages/xrplwin/xrpl-orderbook-reader)
# XRPL Orderbook Reader for PHP
This repository takes XRPL Orderbook (`book_offers`) datasets and requested volume to
exchange and calculates the effective exchange rates based on the requested and available liquidity.
Optionally certain checks can be specified (eg. `book_offers` on the other side of the book)
to warn for limited (percentage) liquidity on the requested side, and possibly other side
of the order book.
This is PHP port of https://github.com/XRPL-Labs/XRPL-Orderbook-Reader by [Wietse Wind](https://github.com/WietseWind) ([@XRPL Labs](https://github.com/XRPL-Labs))
# Note
This package is provided as is, please test it yourself first.
Found a bug? [Report issue here](https://github.com/XRPLWin/XRPL-Orderbook-Reader/issues/new)
## Requirements
- PHP 8.1 or higher
- [Composer](https://getcomposer.org/)
## Installation
To install run
```
composer require xrplwin/xrpl-orderbook-reader
```
## Usage
```PHP
use \XRPLWin\XRPL\Client;
$xrplwinapiclient = new Client([]);
$lc = new LiquidityCheck([
# Trade:
'from' => [
'currency' => 'XRP'
],
'amount' => 10,
'to' => [
'currency' => 'USD',
'issuer' => 'rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq'
],
],
[
# Options:
//'rates' => 'to',
//'maxSpreadPercentage' => 4,
//'maxSlippagePercentage' => 3,
//'maxSlippagePercentageReverse' => 3,
//'maxBookLines' => 500,
'includeBookData' => true //default false
], $xrplwinapiclient);
try {
$Liquidity = $lc->get();
} catch (\Throwable) {
//Unable to connect to provided XRPL server...
$Liquidity = [
'rate' => null,
'safe' => false,
'errors' => ['CONNECT_ERROR']
];
}
print_r($Liquidity);
/**
* [
* 'rate' => NUMBER,
* 'safe' => BOOLEAN,
* 'errors' => ARRAY,
* 'books' => ARRAY
* ]
**/
```
## Running tests
Run all tests in "tests" directory.
```
composer test
```
or
```
./vendor/bin/phpunit --testdox
```
### Sample
See [sample.php](sample.php)