{"id":34253721,"url":"https://github.com/danielgnh/polymarket-php","last_synced_at":"2025-12-16T11:52:39.106Z","repository":{"id":326244575,"uuid":"1104713956","full_name":"danielgnh/polymarket-php","owner":"danielgnh","description":"PHP Framework for Polymarket API integration","archived":false,"fork":false,"pushed_at":"2025-12-08T12:49:26.000Z","size":106,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-08T19:48:46.290Z","etag":null,"topics":["api","clob","gamma","package","php","polymarket","polymarket-api","polymarket-php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielgnh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-26T15:30:40.000Z","updated_at":"2025-12-08T12:47:45.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/danielgnh/polymarket-php","commit_stats":null,"previous_names":["danielgnh/polymarket-php"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/danielgnh/polymarket-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgnh%2Fpolymarket-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgnh%2Fpolymarket-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgnh%2Fpolymarket-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgnh%2Fpolymarket-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielgnh","download_url":"https://codeload.github.com/danielgnh/polymarket-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielgnh%2Fpolymarket-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27763657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-16T02:00:10.477Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","clob","gamma","package","php","polymarket","polymarket-api","polymarket-php"],"created_at":"2025-12-16T11:52:35.265Z","updated_at":"2025-12-16T11:52:39.097Z","avatar_url":"https://github.com/danielgnh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polymarket PHP SDK\n\n[Polymarket API](https://polymarket.com) PHP SDK for interacting with the prediction markets and managing orders.\n\nYou can search for the markets, events, create / delete orders and much more.\n\n[What is polymarket?](https://docs.polymarket.com/polymarket-learn/get-started/what-is-polymarket)\n\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/danielgnh/polymarket-php.svg?style=flat-square)](https://packagist.org/packages/danielgnh/polymarket-php)\n[![PHP Version](https://img.shields.io/packagist/php-v/danielgnh/polymarket-php.svg?style=flat-square)](https://packagist.org/packages/danielgnh/polymarket-php)\n[![Total Downloads](https://img.shields.io/packagist/dt/danielgnh/polymarket-php.svg?style=flat-square)](https://packagist.org/packages/danielgnh/polymarket-php)\n[![License](https://img.shields.io/packagist/l/danielgnh/polymarket-php.svg?style=flat-square)](https://packagist.org/packages/danielgnh/polymarket-php)\n[![Tests](https://img.shields.io/github/actions/workflow/status/danielgnh/polymarket-php/tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/danielgnh/polymarket-php/actions)\n[![PHPStan](https://img.shields.io/badge/PHPStan-level%209-brightgreen.svg?style=flat-square)](https://phpstan.org/)\n\n## Requirements\n\n- PHP 8.1 or higher\n- Composer\n\n## Installation\n\nInstall the package via Composer:\n\n```bash\ncomposer require danielgnh/polymarket-php\n```\n\n## Configuration\n\nAdd your polymarket credentials to your `.env` file:\n\n```env\nPOLYMARKET_API_KEY=your-api-key\nPOLYMARKET_PRIVATE_KEY=0x...\n```\n\nHere is documentation [how to export you private key](https://docs.polymarket.com/polymarket-learn/FAQ/how-to-export-private-key)\n\n## Quick Start\n\n```php\n\u003c?php\n\nuse Danielgnh\\PolymarketPhp\\Client;\n\n/*\n* Let's initialize the client.\n* In case if you defined the POLYMARKET_API_KEY you don't need to pass any parameters in Client\n*/\n$client = new Client();\n\n/*\n* In case if you want to define any other API Key, you can do it as well.\n*/\n$client = new Client('api-key');\n```\n\n## API Architecture\n\nPolymarket uses two separate API systems:\n\n- **Gamma API** (`https://gamma-api.polymarket.com`) - Read-only market data\n- **CLOB API** (`https://clob.polymarket.com`) - Trading operations and order management\n\nThe SDK provides separate client interfaces for each:\n\n```php\n/* Market data */\n$client-\u003egamma()-\u003emarkets()-\u003elist();\n\n/* Trading \u0026 Orders */\n$client-\u003eclob()-\u003eorders()-\u003ecreate([...]);\n```\n\n## API Reference\n\n### Client Initialization\n\n```php\nuse Danielgnh\\PolymarketPhp\\Client;\n\n/* There is a way to initialize the client with custom configuration */\n$client = new Client('your-api-key', [\n    'gamma_base_url' =\u003e 'https://gamma-api.polymarket.com',\n    'clob_base_url' =\u003e 'https://clob.polymarket.com',\n    'timeout' =\u003e 30,\n    'retries' =\u003e 3,\n    'verify_ssl' =\u003e true,\n]);\n```\n\n### Configuration Options\n\nThe SDK supports the following configuration options:\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `gamma_base_url` | string | `https://gamma-api.polymarket.com` | Gamma API base URL |\n| `clob_base_url` | string | `https://clob.polymarket.com` | CLOB API base URL |\n| `timeout` | int | `30` | Request timeout in seconds |\n| `retries` | int | `3` | Number of retry attempts for failed requests |\n| `verify_ssl` | bool | `true` | Whether to verify SSL certificates |\n\n### Markets (Gamma API)\n\nThe Markets resource provides access to prediction market data via the Gamma API.\n\n#### List Markets\n\n```php\n$markets = $client-\u003egamma()-\u003emarkets()-\u003elist(\n    filters: ['active' =\u003e true, 'category' =\u003e 'politics'],\n    limit: 100,\n    offset: 0\n);\n```\n\n**Parameters:**\n- `filters` (array, optional): Filtering options for markets\n- `limit` (int, optional): Maximum number of results (default: 100)\n- `offset` (int, optional): Pagination offset (default: 0)\n\n**Returns:** Array of market data\n\n#### Get Market by ID\n\n```php\n$market = $client-\u003egamma()-\u003emarkets()-\u003eget('market-id');\n```\n\n**Parameters:**\n- `marketId` (string): The unique identifier of the market\n\n**Returns:** Market data array\n\n#### Search Markets\n\n```php\n$results = $client-\u003egamma()-\u003emarkets()-\u003esearch(\n    query: 'election',\n    filters: ['active' =\u003e true],\n    limit: 50\n);\n```\n\n**Parameters:**\n- `query` (string): Search query string\n- `filters` (array, optional): Additional filtering options\n- `limit` (int, optional): Maximum number of results (default: 100)\n\n**Returns:** Array of matching markets\n\n### Orders (CLOB API)\n\nThe Orders resource handles order management and execution via the CLOB API.\n\n#### List Orders\n\n```php\n$orders = $client-\u003eclob()-\u003eorders()-\u003elist(\n    filters: ['status' =\u003e 'open'],\n    limit: 100,\n    offset: 0\n);\n```\n\n**Parameters:**\n- `filters` (array, optional): Filtering options for orders\n- `limit` (int, optional): Maximum number of results (default: 100)\n- `offset` (int, optional): Pagination offset (default: 0)\n\n**Returns:** Array of order data\n\n#### Get Order by ID\n\n```php\n$order = $client-\u003eclob()-\u003eorders()-\u003eget('order-id');\n```\n\n**Parameters:**\n- `orderId` (string): The unique identifier of the order\n\n**Returns:** Order data array\n\n#### Create Order\n\n```php\nuse Danielgnh\\PolymarketPhp\\Enums\\OrderSide;\nuse Danielgnh\\PolymarketPhp\\Enums\\OrderType;\n\n$order = $client-\u003eclob()-\u003eorders()-\u003ecreate([\n    'market_id' =\u003e 'market-id',\n    'side' =\u003e OrderSide::BUY-\u003evalue,\n    'type' =\u003e OrderType::GTC-\u003evalue,\n    'price' =\u003e '0.52',\n    'amount' =\u003e '10.00',\n]);\n```\n\n**Parameters:**\n- `orderData` (array): Order details including:\n  - `market_id` (string): Target market identifier\n  - `side` (string): Order side - use `OrderSide` enum\n  - `type` (string): Order type - use `OrderType` enum\n  - `price` (string): Order price as decimal string\n  - `amount` (string): Order amount as decimal string\n\n**Important:** Always use strings for price and amount values to maintain decimal precision.\n\n**Returns:** Created order data array\n\n#### Cancel Order\n\n```php\n$result = $client-\u003eclob()-\u003eorders()-\u003ecancel('order-id');\n```\n\n**Parameters:**\n- `orderId` (string): The unique identifier of the order to cancel\n\n**Returns:** Cancellation result data\n\n## Error Handling\n\nThe SDK provides a comprehensive exception hierarchy for handling different error scenarios:\n\n```php\nuse Danielgnh\\PolymarketPhp\\Exceptions\\{\n    PolymarketException,\n    AuthenticationException,\n    ValidationException,\n    RateLimitException,\n    NotFoundException,\n    ApiException\n};\n\ntry {\n    $market = $client-\u003egamma()-\u003emarkets()-\u003eget('invalid-id');\n} catch (AuthenticationException $e) {\n    // Handle 401/403 authentication errors\n    echo \"Authentication failed: \" . $e-\u003egetMessage();\n} catch (ValidationException $e) {\n    // Handle 400/422 validation errors\n    echo \"Validation error: \" . $e-\u003egetMessage();\n} catch (RateLimitException $e) {\n    // Handle 429 rate limit errors\n    echo \"Rate limit exceeded: \" . $e-\u003egetMessage();\n} catch (NotFoundException $e) {\n    // Handle 404 not found errors\n    echo \"Resource not found: \" . $e-\u003egetMessage();\n} catch (ApiException $e) {\n    // Handle other API errors (5xx)\n    echo \"API error: \" . $e-\u003egetMessage();\n} catch (PolymarketException $e) {\n    // Catch-all for any SDK exception\n    echo \"Error: \" . $e-\u003egetMessage();\n\n    // Get additional error details\n    $statusCode = $e-\u003egetCode();\n    $response = $e-\u003egetResponse();\n}\n```\n\n## Enums\n\nThe SDK provides type-safe enums for API fields with fixed value sets, ensuring compile-time safety and better IDE autocomplete.\n\n### Available Enums\n\n#### OrderSide\n\nSpecifies whether you're buying or selling shares:\n\n```php\nuse Danielgnh\\PolymarketPhp\\Enums\\OrderSide;\n\nOrderSide::BUY   // Buy shares\nOrderSide::SELL  // Sell shares\n```\n\n#### OrderType\n\nDetermines the execution behavior of an order:\n\n```php\nuse Danielgnh\\PolymarketPhp\\Enums\\OrderType;\n\nOrderType::FOK  // Fill-Or-Kill: Execute immediately in full or cancel\nOrderType::FAK  // Fill-And-Kill: Execute immediately for available shares, cancel remainder\nOrderType::GTC  // Good-Til-Cancelled: Active until fulfilled or cancelled\nOrderType::GTD  // Good-Til-Date: Active until specified date\n```\n\n#### OrderStatus\n\nIndicates the current state of an order:\n\n```php\nuse Danielgnh\\PolymarketPhp\\Enums\\OrderStatus;\n\nOrderStatus::MATCHED    // Matched with existing order\nOrderStatus::LIVE       // Resting on the order book\nOrderStatus::DELAYED    // Marketable but subject to matching delay\nOrderStatus::UNMATCHED  // Marketable but experiencing delay\n```\n\n#### SignatureType\n\nFor order authentication methods:\n\n```php\nuse Danielgnh\\PolymarketPhp\\Enums\\SignatureType;\n\nSignatureType::POLYMARKET_PROXY_EMAIL   // Email/Magic account (value: 1)\nSignatureType::POLYMARKET_PROXY_WALLET  // Browser wallet (value: 2)\nSignatureType::EOA                      // Externally owned account (value: 0)\n```\n\n### Usage Example\n\n```php\nuse Danielgnh\\PolymarketPhp\\Enums\\{OrderSide, OrderType};\n\n$order = $client-\u003eclob()-\u003eorders()-\u003ecreate([\n    'market_id' =\u003e 'market-id',\n    'side' =\u003e OrderSide::BUY-\u003evalue,\n    'type' =\u003e OrderType::GTC-\u003evalue,\n    'price' =\u003e '0.52',\n    'amount' =\u003e '10.00',\n]);\n```\n\n## Working with Decimal Values\n\nWhen working with financial data (prices, amounts), always use string representation to maintain precision:\n\n```php\n// Good - maintains precision\n$order = $client-\u003eclob()-\u003eorders()-\u003ecreate([\n    'price' =\u003e '0.52',\n    'amount' =\u003e '10.00',\n]);\n\n// Bad - may lose precision\n$order = $client-\u003eclob()-\u003eorders()-\u003ecreate([\n    'price' =\u003e 0.52,  // Float loses precision!\n    'amount' =\u003e 10.00,\n]);\n```\n\n## Development\n\n### Running Tests\n\n```bash\ncomposer test\n```\n\n### Code Style\n\nFormat code using PHP CS Fixer:\n\n```bash\ncomposer cs-fix\n```\n\nCheck code style without making changes:\n\n```bash\ncomposer cs-check\n```\n\n### Static Analysis\n\nRun PHPStan for static analysis:\n\n```bash\ncomposer phpstan\n```\n\n### Test Coverage\n\nGenerate test coverage report:\n\n```bash\ncomposer test-coverage\n```\n\nCoverage reports will be generated in the `coverage/` directory.\n\n## Contributing\n\nContributions are welcome! Please follow these guidelines:\n\n1. Follow PSR-12 coding standards\n2. Write tests for new features\n3. Run `composer cs-fix` before committing\n4. Ensure all tests pass with `composer test`\n5. Run static analysis with `composer phpstan`\n\n## Security\n\nIf you discover any security-related issues, please email uhorman@gmail.com instead of using the issue tracker.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Credits\n\n- **Author**: Daniel Goncharov\n- **Email**: uhorman@gmail.com\n\n## Resources\n\n- [Polymarket Official Website](https://polymarket.com)\n- [Polymarket API Documentation](https://docs.polymarket.com)\n- [Package on Packagist](https://packagist.org/packages/danielgnh/polymarket-php)\n\n## Support\n\nFor bugs and feature requests, please use the [GitHub issue tracker](https://github.com/danielgnh/polymarket-php-sdk/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielgnh%2Fpolymarket-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielgnh%2Fpolymarket-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielgnh%2Fpolymarket-php/lists"}