Skip to content

Conversation

@danielgnh
Copy link
Member

This pull request introduces a new Data API client to the codebase, enabling access to market analytics, user positions, trade history, leaderboards, and other data-centric endpoints. The changes include the addition of a dedicated Data client, integration into the main Client class, and resource classes for each Data API feature. An example usage script is also provided to demonstrate the new functionality.

New Data API client integration:

  • Added the Data client (src/Data.php) to handle Data API operations such as positions, trades, analytics, leaderboards, and health checks.
  • Integrated the Data client into the main Client class, including support for custom HTTP clients and lazy instantiation. [1] [2] [3] [4]
  • Updated the Config class to support a separate Data API base URL via the new dataBaseUrl property. [1] [2]

Data API resource classes:

  • Added resource classes for Data API endpoints: Positions, Trades, Activity, Analytics, Leaderboards, and Health, each providing typed methods for their respective API operations. [1] [2] [3] [4] [5] [6]

Documentation and examples:

  • Added an example script (examples/data-api-positions.php) demonstrating how to use the Data API client to fetch user positions, analytics, trade history, leaderboard data, and API health status.

@danielgnh danielgnh self-assigned this Jan 8, 2026
@danielgnh danielgnh added the enhancement New feature or request label Jan 12, 2026
@danielgnh danielgnh requested a review from Copilot January 24, 2026 21:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces a new Data API client to the Polymarket PHP SDK, enabling developers to access market analytics, user positions, trade history, leaderboards, and other data-centric endpoints. The implementation follows the established architectural patterns in the codebase, with proper separation of concerns and consistent API design.

Changes:

  • Adds a new Data client with lazy instantiation and HTTP client injection support
  • Implements six resource classes for Data API endpoints: Positions, Trades, Activity, Analytics, Leaderboards, and Health
  • Extends the Config class to support a configurable Data API base URL
  • Provides a comprehensive example script demonstrating all Data API features

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/Config.php Adds dataBaseUrl property with default value for the Data API endpoint
src/Client.php Integrates Data client with constructor injection support and lazy instantiation accessor method
src/Data.php Main Data API client class that manages HTTP client and provides access to all Data API resources
src/Resources/Data/Positions.php Resource for fetching current positions, closed positions, and position values
src/Resources/Data/Trades.php Resource for retrieving trade history and counting traded markets
src/Resources/Data/Activity.php Resource for querying on-chain operations (trades, splits, merges, redemptions, etc.)
src/Resources/Data/Analytics.php Resource for market analytics including holders, open interest, and live volume tracking
src/Resources/Data/Leaderboards.php Resource for accessing trader rankings, builder rankings, and builder volume data
src/Resources/Data/Health.php Resource for checking Data API operational status
examples/data-api-positions.php Comprehensive example demonstrating all Data API functionality with proper error handling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* Resources:
* - Health: API health check
* - Positions: Current and closed positions
* - Trades: Trade history and activity
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class docblock lists the available resources but omits the Activity resource. For completeness, add "Activity: On-chain operations including trades, splits, merges, redemptions" to the resources list in the docblock (around line 25), similar to how other resources are documented.

Suggested change
* - Trades: Trade history and activity
* - Trades: Trade history and activity
* - Activity: On-chain operations including trades, splits, merges, redemptions

Copilot uses AI. Check for mistakes.

return $this->bridgeClient;
}

Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data() method is missing a docblock comment. For consistency with other API client accessor methods in this class (gamma(), clob(), and bridge()), this method should have a docblock describing what it returns. Consider adding a docblock similar to the one used for bridge() method.

Suggested change
/**
* Get Data API client for market and trading data.
*
* @return Data
*/

Copilot uses AI. Check for mistakes.
Comment on lines 29 to 73
class Data
{
private HttpClientInterface $httpClient;

/**
* @param Config $config
* @param HttpClientInterface|null $httpClient
*/
public function __construct(
private readonly Config $config,
?HttpClientInterface $httpClient = null
) {
$this->httpClient = $httpClient ?? new GuzzleHttpClient($this->config->dataBaseUrl, $this->config);
}

public function health(): Health
{
return new Health($this->httpClient);
}

public function positions(): Positions
{
return new Positions($this->httpClient);
}

public function trades(): Trades
{
return new Trades($this->httpClient);
}

public function activity(): Activity
{
return new Activity($this->httpClient);
}

public function analytics(): Analytics
{
return new Analytics($this->httpClient);
}

public function leaderboards(): Leaderboards
{
return new Leaderboards($this->httpClient);
}
}
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Data API client and its resource classes lack test coverage. The codebase has comprehensive test coverage for other API clients (Gamma, Clob, Bridge), but no tests exist for the new Data API functionality. Consider adding test files similar to the existing pattern: tests for the Data client itself, and tests for each resource class (Positions, Trades, Activity, Analytics, Leaderboards, Health).

Copilot uses AI. Check for mistakes.
try {
echo "10. Checking Data API health...\n";
$health = $client->data()->health()->check();
echo "Status: {$health['status']}\n";
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code assumes that the API response contains a 'status' key without checking its existence first. While the try-catch block will handle exceptions, for consistency with other example files in this codebase (such as examples/bridge-deposit.php which uses isset() checks), consider adding a check before accessing the key, or use the null coalescing operator. For example: echo "Status: " . ($health['status'] ?? 'unknown') . "\n";

Suggested change
echo "Status: {$health['status']}\n";
echo "Status: " . ($health['status'] ?? 'unknown') . "\n";

Copilot uses AI. Check for mistakes.
try {
echo "3. Calculating total position value...\n";
$value = $client->data()->positions()->value($walletAddress);
echo "Total value: \${$value['total']}\n\n";
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code assumes that the API response contains a 'total' key without checking its existence first. While the try-catch block will handle exceptions, for consistency with other example files in this codebase (such as examples/bridge-deposit.php which uses isset() checks), consider adding a check before accessing the key, or use the null coalescing operator. For example: echo "Total value: $" . ($value['total'] ?? '0') . "\n\n";

Suggested change
echo "Total value: \${$value['total']}\n\n";
echo "Total value: $" . ($value['total'] ?? '0') . "\n\n";

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants