polymarket_gamma

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: MIT Imports: 10 Imported by: 0

README

Polymarket Gamma API Go Client

A Go client for interacting with the Polymarket Gamma structure API.

(because I found Typescript & Python slow)

Notes

This package:

  • Does not error when new fields are added
  • Will validate known fields
  • May become out of date (please make a PR!)
  • Supports querying by event, which is Polymarket's recommended method for market & event discovery

Installation

go get github.com/CalderWhite/polymarket-gamma-go

Usage

Fetching events by Id

package main

import (
    "fmt"
    "log"
    
    polymarket_gamma "github.com/polymarket-gamma-go"
)

func main() {
    // Create a client with default settings
    client := polymarket_gamma.NewClient(nil)
    
    // Fetch events by IDs (query uses integers, response contains string IDs)
    response, err := client.GetEventsByIDs([]int{2890, 2891, 2892})
    if err != nil {
        log.Fatal(err)
    }
    
    for _, event := range response.Events {
        fmt.Printf("Event: %s\n", event.Title)
        for _, market := range event.Markets {
            fmt.Printf("  Market: %s\n", market.Question)
        }
    }
}

Pagination

This is primarily for event/market discovery.

// Fetch the latest 10 events (by ID)
response, err := client.GetEventsByPage(0, 10, false)

// Fetch events in order
response, err := client.GetEventsByPage(0, 10, true)

Documentation

Overview

Package polymarket_gamma provides a Go client for interacting with the Polymarket Gamma structure API.

This package:

  • Does not error when new fields are added
  • Will validate known fields
  • May become out of date (please make a PR!)
  • Supports querying by event, which is Polymarket's recommended method for market & event discovery

Installation

go get github.com/CalderWhite/polymarket-gamma-go

Usage

Fetching events by ID:

client := polymarket_gamma.NewClient(nil)
response, err := client.GetEventsByIDs([]int{2890, 2891, 2892})
if err != nil {
    log.Fatal(err)
}

for _, event := range response.Events {
    fmt.Printf("Event: %s\n", event.Title)
    for _, market := range event.Markets {
        fmt.Printf("  Market: %s\n", market.Question)
    }
}

Pagination (for event/market discovery):

// Fetch the latest 10 events (by ID)
response, err := client.GetEventsByPage(0, 10, false)

