Every exception extends RoundlyConsulting\TradingAnalytics\Exceptions\TradingAnalyticsException (a RuntimeException), so you can catch them all with one catch:
use RoundlyConsulting\TradingAnalytics\Exceptions\TradingAnalyticsException;
use RoundlyConsulting\TradingAnalytics\Facades\TradingAnalytics;
try {
$analytics = TradingAnalytics::for($rows)->scale($scale)->calculate();
} catch (TradingAnalyticsException $e) {
// an invalid trade row, an unordered source, a chunk size below 1, a negative scale,
// a non-numeric value, a division by zero, an unknown calculator or engine
report($e);
}| Exception | Named constructors | Thrown when |
|---|---|---|
InvalidTradeException | emptyCurrency, closeBeforeOpen, missingField, invalidField, invalidDirection | An empty base or quote currency, a close time before the open time, a missing or null required field, a field of the wrong type, or a direction other than buy / sell. |
UnorderedTradeSourceException | for, outOfOrder | A query passed as a trade source without an orderBy, or a realized trade that arrives after one that closed later. |
InvalidChunkSizeException | tooSmall | A chunk below 1. |
InvalidScaleException | negative | A negative scale. |
InvalidNumericOperationException | nonNumericValue, outOfRange, fractionalExponent | A non-numeric input (INF and NAN included), an exponent above 1000, or a fractional pow() exponent. |
DivisionByZeroException | make | Division by zero. |
UnknownCalculatorException | notACalculator | only() / except() / calculate(only: …) given a class that is not a registered calculator. |
InvalidEngineException | notAnAnalyticsEngine | TradingAnalytics::using() given a class that isn’t Analytics or a subclass of it. |
Trade::collect() is lazy: an invalid row or an out-of-order trade throws while calculate() consumes it, not when the collection is built. A query without an orderBy and a chunk below 1 throw as soon as the source is passed in.
A malformed scale or win_rate_period config is the one exception outside this family: it throws package-toolkit’s InvalidConfigurationException, naming the key, as soon as the engine is built.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.