data

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DataAPIBase = "https://data-api.polymarket.com"

Variables

This section is empty.

Functions

This section is empty.

Types

type APILeaderboardEntry

type APILeaderboardEntry struct {
	Rank          interface{} `json:"rank"` // Can be string or number
	ProxyWallet   string      `json:"proxyWallet"`
	UserName      string      `json:"userName"`
	Vol           float64     `json:"vol"`
	Pnl           float64     `json:"pnl"`
	ProfileImage  string      `json:"profileImage"`
	XUsername     string      `json:"xUsername"`
	VerifiedBadge bool        `json:"verifiedBadge"`
}

APILeaderboardEntry represents raw API response for leaderboard

type Activity

type Activity struct {
	Type            string  `json:"type"` // "TRADE" | "SPLIT" | "MERGE" | "REDEEM" | "REWARD" | "CONVERSION"
	Side            string  `json:"side"` // "BUY" | "SELL"
	Size            float64 `json:"size"`
	Price           float64 `json:"price"`
	UsdcSize        float64 `json:"usdcSize,omitempty"`
	Asset           string  `json:"asset"`
	ConditionID     string  `json:"conditionId"`
	Outcome         string  `json:"outcome"`
	OutcomeIndex    int     `json:"outcomeIndex,omitempty"`
	Timestamp       int64   `json:"timestamp"`
	TransactionHash string  `json:"transactionHash"`
	ProxyWallet     string  `json:"proxyWallet,omitempty"`
	Title           string  `json:"title,omitempty"`
	Slug            string  `json:"slug,omitempty"`
	Name            string  `json:"name,omitempty"`
}

Activity represents an activity entry from Data API

type ActivityParams

type ActivityParams struct {
	Limit         int      `url:"limit,omitempty"`
	Offset        int      `url:"offset,omitempty"`
	Start         int64    `url:"start,omitempty"`
	End           int64    `url:"end,omitempty"`
	Type          string   `url:"type,omitempty"` // TRADE, SPLIT, MERGE, REDEEM, REWARD, CONVERSION
	Side          string   `url:"side,omitempty"` // BUY, SELL
	Market        []string `url:"market,omitempty"`
	EventID       []int    `url:"eventId,omitempty"`
	SortBy        string   `url:"sortBy,omitempty"`        // TIMESTAMP, TOKENS, CASH
	SortDirection string   `url:"sortDirection,omitempty"` // ASC, DESC
}

type ClosedPosition

type ClosedPosition struct {
	ProxyWallet     string  `json:"proxyWallet"`
	Asset           string  `json:"asset"`
	ConditionID     string  `json:"conditionId"`
	AvgPrice        float64 `json:"avgPrice"`
	TotalBought     float64 `json:"totalBought"`
	RealizedPnl     float64 `json:"realizedPnl"`
	CurPrice        float64 `json:"curPrice"`
	Timestamp       int64   `json:"timestamp"`
	Title           string  `json:"title"`
	Slug            string  `json:"slug,omitempty"`
	Icon            string  `json:"icon,omitempty"`
	EventSlug       string  `json:"eventSlug,omitempty"`
	Outcome         string  `json:"outcome"`
	OutcomeIndex    int     `json:"outcomeIndex"`
	OppositeOutcome string  `json:"oppositeOutcome,omitempty"`
	OppositeAsset   string  `json:"oppositeAsset,omitempty"`
	EndDate         string  `json:"endDate,omitempty"`
}

ClosedPosition represents a closed position entry

type ClosedPositionsParams

type ClosedPositionsParams struct {
	Limit         int      `url:"limit,omitempty"`
	Offset        int      `url:"offset,omitempty"`
	Market        []string `url:"market,omitempty"`
	EventID       []int    `url:"eventId,omitempty"`
	Title         string   `url:"title,omitempty"`
	SortBy        string   `url:"sortBy,omitempty"`        // REALIZEDPNL, TITLE, PRICE, AVGPRICE, TIMESTAMP
	SortDirection string   `url:"sortDirection,omitempty"` // ASC, DESC
}

type DataAPIError

type DataAPIError struct {
	StatusCode int    `json:"-"`
	Message    string `json:"message"`
	ErrorMsg   string `json:"error"`
}

DataAPIError represents Data API specific error structure

func (*DataAPIError) Error

func (e *DataAPIError) Error() string

type DataClient

type DataClient struct {
	BaseURL    string
	HTTPClient *http.Client
}

DataClient interacts with Polymarket Data API

func NewDataClient

func NewDataClient(httpClient *http.Client) *DataClient

NewDataClient creates a new DataClient

func (*DataClient) GetActivity

func (c *DataClient) GetActivity(address string, params ActivityParams) ([]Activity, error)

GetActivity retrieves activity for a wallet

func (*DataClient) GetClosedPositions

func (c *DataClient) GetClosedPositions(address string, params ClosedPositionsParams) ([]ClosedPosition, error)

GetClosedPositions retrieves closed positions for a wallet

func (*DataClient) GetLeaderboard

func (c *DataClient) GetLeaderboard(params LeaderboardParams) (*LeaderboardResult, error)

GetLeaderboard retrieves leaderboard rankings

func (*DataClient) GetPositions

func (c *DataClient) GetPositions(address string, params PositionsParams) ([]Position, error)

GetPositions retrieves positions for a wallet

func (*DataClient) GetTrades

func (c *DataClient) GetTrades(params TradesParams) ([]DataTrade, error)

GetTrades retrieves trades

type DataTrade

