masyasmv / freedom-broker-api
PHP SDK & parser for Freedom24 (TraderNet) Broker API — reports, securities, quotes, orders and history
Requires
- php: ^8.0
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^7.0
- league/csv: ^9.0
- psr/http-client: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- larastan/larastan: ^1.0
- mockery/mockery: ^1.5
- orchestra/testbench: ^6.30
- orchestra/testbench-core: ^6.30
- php-coveralls/php-coveralls: ^2.8
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2025-07-10 17:04:36 UTC
README
Freedom Broker API SDK for PHP
Freedom Broker (TraderNet) API client — a lean, PSR-4, PHP 8.0+ and Laravel 8 library for:
- Authentication & Request Signing (V1, V2 cases)
- Fetching & parsing broker reports
- Retrieving securities catalog, quotes info and historical data
- Sending, cancelling and listing orders
All data comes back as strict DTOs and Collections; you handle persistence and business logic in your app.
🛠️ Requirements
- PHP ≥ 8.0
- ext-json, ext-mbstring
- Guzzle HTTP client (will be pulled in as dependency)
- illuminate/collections (via
orchestra/testbench
dev dependency)
🚀 Installation
composer require masyasmv/freedom-broker-api
Laravel Integration
Laravel 8+ will auto-discover the package’s ServiceProvider & Facade.
- Publish config
php artisan vendor:publish --provider="MasyaSmv\FreedomBrokerApi\Laravel\Providers\FreedomBrokerServiceProvider" --tag="freedom-config"
- Set your API keys in
.env
:FREEDOM_PUBLIC_KEY=your_public_api_key FREEDOM_PRIVATE_KEY=your_secret_api_key
📖 Usage Examples
1. Fetch & Parse Broker Report
use MasyaSmv\FreedomBrokerApi\Laravel\Facades\Freedom; /** @var array{ * plain:\MasyaSmv\FreedomBrokerApi\DTO\AccountPlainDTO, * operations:\Illuminate\Support\Collection, * positions:\Illuminate\Support\Collection, * balances:\Illuminate\Support\Collection * } $report */ \$report = Freedom::load('2025-01-01', '2025-01-31');
2. Securities Catalog
use MasyaSmv\FreedomBrokerApi\Core\Service\StockService; \$stocks = app(StockService::class)->all(); // Collection<StockDTO>
3. Quote Info
use MasyaSmv\FreedomBrokerApi\Core\Service\QuoteInfoService; \$info = app(QuoteInfoService::class)->get('AAPL.US'); // StockDTO|null
4. Historical Prices
use MasyaSmv\FreedomBrokerApi\Core\Service\StockHistoryService; \$history = app(StockHistoryService::class) ->history('AAPL.US', new DateTime('2020-01-01'), new DateTime('now'));
5. Orders
use MasyaSmv\FreedomBrokerApi\Core\Service\OrderService; \$order = app(OrderService::class) ->send('AAPL.US', 1.0, 150.00, 'ACC-123'); \$cancel = app(OrderService::class)->cancel(\$order->orderId); \$history = app(OrderService::class) ->history('ACC-123', '2025-01-01', '2025-02-01');
✅ Testing & Quality
composer test # run PHPUnit unit + live tests composer live-test # only live tests (pings real API) composer coverage # run with coverage report composer cs # check PSR-12 coding style composer cs-fix # auto-fix style issues
Live tests are disabled by default; to enable all of them:
FREEDOM_LIVE_TEST=1 composer test
🙌 Contributing
- Fork & clone
- Create a feature branch
- Write unit tests (
tests/…
) - Run
composer test
- Send a PR
Please follow [PSR-12] style, add PHPDoc for new methods, and aim for 100 % coverage.
❤️ Support & Sponsorship
If you find this package useful, please ⭐️ the repo and consider sponsoring development.
📄 License
This library is released under the MIT License. See LICENSE for details.