Skip to content

Commit aef241e

Browse files
committed
Cleanup
1 parent 3edc47f commit aef241e

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

README.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
[![Total Downloads](https://img.shields.io/packagist/dt/xrplwin/xrpl-orderbook-reader.svg?style=flat)](https://packagist.org/packages/xrplwin/xrpl-orderbook-reader)
44

55
# XRPL Orderbook Reader for PHP
6-
7-
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))
8-
96
This repository takes XRPL Orderbook (`book_offers`) datasets and requested volume to
107
exchange and calculates the effective exchange rates based on the requested and available liquidity.
118

129
Optionally certain checks can be specified (eg. `book_offers` on the other side of the book)
1310
to warn for limited (percentage) liquidity on the requested side, and possibly other side
1411
of the order book.
1512

13+
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))
14+
1615
# Note
1716

1817
This package is provided as is, please test it yourself first.
@@ -35,38 +34,47 @@ use \XRPLWin\XRPL\Client;
3534

3635
$xrplwinapiclient = new Client([]);
3736
$lc = new LiquidityCheck([
38-
# Trade:
39-
'from' => [
40-
'currency' => 'XRP'
41-
],
42-
'to' => [
43-
'currency' => 'USD',
44-
'issuer' => 'rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq'
45-
],
46-
'amount' => 10,
47-
'limit' => 100
37+
# Trade:
38+
'from' => [
39+
'currency' => 'XRP'
40+
],
41+
'amount' => 10,
42+
'to' => [
43+
'currency' => 'USD',
44+
'issuer' => 'rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq'
45+
],
4846
],
4947
[
50-
# Options:
51-
//'rates' => 'to',
52-
//'maxSpreadPercentage' => 4
53-
//'maxSlippagePercentage' => 3
54-
//'maxSlippagePercentageReverse' => 3
55-
'includeBookData' => true //default false
48+
# Options:
49+
//'rates' => 'to',
50+
//'maxSpreadPercentage' => 4,
51+
//'maxSlippagePercentage' => 3,
52+
//'maxSlippagePercentageReverse' => 3,
53+
//'maxBookLines' => 500,
54+
'includeBookData' => true //default false
5655
], $xrplwinapiclient);
5756

5857
try {
59-
$Liquidity = $lc->get();
58+
$Liquidity = $lc->get();
6059
} catch (\Exception) {
61-
//Unable to connect to provided XRPL server...
62-
$Liquidity = [
63-
'rate' => null,
64-
'safe' => false,
65-
'errors' => ['CONNECT_ERROR']
66-
];
60+
//Unable to connect to provided XRPL server...
61+
$Liquidity = [
62+
'rate' => null,
63+
'safe' => false,
64+
'errors' => ['CONNECT_ERROR']
65+
];
6766
}
6867

69-
print_r($Liquidity); //['rate' => NUMBER, 'safe' => BOOLEAN, 'errors' => ARRAY, 'books' => ARRAY]
68+
print_r($Liquidity);
69+
/**
70+
* [
71+
* 'rate' => NUMBER,
72+
* 'safe' => BOOLEAN,
73+
* 'errors' => ARRAY,
74+
* 'books' => ARRAY
75+
* ]
76+
**/
77+
//
7078
```
7179
## Running tests
7280
Run all tests in "tests" directory.
@@ -80,4 +88,4 @@ or
8088

8189
### Sample
8290

83-
See [dev.php](dev.php) for sample.
91+
See [sample.php](sample.php)
File renamed without changes.

src/LiquidityCheck.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ class LiquidityCheck
1616
const ERROR_MAX_SLIPPAGE_EXCEEDED = 'MAX_SLIPPAGE_EXCEEDED';
1717
const ERROR_MAX_REVERSE_SLIPPAGE_EXCEEDED = 'MAX_REVERSE_SLIPPAGE_EXCEEDED';
1818

19-
const PRECISION = 17;
20-
/**
21-
* PRECISION_CAPPED:
22-
* Due to divisions, calculated values must be rounded to PRECISION,
23-
* sum of fields _I_Spend_Capped and _I_Get_Capped can be very close approximation of
24-
* TradeAmount. To create correct comparison of TradeAmount === _I_Spend_Capped or _I_Get_Capped,
25-
* those fields are rounded to ROUNDING_MODE of PRECISION_CAPPED precision.
26-
*/
27-
const PRECISION_CAPPED = 10;
19+
const NATURAL_PRECISION = 17;
2820
const ROUNDING_MODE = RoundingMode::HALF_UP;
2921

3022
protected XRPLWinClient $client;
@@ -270,7 +262,7 @@ private function detectErrors(array $book, array $bookReversed): array
270262
}
271263

272264
if($this->options['maxSpreadPercentage']) {
273-
$spread = BigDecimal::one()->minus( $startRate->dividedBy($startRateReverse,self::PRECISION,self::ROUNDING_MODE) )->multipliedBy(100)->abs();
265+
$spread = BigDecimal::one()->minus( $startRate->dividedBy($startRateReverse,self::NATURAL_PRECISION,self::ROUNDING_MODE) )->multipliedBy(100)->abs();
274266

275267
//todo: log
276268

@@ -279,7 +271,7 @@ private function detectErrors(array $book, array $bookReversed): array
279271
}
280272

281273
if($this->options['maxSlippagePercentage']) {
282-
$slippage = BigDecimal::one()->minus( $startRate->dividedBy($finalRate,self::PRECISION,self::ROUNDING_MODE) )->multipliedBy(100)->abs();
274+
$slippage = BigDecimal::one()->minus( $startRate->dividedBy($finalRate,self::NATURAL_PRECISION,self::ROUNDING_MODE) )->multipliedBy(100)->abs();
283275
//die((string)$finalRate);
284276
//todo: log
285277

@@ -288,7 +280,7 @@ private function detectErrors(array $book, array $bookReversed): array
288280
}
289281

290282
if($this->options['maxSlippagePercentageReverse']) {
291-
$slippage = BigDecimal::one()->minus( $startRateReverse->dividedBy($finalRateReverse,self::PRECISION,self::ROUNDING_MODE) )->multipliedBy(100)->abs();
283+
$slippage = BigDecimal::one()->minus( $startRateReverse->dividedBy($finalRateReverse,self::NATURAL_PRECISION,self::ROUNDING_MODE) )->multipliedBy(100)->abs();
292284

293285
//todo: log
294286

src/LiquidityParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static function parse(array $offers, array $from, array $to, mixed $amoun
200200
unset($v['_I_Spend']);
201201
unset($v['_I_Get']);
202202
unset($v['taker_pays_funded']);
203-
203+
unset($v['taker_gets_funded']);
204204
unset($v['index']);
205205
unset($v['owner_funds']);
206206
unset($v['quality']);

tests/CalculatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public function renderTable(array $data): void
367367

368368
} else {
369369
$table->addColumn(
370-
'Value: '.$v->value
370+
$v->value
371371
);
372372
}
373373
}

0 commit comments

Comments
 (0)