type DataTrade struct {
	ID                    string  `json:"id,omitempty"`
	Market                string  `json:"market"` // conditionId
	Asset                 string  `json:"asset"`
	Side                  string  `json:"side"` // "BUY" | "SELL"
	Price                 float64 `json:"price"`
	Size                  float64 `json:"size"`
	Outcome               string  `json:"outcome"`
	OutcomeIndex          int     `json:"outcomeIndex"`
	Timestamp             int64   `json:"timestamp"`
	TransactionHash       string  `json:"transactionHash"`
	ProxyWallet           string  `json:"proxyWallet,omitempty"`
	Title                 string  `json:"title,omitempty"`
	Slug                  string  `json:"slug,omitempty"`
	Icon                  string  `json:"icon,omitempty"`
	EventSlug             string  `json:"eventSlug,omitempty"`
	Name                  string  `json:"name,omitempty"`
	Pseudonym             string  `json:"pseudonym,omitempty"`
	Bio                   string  `json:"bio,omitempty"`
	ProfileImage          string  `json:"profileImage,omitempty"`
	ProfileImageOptimized string  `json:"profileImageOptimized,omitempty"`
}

DataTrade represents a trade from the Data API (distinct from CLOB Trade)

type LeaderboardEntry

type LeaderboardEntry struct {
	Address       string  `json:"address"` // Standardized from proxyWallet
	Rank          int     `json:"rank"`    // Converted from string in API if needed, but assuming int in struct
	Pnl           float64 `json:"pnl"`
	Volume        float64 `json:"volume"` // Renamed from vol
	UserName      string  `json:"userName,omitempty"`
	XUsername     string  `json:"xUsername,omitempty"`
	VerifiedBadge bool    `json:"verifiedBadge,omitempty"`
	ProfileImage  string  `json:"profileImage,omitempty"`
	Positions     int     `json:"positions,omitempty"`
	Trades        int     `json:"trades,omitempty"`
}

LeaderboardEntry represents a leaderboard entry

type LeaderboardParams

type LeaderboardParams struct {
	TimePeriod string `url:"timePeriod,omitempty"` // DAY, WEEK, MONTH, ALL
	OrderBy    string `url:"orderBy,omitempty"`    // PNL, VOL
	Category   string `url:"category,omitempty"`   // OVERALL, POLITICS, SPORTS, CRYPTO, CULTURE, MENTIONS, WEATHER, ECONOMICS, TECH, FINANCE
	Limit      int    `url:"limit,omitempty"`
	Offset     int    `url:"offset,omitempty"`
	User       string `url:"user,omitempty"`
	UserName   string `url:"userName,omitempty"`
}

type LeaderboardResult

type LeaderboardResult struct {
	Entries []LeaderboardEntry `json:"entries"`
	HasMore bool               `json:"hasMore"`
	Request LeaderboardParams  `json:"request"`
}

LeaderboardResult represents the result with metadata

type Position

type Position struct {
	ProxyWallet        string  `json:"proxyWallet,omitempty"`
	Asset              string  `json:"asset"`
	ConditionID        string  `json:"conditionId"`
	Outcome            string  `json:"outcome"`
	OutcomeIndex       int     `json:"outcomeIndex"`
	Size               float64 `json:"size"`
	AvgPrice           float64 `json:"avgPrice"`
	CurPrice           float64 `json:"curPrice,omitempty"`
	TotalBought        float64 `json:"totalBought,omitempty"`
	InitialValue       float64 `json:"initialValue,omitempty"`
	CurrentValue       float64 `json:"currentValue,omitempty"`
	CashPnl            float64 `json:"cashPnl,omitempty"`
	PercentPnl         float64 `json:"percentPnl,omitempty"`
	RealizedPnl        float64 `json:"realizedPnl,omitempty"`
	PercentRealizedPnl float64 `json:"percentRealizedPnl,omitempty"`
	Title              string  `json:"title"`
	Slug               string  `json:"slug,omitempty"`
	Icon               string  `json:"icon,omitempty"`
	EventID            string  `json:"eventId,omitempty"`
	EventSlug          string  `json:"eventSlug,omitempty"`
	OppositeOutcome    string  `json:"oppositeOutcome,omitempty"`
	OppositeAsset      string  `json:"oppositeAsset,omitempty"`
	Redeemable         bool    `json:"redeemable,omitempty"`
	Mergeable          bool    `json:"mergeable,omitempty"`
	EndDate            string  `json:"endDate,omitempty"`
	NegativeRisk       bool    `json:"negativeRisk,omitempty"`
}

Position represents a position from Data API

type PositionsParams

type PositionsParams struct {
	Limit         int      `url:"limit,omitempty"`
	Offset        int      `url:"offset,omitempty"`
	SortBy        string   `url:"sortBy,omitempty"`        // CURRENT, INITIAL, TOKENS, CASHPNL, PERCENTPNL, TITLE, RESOLVING, PRICE, AVGPRICE
	SortDirection string   `url:"sortDirection,omitempty"` // ASC, DESC
	Market        []string `url:"market,omitempty"`
	EventID       []int    `url:"eventId,omitempty"`
	SizeThreshold float64  `url:"sizeThreshold,omitempty"`
	Redeemable    *bool    `url:"redeemable,omitempty"`
	Mergeable     *bool    `url:"mergeable,omitempty"`
	Title         string   `url:"title,omitempty"`
}

type TradesParams

type TradesParams struct {
	Limit          int     `url:"limit,omitempty"`
	Market         string  `url:"market,omitempty"`
	User           string  `url:"user,omitempty"`
	TakerOnly      *bool   `url:"takerOnly,omitempty"`
	FilterType     string  `url:"filterType,omitempty"` // CASH | TOKENS
	FilterAmount   float64 `url:"filterAmount,omitempty"`
	Side           string  `url:"side,omitempty"` // BUY | SELL
	StartTimestamp int64   `url:"-"`              // Client-side filtering
	EndTimestamp   int64   `url:"-"`              // Client-side filtering
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL