polymarket-php/polymarket-laravel
Composer 安装命令:
composer require polymarket-php/polymarket-laravel
包简介
Laravel adapter for the Polymarket PHP - Integrate prediction markets into your Laravel applications
关键字:
README 文档
README
This is a Laravel adapter for the Polymarket PHP SDK, providing easy ways to integrate polymarket in your Laravel application.
Requirements
- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
Installation
You can install the package via Composer:
composer require polymarket-php/polymarket-laravel
Quick Setup
Run the install command for guided setup:
php artisan polymarket:install
This will:
- Publish the configuration file
- Display instructions for adding credentials to your
.envfile
Manual Setup
Alternatively, you can publish the configuration file manually:
php artisan vendor:publish --tag="polymarket-config"
Configuration
Add your Polymarket credentials to your .env file:
POLYMARKET_API_KEY=your-api-key POLYMARKET_PRIVATE_KEY=0x... POLYMARKET_CHAIN_ID=137
Configuration Options
All configuration options can be customized in config/polymarket.php:
| Option | Environment Variable | Default | Description |
|---|---|---|---|
api_key |
POLYMARKET_API_KEY |
null |
API key for authenticated requests (optional for read-only) |
private_key |
POLYMARKET_PRIVATE_KEY |
null |
Private key for trading operations |
chain_id |
POLYMARKET_CHAIN_ID |
137 |
Blockchain network (137 = Polygon mainnet) |
gamma_base_url |
POLYMARKET_GAMMA_BASE_URL |
https://gamma-api.polymarket.com |
Gamma API base URL |
clob_base_url |
POLYMARKET_CLOB_BASE_URL |
https://clob.polymarket.com |
CLOB API base URL |
bridge_base_url |
POLYMARKET_BRIDGE_BASE_URL |
https://bridge-api.polymarket.com |
Bridge API base URL |
timeout |
POLYMARKET_TIMEOUT |
30 |
Request timeout in seconds |
retries |
POLYMARKET_RETRIES |
3 |
Number of retry attempts |
verify_ssl |
POLYMARKET_VERIFY_SSL |
true |
Enable SSL certificate verification |
Usage
Using the Facade
The facade provides convenient static access to the Polymarket client:
use PolymarketPhp\PolymarketLaravel\Facades\Polymarket; // Fetch markets $markets = Polymarket::gamma()->markets()->all(); // Search for specific markets $markets = Polymarket::gamma()->markets()->search('election'); // Get a specific market $market = Polymarket::gamma()->markets()->get('market-id');
Dependency Injection
Inject the client directly into your classes:
use PolymarketPhp\Polymarket\Client; class MarketController extends Controller { public function __construct( private Client $polymarket ) {} public function index() { $markets = $this->polymarket->gamma()->markets()->all(); return view('markets.index', compact('markets')); } public function show(string $id) { $market = $this->polymarket->gamma()->markets()->get($id); return view('markets.show', compact('market')); } }
Trading Operations (CLOB API)
For trading operations, you need to configure both an API key and private key:
use PolymarketPhp\PolymarketLaravel\Facades\Polymarket; // Authenticate for trading Polymarket::auth(); // Place an order $order = Polymarket::clob()->orders()->create([ 'market' => 'market-id', 'side' => 'BUY', 'price' => 0.5, 'size' => 100, ]); // Get your orders $orders = Polymarket::clob()->orders()->list(); // Cancel an order Polymarket::clob()->orders()->cancel($orderId);
Bridge API (Cross-Chain Deposits)
The Bridge API enables deposits from multiple chains, automatically converting to USDC.e on Polygon:
use PolymarketPhp\PolymarketLaravel\Facades\Polymarket; // Access the Bridge API $bridge = Polymarket::bridge(); // Supported chains: Ethereum, Arbitrum, Base, Optimism, Solana, Bitcoin
Market Data Examples
Fetching All Markets
use PolymarketPhp\PolymarketLaravel\Facades\Polymarket; // Get all markets with pagination $markets = Polymarket::gamma()->markets()->all([ 'limit' => 20, 'offset' => 0, ]); foreach ($markets as $market) { echo $market['question'] . PHP_EOL; }
Searching Markets
// Search for election-related markets $results = Polymarket::gamma()->markets()->search('election', [ 'limit' => 10, ]); // Search with filters $results = Polymarket::gamma()->markets()->search('crypto', [ 'active' => true, 'closed' => false, ]);
Getting Market Details
$marketId = 'some-market-id'; $market = Polymarket::gamma()->markets()->get($marketId); echo "Question: {$market['question']}" . PHP_EOL; echo "Volume: {$market['volume']}" . PHP_EOL; echo "Liquidity: {$market['liquidity']}" . PHP_EOL;
Error Handling
The SDK throws specific exceptions for different error scenarios:
use PolymarketPhp\Polymarket\Exceptions\AuthenticationException; use PolymarketPhp\Polymarket\Exceptions\NotFoundException; use PolymarketPhp\Polymarket\Exceptions\RateLimitException; use PolymarketPhp\Polymarket\Exceptions\ValidationException; use PolymarketPhp\PolymarketLaravel\Facades\Polymarket; try { $market = Polymarket::gamma()->markets()->get($marketId); } catch (NotFoundException $e) { // Market not found return response()->json(['error' => 'Market not found'], 404); } catch (RateLimitException $e) { // Rate limit exceeded return response()->json(['error' => 'Too many requests'], 429); } catch (AuthenticationException $e) { // Authentication failed return response()->json(['error' => 'Unauthorized'], 401); } catch (ValidationException $e) { // Invalid request parameters return response()->json(['error' => $e->getMessage()], 422); }
Testing
The package includes comprehensive tests:
# Run tests composer test # Run static analysis composer analyse # Fix code style composer format
Mocking in Your Tests
You can easily mock the Polymarket client in your tests:
use PolymarketPhp\PolymarketLaravel\Facades\Polymarket; use PolymarketPhp\Polymarket\Client; public function test_it_fetches_markets() { $mockClient = Mockery::mock(Client::class); $mockClient->shouldReceive('gamma->markets->all') ->once() ->andReturn(['market1', 'market2']); $this->app->instance(Client::class, $mockClient); // Your test code... }
Advanced Configuration
Custom Timeouts
For long-running operations, adjust the timeout:
POLYMARKET_TIMEOUT=60
Retry Configuration
Configure automatic retry behavior:
POLYMARKET_RETRIES=5
Local Development
Disable SSL verification for local testing (not recommended for production):
POLYMARKET_VERIFY_SSL=false
Custom API URLs
Use custom API endpoints (useful for testing):
POLYMARKET_GAMMA_BASE_URL=https://custom-gamma-api.example.com POLYMARKET_CLOB_BASE_URL=https://custom-clob-api.example.com
Changelog
Please see CHANGELOG for more information on recent changes.
Contributing
Contributions are welcome! In case if you found any bug or have an idea just open an issue and create a Pull Request.
Security
If you discover any security-related issues, please email security@example.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
polymarket-php/polymarket-laravel 适用场景与选型建议
polymarket-php/polymarket-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 81 次下载、GitHub Stars 达 3, 最近一次更新时间为 2026 年 01 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「polymarket」 「polymarket laravel」 「polymarket api」 「laravel trading agent」 「polymarket framework」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 polymarket-php/polymarket-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 polymarket-php/polymarket-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 polymarket-php/polymarket-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
PHP Package for Polymarket API Integration
PHP Package for Polymarket API Integration
Alfabank REST API integration
Laravel adapter for the Polymarket PHP - Integrate prediction markets into your Laravel applications
Laravel package for Accurate Online API integration.
统计信息
- 总下载量: 81
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-25