// Fetch events in order
response, err := client.GetEventsByPage(0, 10, true)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	ID             string    `json:"id"`
	Label          string    `json:"label"`
	ParentCategory string    `json:"parentCategory"`
	Slug           string    `json:"slug"`
	PublishedAt    string    `json:"publishedAt"`
	CreatedBy      string    `json:"createdBy"`
	UpdatedBy      string    `json:"updatedBy"`
	CreatedAt      time.Time `json:"createdAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
}

Category represents a category for events or markets

type Client

type Client struct {
	// contains filtered or unexported fields
}

Polymarket Gamma API client

func NewClient

func NewClient(config *ClientConfig) *Client

func (*Client) GetActiveEventsByPage

func (c *Client) GetActiveEventsByPage(offset, limit int, ascending bool) (*GetEventsResponse, error)

func (*Client) GetEventsByIDs

func (c *Client) GetEventsByIDs(ids []int) (*GetEventsResponse, error)

GetEventsByIDs fetches events by their IDs from the Polymarket Gamma API

func (*Client) GetEventsByPage

func (c *Client) GetEventsByPage(offset, limit int, ascending bool) (*GetEventsResponse, error)

GetEventsByPage fetches events with pagination from the Polymarket Gamma API

type ClientConfig

type ClientConfig struct {
	BaseURL string
	Timeout time.Duration
	// Custom transport (optional)
	Transport http.RoundTripper
	// Custom HTTP client (optional)
	HTTPClient *http.Client
}

type Event

type Event struct {
	ID                     string             `json:"id" validate:"required"`
	Ticker                 string             `json:"ticker"`
	Slug                   string             `json:"slug"`
	Title                  string             `json:"title"`
	Subtitle               string             `json:"subtitle"`
	Description            string             `json:"description"`
	ResolutionSource       string             `json:"resolutionSource"`
	StartDate              time.Time          `json:"startDate"`
	CreationDate           time.Time          `json:"creationDate"`
	EndDate                time.Time          `json:"endDate"`
	ImageURL               string             `json:"image"`
	Icon                   string             `json:"icon"`
	Active                 bool               `json:"active"`
	Closed                 bool               `json:"closed"`
	Archived               bool               `json:"archived"`
	New                    bool               `json:"new"`
	Featured               bool               `json:"featured"`
	Restricted             bool               `json:"restricted"`
	Liquidity              float64            `json:"liquidity"`
	Volume                 float64            `json:"volume"`
	OpenInterest           float64            `json:"openInterest"`
	SortBy                 string             `json:"sortBy"`
	Category               string             `json:"category"`
	Subcategory            string             `json:"subcategory"`
	PublishedAt            string             `json:"published_at"`
	CreatedBy              string             `json:"createdBy"`
	UpdatedBy              string             `json:"updatedBy"`
	CreatedAt              time.Time          `json:"createdAt"`
	UpdatedAt              time.Time          `json:"updatedAt"`
	CommentsEnabled        bool               `json:"commentsEnabled"`
	Competitive            float64            `json:"competitive"`
	Volume24hr             float64            `json:"volume24hr"`
	Volume1wk              float64            `json:"volume1wk"`
	Volume1mo              float64            `json:"volume1mo"`
	Volume1yr              float64            `json:"volume1yr"`
	FeaturedImage          string             `json:"featuredImage"`
	EnableOrderBook        bool               `json:"enableOrderBook"`
	LiquidityAmm           float64            `json:"liquidityAmm"`
	LiquidityClob          float64            `json:"liquidityClob"`
	NegRisk                bool               `json:"negRisk"`
	NegRiskMarketID        string             `json:"negRiskMarketID"`
	CommentCount           int                `json:"commentCount"`
	ImageOptimized         *ImageOptimization `json:"imageOptimized"`
	IconOptimized          *ImageOptimization `json:"iconOptimized"`
	FeaturedImageOptimized *ImageOptimization `json:"featuredImageOptimized"`
	SubEvents              []string           `json:"subEvents"`
	Markets                []Market           `json:"markets"`
	Series                 []Series           `json:"series"`
	Categories             []Category         `json:"categories"`
	Tags                   []Tag              `json:"tags"`
	Cyom                   bool               `json:"cyom"`
	ClosedTime             time.Time          `json:"closedTime"`
	ShowAllOutcomes        bool               `json:"showAllOutcomes"`
	ShowMarketImages       bool               `json:"showMarketImages"`
	EnableNegRisk          bool               `json:"enableNegRisk"`
	SeriesSlug             string             `json:"seriesSlug"`
	Live                   bool               `json:"live"`
	Ended                  bool               `json:"ended"`
	EventCreators          []EventCreator     `json:"eventCreators"`
}

Event represents a Polymarket event from the Gamma API

type EventCreator

type EventCreator struct {
	ID            string    `json:"id"`
	CreatorName   string    `json:"creatorName"`
	CreatorHandle string    `json:"creatorHandle"`
	CreatorURL    string    `json:"creatorUrl"`
	CreatorImage  string    `json:"creatorImage"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
}

EventCreator represents a creator of an event

type GetEventsResponse

type GetEventsResponse struct {
	Events []Event `json:"events"`
}

GetEventsResponse represents the response from the events endpoint

type ImageOptimization

type ImageOptimization struct {
	ID                       string  `json:"id"`
	ImageURLSource           string  `json:"imageUrlSource"`
	ImageURLOptimized        string  `json:"imageUrlOptimized"`
	ImageSizeKbSource        float64 `json:"imageSizeKbSource"`
	ImageSizeKbOptimized     float64 `json:"imageSizeKbOptimized"`
	ImageOptimizedComplete   bool    `json:"imageOptimizedComplete"`
	ImageOptimizedLastUpdate string  `json:"imageOptimizedLastUpdated"`
	RelID                    int     `json:"relID"`
	Field                    string  `json:"field"`
	Relname                  string  `json:"relname"`
}

ImageOptimization represents optimized image metadata

type Market

