polyhttp

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package polyhttp provides the shared HTTP client used by all Polymarket API packages (clob, data, gamma, relayer, bridge).

Authentication Levels

Polymarket endpoints use three auth tiers:

AuthNone (0) — public endpoints, no headers
AuthL1   (1) — EIP-712 wallet-signed headers (e.g. CreateAPIKey)
AuthL2   (2) — full trading: requires both a Signer and Credentials

The caller passes the desired AuthLevel to GetJSON, PostJSON, DeleteJSON, or DoJSON. If Client.Headers (a HeaderFunc) is non-nil, it is invoked with the level to produce auth headers injected into every request.

Client Usage

The Client struct holds BaseURL, an http.Client, UserAgent, and the optional HeaderFunc callback. Construct it directly and pass it to higher-level packages.

Request Pipeline

GetJSON/PostJSON/DeleteJSON → DoJSON → marshal body (JSON/[]byte/string) → build request → set Accept/Content-Type/User-Agent → call HeaderFunc for auth → execute → on non-2xx return *APIError → otherwise unmarshal JSON into out (with special handling for *int64 and *string responses).

Query Parameters

Callers pass url.Values to DoJSON/GetJSON. At the package level, query structs use `url:"param"` tags and are reflected into values by the caller before constructing the final query map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode  int
	Message     string
	Body        []byte
	RequestBody []byte
}

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) HTTPStatus

func (e *APIError) HTTPStatus() int

type AuthLevel

type AuthLevel int
const (
	AuthNone AuthLevel = iota
	AuthL1
	AuthL2
)

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	UserAgent  string
	Headers    HeaderFunc
}

func (*Client) DeleteJSON

func (c *Client) DeleteJSON(ctx context.Context, path string, body any, auth AuthLevel, out any) error

func (*Client) DoJSON

func (c *Client) DoJSON(ctx context.Context, method, path string, query url.Values, body any, auth AuthLevel, nonce *int64, out any) error

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, path string, query url.Values, auth AuthLevel, out any) error

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, path string, body any, auth AuthLevel, out any) error

type HeaderFunc

type HeaderFunc func(ctx context.Context, method, path string, body []byte, level AuthLevel, nonce *int64) (map[string]string, error)

Jump to

Keyboard shortcuts

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