---
title: "Direction & Period enums — Trading Analytics for Laravel | Roundly"
description: "The buy/sell Direction and daily/weekly/monthly Period enums, their domain methods and the shared select and validation helpers."
url: https://roundly-consulting.com/open-source/docs/trading-analytics-for-laravel/enums
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)

# Direction & Period enums

Two string-backed enums: Direction (BUY = buy, SELL = sell) and Period (DAILY, WEEKLY, MONTHLY). Their domain methods:

```php
use Illuminate\Support\Carbon;
use RoundlyConsulting\TradingAnalytics\Enums\Direction;
use RoundlyConsulting\TradingAnalytics\Enums\Period;

Direction::BUY->isBuy();     // true
Direction::SELL->isSell();   // true
Direction::from('sell');     // Direction::SELL

Period::DAILY->bucketFor(Carbon::parse('2024-03-05'));   // '2024-03-05'
Period::WEEKLY->bucketFor(Carbon::parse('2024-03-05'));  // '2024-W10'
Period::MONTHLY->bucketFor(Carbon::parse('2024-03-05')); // '2024-03'
```

bucketFor() reads the moment in the default timezone — the app timezone in Laravel — so one instant written with two offsets (+00:00 and -05:00) lands in one bucket.

## Select and validation helpers

Both enums adopt the shared helper toolkit from enums-for-laravel, so they expose a full select/validation surface out of the box. Labels go through Laravel’s translator:

```php
Direction::validationRule();   // "in:buy,sell"
Period::validationRule();      // "in:daily,weekly,monthly"

Period::toOptions()->all();    // ['daily' => 'Daily', 'weekly' => 'Weekly', 'monthly' => 'Monthly']
Direction::options();          // Collection<EnumOption{value,label,name}> for JS/Inertia selects
Period::labels()->all();       // ['Daily', 'Weekly', 'Monthly']
Period::values()->all();       // ['daily', 'weekly', 'monthly']
```

For example, to let users choose the reporting period:

```php
$validated = $request->validate([
    'period' => ['nullable', Period::validationRule()],
]);

$analytics = TradingAnalytics::for($trades)
    ->usingWinRatePeriod(Period::from($validated['period'] ?? 'daily'))
    ->calculate();
```

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