type Market struct {
	ID                 string             `json:"id" validate:"required"`
	Question           string             `json:"question"`
	ConditionID        string             `json:"conditionId"`
	Slug               string             `json:"slug"`
	ResolutionSource   string             `json:"resolutionSource"`
	EndDate            time.Time          `json:"endDate"`
	StartDate          time.Time          `json:"startDate"`
	Description        string             `json:"description"`
	Active             bool               `json:"active"`
	Closed             bool               `json:"closed"`
	Archived           bool               `json:"archived"`
	MarketType         string             `json:"marketType"`
	RewardsMinSize     float64            `json:"rewardsMinSize"`
	RewardsMaxSpread   float64            `json:"rewardsMaxSpread"`
	Outcomes           string             `json:"outcomes"`
	OutcomePrices      string             `json:"outcomePrices"`
	Volume             string             `json:"volume"`
	Liquidity          string             `json:"liquidity"`
	Category           string             `json:"category"`
	CreatedAt          time.Time          `json:"createdAt"`
	UpdatedAt          time.Time          `json:"updatedAt"`
	CreatedBy          int                `json:"createdBy"`
	UpdatedBy          int                `json:"updatedBy"`
	MarketMakerAddress string             `json:"marketMakerAddress"`
	New                bool               `json:"new"`
	Featured           bool               `json:"featured"`
	Restricted         bool               `json:"restricted"`
	VolumeNum          float64            `json:"volumeNum"`
	LiquidityNum       float64            `json:"liquidityNum"`
	Volume24hr         float64            `json:"volume24hr"`
	Volume1wk          float64            `json:"volume1wk"`
	Volume1mo          float64            `json:"volume1mo"`
	Volume1yr          float64            `json:"volume1yr"`
	EnableOrderBook    bool               `json:"enableOrderBook"`
	ClobTokenIds       string             `json:"clobTokenIds"`
	Competitive        float64            `json:"competitive"`
	Spread             float64            `json:"spread"`
	LastTradePrice     float64            `json:"lastTradePrice"`
	BestBid            float64            `json:"bestBid"`
	BestAsk            float64            `json:"bestAsk"`
	ImageOptimized     *ImageOptimization `json:"imageOptimized"`
	IconOptimized      *ImageOptimization `json:"iconOptimized"`
	Categories         []Category         `json:"categories"`
	Tags               []Tag              `json:"tags"`
	CommentsEnabled    bool               `json:"commentsEnabled"`
}

Market represents a Polymarket market from the Gamma API

type Series

type Series struct {
	ID              string     `json:"id"`
	Ticker          string     `json:"ticker"`
	Slug            string     `json:"slug"`
	Title           string     `json:"title"`
	Subtitle        string     `json:"subtitle"`
	SeriesType      string     `json:"seriesType"`
	Recurrence      string     `json:"recurrence"`
	Description     string     `json:"description"`
	Image           string     `json:"image"`
	Icon            string     `json:"icon"`
	Layout          string     `json:"layout"`
	Active          bool       `json:"active"`
	Closed          bool       `json:"closed"`
	Archived        bool       `json:"archived"`
	New             bool       `json:"new"`
	Featured        bool       `json:"featured"`
	Restricted      bool       `json:"restricted"`
	PublishedAt     string     `json:"publishedAt"`
	CreatedBy       string     `json:"createdBy"`
	UpdatedBy       string     `json:"updatedBy"`
	CreatedAt       time.Time  `json:"createdAt"`
	UpdatedAt       time.Time  `json:"updatedAt"`
	CommentsEnabled bool       `json:"commentsEnabled"`
	Competitive     string     `json:"competitive"`
	Volume24hr      float64    `json:"volume24hr"`
	Volume          float64    `json:"volume"`
	Liquidity       float64    `json:"liquidity"`
	StartDate       time.Time  `json:"startDate"`
	CommentCount    int        `json:"commentCount"`
	Categories      []Category `json:"categories"`
	Tags            []Tag      `json:"tags"`
}

Series represents a series that an event belongs to

type Tag

type Tag struct {
	ID          string    `json:"id"`
	Label       string    `json:"label"`
	Slug        string    `json:"slug"`
	ForceShow   bool      `json:"forceShow"`
	PublishedAt string    `json:"publishedAt"`
	CreatedBy   int       `json:"createdBy"`
	UpdatedBy   int       `json:"updatedBy"`
	CreatedAt   time.Time `json:"createdAt"`
	UpdatedAt   time.Time `json:"updatedAt"`
	ForceHide   bool      `json:"forceHide"`
	IsCarousel  bool      `json:"isCarousel"`
}

Tag represents a tag associated with an event or market

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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