Field Manual Brokerage / Linux / Laravel
← Laravel

app/Http/Requests/StoreOrderRequest.php

Paste the complete file at this path. Names and paths are case-sensitive on Linux.

What it is

Complete brokerage practice file. The Assemble project page lists every file in order.

When to use it

Paste the complete file at this path. Names and paths are case-sensitive on Linux.

Syntax

mkdir -p 'app/Http/Requests'
# Paste the Example below into app/Http/Requests/StoreOrderRequest.php

Example

<?php

declare(strict_types=1);

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreOrderRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'symbol' => ['required', 'string', 'regex:/^[A-Z]{1,5}$/'],
            'side' => ['required', 'in:buy,sell'],
            'type' => ['required', 'in:limit,market'],
            'quantity' => ['required', 'integer', 'min:1', 'max:1000000'],
            'price' => ['exclude_if:type,market', 'required_if:type,limit', 'nullable', 'numeric', 'gt:0', 'decimal:0,4', 'max:99999999.9999'],
        ];
    }

    public function messages(): array
    {
        return [
            'symbol.required' => 'Symbol is required.',
            'symbol.string' => 'Symbol must be text.',
            'symbol.regex' => 'Use 1 to 5 uppercase letters for the symbol.',
            'side.required' => 'Choose buy or sell.',
            'side.in' => 'Side must be buy or sell.',
            'type.required' => 'Choose a limit or market order.',
            'type.in' => 'Order type must be limit or market.',
            'quantity.required' => 'Quantity is required.',
            'quantity.integer' => 'Quantity must be a whole number.',
            'quantity.min' => 'Quantity must be at least 1.',
            'quantity.max' => 'Quantity must not exceed 1,000,000.',
            'price.required_if' => 'Price is required for limit orders.',
            'price.numeric' => 'Price must be a number.',
            'price.gt' => 'Price must be greater than zero.',
            'price.decimal' => 'Price must have at most 4 decimal places.',
            'price.max' => 'Price must not exceed 99,999,999.9999.',
        ];
    }
}

Common mistakes

Use the setup runbook first. Adapt provisional API assumptions to the supplied contract. Merge into supplied applications; do not duplicate the orders migration.

Related topics

API contract: change these points first