---
title: "The TradingAnalytics facade — Trading Analytics for Laravel | Roundly"
description: "The whole API on one facade — build or run the engine for trades, rows or a query, map rows lazily, list calculators and swap in your engine."
url: https://roundly-consulting.com/open-source/docs/trading-analytics-for-laravel/facade
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Trading Analytics for Laravel](https://roundly-consulting.com/open-source/docs/trading-analytics-for-laravel.md)

# The TradingAnalytics facade

RoundlyConsulting\\TradingAnalytics\\Facades\\TradingAnalytics is the recommended entry point. Its root is RoundlyConsulting\\TradingAnalytics\\TradingAnalyticsManager, a container singleton that normalises the input and builds the Analytics engine. Every method takes a trade source: any iterable of trades or rows (anything Trade::fromRow() reads, Trade objects included, or a mix), or an ordered query — a query builder, an Eloquent builder or a relation. Rows are mapped lazily:

```php
use RoundlyConsulting\TradingAnalytics\Facades\TradingAnalytics;

$analytics = TradingAnalytics::for($rows)->scale(2)->calculate(); // the engine, ready to configure
$analytics = TradingAnalytics::calculate($rows, only: [Counts::class]); // build and run in one call

// A query is a trade source too — streamed in pages of $chunk rows (default 1000)
$analytics = TradingAnalytics::calculate($account->trades()->orderBy('close_time')->orderBy('id'), chunk: 500);

$trades = TradingAnalytics::trades($rows);   // LazyCollection<int, Trade>, mapped lazily
TradingAnalytics::metrics();                 // the calculator class-strings only / except() accept

TradingAnalytics::using(DeskAnalytics::class); // build every engine from your subclass (once, in boot())
TradingAnalytics::engine();                    // 'App\Analytics\DeskAnalytics'
```

## Every method

| Facade method | Returns | Purpose |
| --- | --- | --- |
| `for($trades, int $chunk = 1000)` | `Analytics` | Build the engine for a trade source, ready to configure. |
| `calculate($trades, ?array $only = null, int $chunk = 1000)` | `Analytics` | Build and run it, optionally only some calculators. |
| `trades($rows, int $chunk = 1000)` | `LazyCollection<int, Trade>` | Map a trade source to trades lazily. |
| `metrics()` | `list<class-string>` | The calculators the engine runs — what only / except() accept. |
| `using(string $analytics)` | `TradingAnalyticsManager` | Build every engine from your Analytics subclass (see Extending the engine). |
| `engine()` | `class-string<Analytics>` | The engine class in use. |

$trades is an iterable, a query builder, an Eloquent builder or a relation; $chunk is the page size when it is a query. for() and calculate() return the Analytics engine, so everything in Running the engine — scale(), usingWinRatePeriod(), only() / except(), the hooks — chains on. The facade class has no global alias; import it where you use it.

There is no TradingAnalytics::fake(): the engine is a pure calculation with no side effects, so a test feeds it the trades it needs and asserts on the numbers (see Testing).

## 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 crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/trading-analytics-for-laravel.md)
