alexstewartja/dxtrade-php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alexstewartja/dxtrade-php-sdk

Composer 安装命令:

composer require alexstewartja/dxtrade-php-sdk

包简介

PHP SDK for DXtrade's Administrative and Trading REST API endpoints

README 文档

README

DXtrade PHP SDK

DXtrade PHP SDK

Latest Stable Version Total Downloads License

Tests Status Static Analysis

PHP Version Required

Buy Me A Coffee

PHP SDK for DXtrade's Administrative and Trading REST API endpoints.

Installation

You can install the package via composer:

composer require alexstewartja/dxtrade-php-sdk

Usage Examples

Client Setup

First, initialize the DXtrade client:

// 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.

// 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.

// 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

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

A Lando file is included in the repo to get up and running quickly:

lando start

Please see CONTRIBUTING for more details.

Security

If you discover any security-related issues, please email dxtrade@alexstewartja.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

alexstewartja/dxtrade-php-sdk 适用场景与选型建议

alexstewartja/dxtrade-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「crypto」 「forex」 「futures」 「trading」 「trade」 「cfd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 alexstewartja/dxtrade-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 alexstewartja/dxtrade-php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 alexstewartja/dxtrade-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 34
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-05