https://github.com/alexstewartja/dxtrade-php-sdk
PHP SDK for DXtrade's Administrative and Trading REST API endpoints.
https://github.com/alexstewartja/dxtrade-php-sdk
cfd crypto dxtrade forex futures trade trading
Last synced: 3 months ago
JSON representation
PHP SDK for DXtrade's Administrative and Trading REST API endpoints.
- Host: GitHub
- URL: https://github.com/alexstewartja/dxtrade-php-sdk
- Owner: alexstewartja
- License: mit
- Created: 2025-05-04T23:24:02.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-01-12T00:35:00.000Z (5 months ago)
- Last Synced: 2026-01-12T04:49:21.691Z (5 months ago)
- Topics: cfd, crypto, dxtrade, forex, futures, trade, trading
- Language: PHP
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README

# DXtrade PHP SDK
[](https://packagist.org/packages/alexstewartja/dxtrade-php-sdk)
[](https://packagist.org/packages/alexstewartja/dxtrade-php-sdk)
[](https://packagist.org/packages/alexstewartja/dxtrade-php-sdk)


[](https://packagist.org/packages/alexstewartja/dxtrade-php-sdk)
[](https://buymeacoffee.com/alexstewartja)
PHP SDK for DXtrade's Administrative and Trading REST API endpoints.
## Installation
You can install the package via composer:
```bash
composer require alexstewartja/dxtrade-php-sdk
```
## Usage Examples
### Client Setup
First, initialize the DXtrade client:
```php
// Create a client in the demo environment
$client = new DXtradeClient(Env::BASE_URL_DEMO);
// Or in a custom/production environment
$prodBaseUrl = 'https://your-production-url.com';
$client = new DXtradeClient($prodBaseUrl);
// With custom Guzzle options
$client = new DXtradeClient(
$prodBaseUrl,
null,
[
'timeout' => 30,
'verify' => false,
]
);
// If you already have a session token
$client = new DXtradeClient(
$prodBaseUrl,
'your-session-token'
);
```
### Administrative API
The Administrative API provides access to account management, user management, and other administrative functions.
```php
// Authentication
$loginRequest = (new LoginRequest())
->setUsername('alex')
->setDomain('uptrendprop')
->setPassword('password123!');
$loginResult = $client->administrative()->authentication()->login($loginRequest);
$sessionToken = $loginResult->getSessionToken(); // Get the session token
// Store the session token for future clients/requests
// OR
// Set the session token on this client
$client->setSessionToken($sessionToken);
// Accounts
$accounts = $client->administrative()->accounts()->getAccounts(); // Get all accounts
$account = $client->administrative()->accounts()->getAccount('clearing_code', 'account_code'); // Get a specific account
// Users
$users = $client->administrative()->users()->getUsers();
// Single Sign-On (SSO)
$ssoToken = $client
->administrative()
->sso()
->generateTokenForm('alex', 'uptrendprop'); // Generate SSO token for a user via HTTP POST
// Brokers
$brokers = $client->administrative()->brokers()->getBrokers();
// Cash Transfers
$adjustment = (new Adjustment())
->setAmount(-50.0)
->setCurrency('USD')
->setDescription('Test debit adjustment');
$transfer = $client->administrative()->cashTransfers()->createAdjustment(
'clearing_code',
'account_code',
uniqid('adj-'),
$adjustment
);
// Categories
$categories = $client->administrative()->categories()->getCategories();
```
### Trading API
The Trading API provides access to trading operations, market data, and order management.
```php
// Authentication
$loginRequest = (new LoginRequest())
->setUsername('alex')
->setDomain('uptrendprop')
->setPassword('password123!');
$loginResponse = $client->trading()->authentication()->login($loginRequest);
// Accounts
$accounts = $client->trading()->accounts()->getAccounts(); // Get all accounts
$eodMetrics = $client
->trading()
->accounts()
->getEodMetricsQuery('2025-04-21', 'uptrendprop:alex,uptrendprop:staff'); // Get End-Of-Day metrics
$portfolios = $client
->trading()
->accounts()
->getAccountPortfolios('uptrendprop:alex', 'account-etag-123'); // Get account portfolios
// Instruments
$instruments = $client->trading()->instruments()->getByType(InstrumentType::CFD_FUTURES); // Get all instruments by type
$instrument = $client->trading()->instruments()->getBySymbol('EUR/USD'); // Get instrument(s) by symbol
// Market Data
$marketEventType = (new MarketEventRequestType())
->setType(MarketEventType::CANDLE->value)
->setCandleType(CandleType::H4->value)
->setFromTime((new DXtradeDateTime('-3 months')))
->setToTime((new DXtradeDateTime('now')));
$marketDataRequest = (new MarketDataRequest())
->setAccount('uptrendprop:alex')
->setSymbols(['EUR/USD'])
->setEventTypes([$marketEventType]);
// Get last 3 months of 4-hour candles for EUR/USD
$candles = $client->trading()->marketData()->getMarketData($marketDataRequest);
// Orders
$openOrders = $client->trading()->orders()->getOpenOrders('uptrendprop:alex'); // Get all open orders for an account
// Place limit-short (sell) order of 100 units on EUR/USD if it drops to the $1.08 USD price-point
$orderCode = uniqid('ord-');
$orderRequest = (new SingleOrderRequest())
->setOrderCode(uniqid('ord-'))
->setType(OrderType::LIMIT->value)
->setInstrument('EUR/USD')
->setQuantity(100.00)
->setSide(OrderSide::SELL->value)
->setLimitPrice(1.08);
$limitOrderResponse = $client->trading()->orders()->createOrder('uptrendprop:alex', $orderRequest);
// Cancel an order
$cancelledOrderResponse = $client->trading()->orders()->cancelOrder('uptrendprop:alex', $orderCode);
$orderIsCancelled = ($cancelledOrderResponse->getOrderId() === $limitOrderResponse->getOrderId());
// Conversions
$conversionRate = $client->trading()->conversion()->getConversionRate('USD', 'EUR');
```
## Testing
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
A [Lando](https://lando.dev/) file is included in the repo to get up and running quickly:
```bash
lando start
```
Please see [CONTRIBUTING](CONTRIBUTING.md) for more details.
## Security
If you discover any security-related issues, please email
[dxtrade@alexstewartja.com](mailto:dxtrade@alexstewartja.com?Subject=DXtrade%20PHP%20SDK) instead of using the issue
tracker.
## Credits
- [Alex Stewart](https://github.com/alexstewartja)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.