A comprehensive Go SDK for the Polymarket Data API. This client library provides easy access to market data, user positions, trading activity, and more.
- β Complete API coverage for all Polymarket Data endpoints
- β
Type-safe with proper decimal handling using
shopspring/decimal - β Comprehensive error handling
- β Full test coverage
- β Production-ready examples for trading strategies
go get github.com/ivanzzeth/polymarket-go-data-clientpackage main
import (
"context"
"fmt"
"net/http"
polymarketdata "github.com/ivanzzeth/polymarket-go-data-client"
)
func main() {
// Create client
client, err := polymarketdata.NewClient(&http.Client{})
if err != nil {
panic(err)
}
ctx := context.Background()
// Check API health
health, err := client.HealthCheck(ctx)
if err != nil {
panic(err)
}
fmt.Printf("API Status: %s\n", health.Data)
// Get user positions
positions, err := client.GetPositions(ctx, &polymarketdata.GetPositionsParams{
User: "0x56687bf447db6ffa42ffe2204a05edaa20f55839",
Limit: 10,
})
if err != nil {
panic(err)
}
for _, pos := range positions {
fmt.Printf("Market: %s | PnL: %s\n", pos.Title, pos.CashPnl.String())
}
}HealthCheck()- Check API availability
GetPositions(params)- Get current user positionsGetClosedPositions(params)- Get historical closed positionsGetPositionsValue(params)- Get total position value
GetTrades(params)- Get trade historyGetTradedMarketsCount(params)- Get count of markets traded
GetActivity(params)- Get user activity (trades, splits, merges, etc.)
GetHolders(params)- Get top token holdersGetOpenInterest(params)- Get market open interestGetLiveVolume(params)- Get live trading volume
ctx := context.Background()
// Get recent trades for a market
trades, err := client.GetTrades(ctx, &polymarketdata.GetTradesParams{
Market: []string{"0xdd22472e552920b8438158ea7238bfadfa4f736aa4cee91a6b86c39ead110917"},
Limit: 50,
})
// Get top holders
holders, err := client.GetHolders(ctx, &polymarketdata.GetHoldersParams{
Market: []string{marketId},
Limit: 10,
MinBalance: 1000,
})
// Get open interest
oi, err := client.GetOpenInterest(ctx, &polymarketdata.GetOpenInterestParams{
Market: []string{marketId},
})This repository includes 5 complete, production-ready examples demonstrating different trading strategies:
Track and follow profitable traders
Identifies high-performing traders and monitors their positions and activities. Perfect for copy-trading strategies.
cd examples/smart_money_tracker && go run main.goKey Use Cases:
- Copy trading profitable traders
- Validate market direction with smart money consensus
- Avoid positions opposite to successful traders
Monitor large holders and market concentration
Analyzes token holder distribution to identify concentration risks and whale movements.
cd examples/whale_watcher && go run main.goKey Use Cases:
- Assess concentration risk before entering markets
- Track whale accumulation/distribution
- Predict potential price movements from large holders
Warning Levels:
β οΈ Top 3 holders > 50% controlβ οΈ Top 10 holders > 70% control
Find liquid markets and identify mispricing
Evaluates market depth, volume, and liquidity to find optimal trading opportunities.
cd examples/market_liquidity_analyzer && go run main.goKey Use Cases:
- Find liquid markets for large trades
- Identify illiquid markets prone to volatility
- Assess OI/Volume ratio for market health
Liquidity Scoring:
- 70-100: Excellent liquidity
- 30-70: Moderate liquidity
- <30: Poor liquidity, use caution
Identify overcrowded trades for contrarian opportunities
Detects extreme sentiment imbalances (>85% one-sided) that often precede reversals.
cd examples/sentiment_reversal_detector && go run main.goKey Use Cases:
- Find contrarian trading opportunities
- Identify overbought/oversold markets
- Fade overcrowded positions
Signal Strength:
- STRONG: >85% one-sided pressure
- MODERATE: 75-85% one-sided pressure
- WEAK: Balanced market
Analyze trends and catch momentum trades
Identifies price trends, volume changes, and momentum to find trending markets.
cd examples/price_momentum_analyzer && go run main.goKey Use Cases:
- Trend following strategies
- Breakout trading
- Support/resistance level identification
Trading Signals:
- π’ STRONG BUY: Price +3%+ with volume
- π’ BUY: Price +1-3%
- π΄ STRONG SELL: Price -3%+ with volume
- π΄ SELL: Price -1-3%
- βͺ HOLD: Sideways action
.
βββ client.go # Core client implementation
βββ types.go # All type definitions
βββ health.go # Health check endpoint
βββ positions.go # Position-related endpoints
βββ trades.go # Trading endpoints
βββ activity.go # Activity endpoints
βββ holders.go # Holder endpoints
βββ misc.go # Miscellaneous endpoints
βββ *_test.go # Comprehensive tests
βββ examples/ # Trading strategy examples
βββ smart_money_tracker/
βββ whale_watcher/
βββ market_liquidity_analyzer/
βββ sentiment_reversal_detector/
βββ price_momentum_analyzer/
Run all tests:
go test -vRun specific test:
go test -v -run TestGetPositionsAll numeric values use github.com/shopspring/decimal for precise handling of financial data.
type Position struct {
Size decimal.Decimal `json:"size"`
AvgPrice decimal.Decimal `json:"avgPrice"`
CashPnl decimal.Decimal `json:"cashPnl"`
}Function parameters use pointers for mutability, while struct fields use values when zero is acceptable:
// Function parameter is pointer, context comes first
func (c *DataClient) GetPositions(ctx context.Context, params *GetPositionsParams) ([]Position, error)
// Field types - pointers only when needed
type GetPositionsParams struct {
User string // Zero value OK
Limit int // 0 means not set
SizeThreshold *decimal.Decimal // Needs pointer
Redeemable *bool // Needs pointer
}Comprehensive error handling with context:
if resp.StatusCode != http.StatusOK {
var errResp ErrorResponse
if err := json.Unmarshal(body, &errResp); err == nil && errResp.Error != "" {
return nil, fmt.Errorf("API error (status %d): %s", resp.StatusCode, errResp.Error)
}
return nil, fmt.Errorf("request failed with status %d: %s", resp.StatusCode, string(body))
}- The Polymarket Data API has rate limits
- Implement exponential backoff for production use
- Consider caching responses when appropriate
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details
This SDK is for educational and research purposes. Trading prediction markets involves risk. Always:
- Do your own research
- Never risk more than you can afford to lose
- Past performance does not guarantee future results
- The examples are for demonstration only
For issues, questions, or contributions:
- Open an issue on GitHub
- Check existing examples for guidance
- Review test files for usage patterns