tradernet / sdk
PHP SDK for the Tradernet public API V3: signed HTTP commands, SID session management and realtime WebSocket streams.
Requires
- php: ^8.3
- ext-json: *
- ext-openssl: *
- guzzlehttp/guzzle: ^7.8 || ^8.0
Requires (Dev)
- amphp/websocket-client: ^2.0
- friendsofphp/php-cs-fixer: ^3.68
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.5
- vlucas/phpdotenv: ^5.6
Suggests
- amphp/http-client: Required for AmpTransport (non-blocking HTTP in Amp event loop)
- amphp/websocket-client: Required for realtime WebSocket streams (Ws\Amp\AmpWebSocketClient)
- vlucas/phpdotenv: Convenient .env loading before Tradernet::fromEnv()
This package is auto-updated.
Last update: 2026-08-29 07:54:49 UTC
README
PHP client for the Tradernet public API V3.
Typed, session-aware HTTP commands and optional Amp WebSocket streams for server-side integrations.
| Package | tradernet/sdk |
| Namespace | Tradernet\Sdk |
| PHP | ^8.3 |
| HTTP | Guzzle ^7.8 || ^8.0 |
| Realtime | optional amphp/websocket-client |
Features
- Signed requests to
/api/{command}(HMAC-SHA256 API key pair) - Optional SID sessions via login/password with local persistence (~2 weeks)
- Circuit breaker against re-authentication storms
- Resource clients mapped to public API sections
- Escape hatch for any V3 command:
$tn->request() - WebSocket quotes / account channels via Amp
Requirements
- PHP 8.3+
- Extensions:
json,openssl - Composer 2
Installation
composer require tradernet/sdk
For realtime streams:
composer require amphp/websocket-client
Full guide: Installing with Composer.
Maintainers: Publishing to Packagist.
Quick start
<?php declare(strict_types=1); require __DIR__ . '/vendor/autoload.php'; use Tradernet\Sdk\Tradernet; $tn = Tradernet::fromEnv(); $quotes = $tn->quotes()->get(['AAPL.US']); $portfolio = $tn->portfolio()->get(); // WARNING: orders()->buy() places a real trade. See examples/orders.php.
Credentials
Environment variables (recommended for containers / CI):
export TRADERNET_API_KEY='your_public_key' export TRADERNET_API_SECRET='your_private_key' export TRADERNET_LOGIN='user@example.com' # optional, for SID export TRADERNET_PASSWORD='secret' # optional, for SID export TRADERNET_DOMAIN='https://tradernet.com'
$tn = Tradernet::fromEnv();
Details: Using environment variables.
INI file (Python SDK parity):
[auth] public = YOUR_PUBLIC_KEY private = YOUR_PRIVATE_KEY login = user@example.com password = secret domain = https://tradernet.com
$tn = Tradernet::fromIni(__DIR__ . '/tradernet.ini');
Details: Using tradernet.ini.
The SDK reads the process environment. It does not load
.envfiles. Usevlucas/phpdotenv(or similar) in your app if needed. Bundledexamples/load.envfor convenience only.
Auth modes
| Mode | Behavior |
|---|---|
keys_only |
HMAC only — SID is never obtained |
sid_lazy |
SID only when a command requires it (default) |
sid_eager |
SID obtained at client construction (still attached only when needed) |
Set via TRADERNET_AUTH_MODE or ClientConfig.
API keys are per cabinet / domain. A key from tradernet.com will not work on tradernet.kz or freedom24.com — match TRADERNET_DOMAIN to the cabinet that issued the key.
More: Authentication.
Resources
$tn->auth(); $tn->user(); $tn->quotes(); $tn->orders(); $tn->portfolio(); $tn->alerts(); $tn->stockLists(); $tn->securitySessions(); $tn->currency(); $tn->reference(); $tn->cps(); $tn->reports(); $tn->news(); $tn->shop(); $tn->tariff(); $tn->websocket();
Any command:
$tn->request('getStockQuotesJson', ['tickers' => 'AAPL.US']);
See API resources and HTTP API.
WebSocket
Streams authenticate with SID only (not API keys). Without SID you get demo quotes.
use Tradernet\Sdk\Ws\Amp\AmpWebSocketClient; $ws = $tn->websocket(requireSid: true); $ws->connect(); if ($ws instanceof AmpWebSocketClient) { $ws->quotes(['AAPL.US']); } foreach ($ws->frames() as $frame) { // $frame->event, $frame->data }
php examples/websocket_quotes.php TRADERNET_WS_SID=1 php examples/websocket_quotes.php
Guide: WebSocket.
Examples
cp .env.example .env # fill in your keys
composer install
php examples/quotes.php
php examples/portfolio.php
php examples/orders.php
php examples/diagnose.php
See the examples directory.
Documentation
| Topic | Link |
|---|---|
| Docs home | docs/index.md |
| Installation | Composer · Env · INI |
| Authentication | docs/authentication.md |
| HTTP API | docs/http-api.md |
| Resources | docs/resources.md |
| WebSocket | docs/websocket.md |
| Security | docs/security.md |
| Development | docs/development.md |
| Upstream API | tradernet.com/tradernet-api |
Development
composer install
composer test
composer stan
composer cs
Security
- Never commit
tradernet.ini,.env, or SID files under~/.tradernet/ - Prefer a password
Closure(Vault / KMS) instead of a plain string - Treat SID as a bearer token — do not log or print it
- Auth endpoints are rate-limited; do not bypass
ReauthGuard
Details: Security.
License
MIT © Tradernet API Support <tradernet.com>