承接 mygrainexchange/mgx-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mygrainexchange/mgx-php

Composer 安装命令:

composer require mygrainexchange/mgx-php

包简介

Official PHP client for the MGX Enterprise API. Browse anonymized inventory, place bids, read your team's trades and bids, manage cash bids, subscribe to webhooks, and read market prices. Authenticate with OAuth2 (Login with MGX). Seller identity is never exposed until a trade is paid on both sides.

README 文档

README

Official PHP client for the MGX Enterprise API.

composer require mygrainexchange/mgx-php

Requires PHP 8.1+.

Quickstart

use MyGrainExchange\Mgx\Overlay\MgxClient;
use MyGrainExchange\Mgx\Overlay\MgxApiError;

$mgx = new MgxClient(
    clientId: getenv('MGX_CLIENT_ID'),
    clientSecret: getenv('MGX_CLIENT_SECRET'),
    scopes: ['inventory.read', 'market.read'],
    // baseUrl: 'https://dashboard.mgx.test/v1', // for local development
);

// Auto-paginates the { items, limit, offset, next } envelope.
foreach ($mgx->inventory()->list(['commodity' => 'wheat', 'minQuantity' => 50]) as $lot) {
    echo $lot->getId(), ' ', $lot->getQuantityMt(), ' ', $lot->getAskingPrice()?->getAmount(), PHP_EOL;
}

You can also construct with an options array:

$mgx = MgxClient::create([
    'clientId' => getenv('MGX_CLIENT_ID'),
    'clientSecret' => getenv('MGX_CLIENT_SECRET'),
    'scopes' => ['inventory.read', 'market.read'],
]);

Authentication

  • Client credentials (read-only data) — pass clientId + clientSecret + scopes; the SDK acquires, caches, and refreshes the token for you.
  • Login with MGX (user-context: bids, trades, teams, cash bids, webhooks) — complete the authorization-code + PKCE flow, then pass the resulting accessToken (and optionally refreshToken) to MgxClient.

Features

  • Resource namespacesinventory(), market(), bids(), trades(), teams(), cashBids(), webhooks().
  • Auto-pagination — every list() returns a Paginator you can foreach over; it follows next until the result set is exhausted (->toArray() collects eagerly).
  • Idempotencyinventory()->placeBid() and cashBids()->create() send an Idempotency-Key automatically (override with the $idempotencyKey argument).
  • Typed errors — non-2xx responses throw MgxApiError with status(), code(), getMessage(), and fieldErrors().
try {
    $bid = $mgx->inventory()->placeBid('inv_3Kd9aZ', [
        'quantity_mt' => 50,
        'price' => ['amount' => 312.5],
        'delivery' => ['from' => '2026-08-01', 'to' => '2026-09-30'],
    ]);
} catch (MgxApiError $e) {
    error_log("{$e->status()} {$e->code()} {$e->getMessage()}");
}

Generated code

The lib/ client is generated from the OpenAPI spec; the ergonomic layer lives in overlay/ (namespace MyGrainExchange\Mgx\Overlay). Do not hand-edit lib/ — change the API spec and regenerate. See the mgx-sdks repo.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固