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 (@XRPL Labs)
This package is provided as is, please test it yourself first.
Found a bug? Report issue here
- PHP 8.1 or higher
- Composer
To install run
composer require xrplwin/xrpl-orderbook-reader
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
* ]
**/
Run all tests in "tests" directory.
composer test
or
./vendor/bin/phpunit --testdox
See sample.php