coinbasego

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT Imports: 16 Imported by: 0

README

coinbasego

A client written in golang to work with the coinbasego exchange rest API.

Coinbase pro reference docs: https://docs.cloud.coinbase.com/exchange/reference

NOTE: Does not implement every feature in the reference doc.

Installation

go get github.com/NekoFluff/coinbasego

Documentation

Index

Constants

View Source
const (
	CancelAfterMin  = "min"
	CancelAFterHour = "hour"
	CancelAfterDay  = "day"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyClaims added in v1.3.0

type APIKeyClaims struct {
	*jwt.Claims
	URI string `json:"uri"`
}

type Account

type Account struct {
	UUID             string `json:"uuid" binding:"required"`
	Name             string `json:"name" binding:"required"`
	Currency         string `json:"currency" binding:"required"`
	AvailableBalance struct {
		Value    string `json:"value" binding:"required"`
		Currency string `json:"currency" binding:"required"`
	} `json:"available_balance" binding:"required"`
	Default   bool   `json:"default"`
	Active    bool   `json:"active"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	DeletedAt string `json:"deleted_at"`
	Type      string `json:"type"`
	Ready     bool   `json:"ready"`
	Hold      struct {
		Value    string `json:"value" binding:"required"`
		Currency string `json:"currency" binding:"required"`
	}
	RetailPortfolioID string `json:"retail_portfolio_id"`
	Platform          string `json:"platform"`
}

type AccountResponse added in v1.3.0

type AccountResponse struct {
	Account Account `json:"account"`
}

type AccountsParams

type AccountsParams struct {
	PaginationParams
}

type AccountsResponse added in v1.3.0

type AccountsResponse struct {
	PaginationResponse
	Accounts []Account `json:"accounts"`
}

type CancelAfter

type CancelAfter string

type Candle

type Candle struct {
	Start  time.Time `json:"start"`
	Low    float64   `json:"low"`
	High   float64   `json:"high"`
	Open   float64   `json:"open"`
	Close  float64   `json:"close"`
	Volume string    `json:"volume"`
}

func (*Candle) UnmarshalJSON

func (c *Candle) UnmarshalJSON(b []byte) error

type CandlesParams

type CandlesParams struct {
	Limit       int32       `url:"limit,omitempty"`
	Granularity Granularity `url:"granularity,omitempty"`
	Start       int64       `url:"start,omitempty"`
	End         int64       `url:"end,omitempty"`
}

type CandlesResponse added in v1.3.0

type CandlesResponse struct {
	Candles []Candle `json:"candles"`
}

type Client

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

func NewClient

func NewClient(credentials ClientCredentials) *Client

func (*Client) Account

func (client *Client) Account(uuid string) (*Account, error)

func (*Client) Accounts

func (client *Client) Accounts() ([]Account, error)

func (*Client) Candles

func (client *Client) Candles(productID string, p CandlesParams) ([]Candle, error)

func (*Client) CreateOrder added in v1.4.0

func (client *Client) CreateOrder(body CreateOrderRequest) (*Order, error)

func (*Client) JWT added in v1.3.0

func (c *Client) JWT(r Request) (string, error)

func (*Client) Order

func (client *Client) Order(id string) (*Order, error)

func (*Client) Orders

func (client *Client) Orders(p OrdersParams) ([]Order, error)

func (*Client) Portfolios added in v1.3.0

func (client *Client) Portfolios() ([]Portfolio, error)

func (*Client) Product

func (client *Client) Product(id string) (*Product, error)

func (*Client) Products

func (client *Client) Products() ([]Product, error)

type ClientCredentials

type ClientCredentials struct {
	KeyName   string
	KeySecret string
}

type CreateOrderRequest added in v1.4.0

type CreateOrderRequest struct {
	// Required fields
	ClientOrderID      string             `json:"client_order_id" binding:"required"`
	ProductID          ProductID          `json:"product_id" binding:"required"`
	Side               OrderSide          `json:"side" binding:"required"`
	OrderConfiguration OrderConfiguration `json:"order_configuration" binding:"required"`

	// Optional Fields
	Leverage                   string             `json:"leverage,omitempty"`
	MarginType                 string             `json:"margin_type,omitempty"` // Either "CROSS" or "ISOLATED"
	PreviewID                  string             `json:"preview_id,omitempty"`
	AttachedOrderConfiguration OrderConfiguration `json:"attached_order_configuration,omitempty"`
	SmartOrderRoutingDisabled  bool               `json:"sor_disabled,omitempty"`
}

https://docs.cdp.coinbase.com/api-reference/advanced-trade-api/rest-api/orders/create-order

type Granularity

type Granularity string
var (
	GranularityMinute         Granularity = "ONE_MINUTE"
	GranularityFiveMinutes    Granularity = "FIVE_MINUTE"
	GranularityFifteenMinutes Granularity = "FIFTEEN_MINUTE"
	GranularityHour           Granularity = "ONE_HOUR"
	GranularitySixHours       Granularity = "SIX_HOUR"
	GranularityDay            Granularity = "ONE_DAY"
)

type LimitLimitFOK added in v1.4.0

type LimitLimitFOK struct {
	QuoteSize  string `json:"quote_size,omitempty"`
	BaseSize   string `json:"base_size,omitempty"`
	LimitPrice string `json:"limit_price,omitempty"`
}

type LimitLimitGTC added in v1.4.0

type LimitLimitGTC struct {
	QuoteSize  string `json:"quote_size,omitempty"`
	BaseSize   string `json:"base_size,omitempty"`
	LimitPrice string `json:"limit_price,omitempty"`
	PostOnly   bool   `json:"post_only,omitempty"`
}

type LimitLimitGTD added in v1.4.0

type LimitLimitGTD struct {
	QuoteSize  string    `json:"quote_size,omitempty"`
	BaseSize   string    `json:"base_size,omitempty"`
	LimitPrice string    `json:"limit_price,omitempty"`
	EndTime    time.Time `json:"end_time,omitempty"`
	PostOnly   bool      `json:"post_only,omitempty"`
}

type MarketmarketIOC added in v1.4.0

type MarketmarketIOC struct {
	QuoteSize string `json:"quote_size,omitempty"`
	BaseSize  string `json:"base_size,omitempty"`
}

type Order

type Order struct {
	OrderID               string             `json:"order_id"`
	ProductID             string             `json:"product_id"`
	UserID                string             `json:"user_id"`
	OrderConfiguration    OrderConfiguration `json:"order_configuration"`
	Side                  OrderSide          `json:"side"`
	ClientOrderID         string             `json:"client_order_id"`
	Status                OrderStatus        `json:"status"`
	TimeInForce           TimeInForce        `json:"time_in_force"`
	CreatedTime           time.Time          `json:"created_time"`
	CompletionPercentage  string             `json:"completion_percentage"`
	FilledSize            string             `json:"filled_size"`
	AverageFilledPrice    string             `json:"average_filled_price"`
	NumberOfFills         string             `json:"number_of_fills"`
	FilledValue           string             `json:"filled_value"`
	PendingCancel         bool               `json:"pending_cancel"`
	SizeInQuote           bool               `json:"size_in_quote"`
	TotalFees             string             `json:"total_fees"`
	SizeInclusiveOfFees   bool               `json:"size_inclusive_of_fees"`
	TotalValueAfterFees   string             `json:"total_value_after_fees"`
	TriggerStatus         string             `json:"trigger_status"` // TODO: This is an enum
	OrderType             OrderType          `json:"order_type"`
	RejectReason          string             `json:"reject_reason"` // TODO: This is an enum
	Settled               bool               `json:"settled"`
	ProductType           string             `json:"product_type"` // TODO: This is an enum
	RejectMessage         string             `json:"reject_message"`
	CancelMessage         string             `json:"cancel_message"`
	OrderPlacementSource  string             `json:"order_placement_source"` // TODO: This is an enum
	OutstandingHoldAmount string             `json:"outstanding_hold_amount"`
	IsLiquidation         bool               `json:"is_liquidation"`
	LastFillTime          time.Time          `json:"last_fill_time"`
	// TODO: Edit history
	Leverage string `json:"leverage"`
}

type OrderConfiguration added in v1.4.0

type OrderConfiguration struct {
	MarketmarketIOC *MarketmarketIOC `json:"marketmarket_ioc,omitempty"`
	SorLimitIOC     *SorLimitIOC     `json:"sor_limit_ioc,omitempty"`
	LimitLimitGTC   *LimitLimitGTC   `json:"limit_limit_gtc,omitempty"`
	LimitLimitGTD   *LimitLimitGTD   `json:"limit_limit_gtd,omitempty"`
	LimitLimitFOK   *LimitLimitFOK   `json:"limit_limit_fok,omitempty"`
}

type OrderResponse added in v1.3.0

type OrderResponse struct {
	Order Order `json:"order"`
}

type OrderSide

type OrderSide string
const (
	OrderSideBuy  OrderSide = "BUY"
	OrderSideSell OrderSide = "SELL"
)

type OrderStatus

type OrderStatus string
const (
	OrderStatusOpen         OrderStatus = "OPEN"
	OrderStatusPending      OrderStatus = "PENDING"
	OrderStatusFilled       OrderStatus = "FILLED"
	OrderStatusCancelled    OrderStatus = "CANCELLED"
	OrderStatusExpired      OrderStatus = "EXPIRED"
	OrderStatusFailed       OrderStatus = "FAILED"
	OrderStatusUnknown      OrderStatus = "UNKNOWN_ORDER_STATUS"
	OrderStatusQueued       OrderStatus = "QUEUED"
	OrderStatusCancelQueued OrderStatus = "CANCEL_QUEUED"
)

type OrderType

type OrderType string
const (
	OrderTypeUnknown   OrderType = "UNKNOWN_ORDER_TYPE"
	OrderTypeMarket    OrderType = "MARKET"
	OrderTypeLimit     OrderType = "LIMIT"
	OrderTypeStop      OrderType = "STOP"
	OrderTypeStopLimit OrderType = "STOP_LIMIT"
	OrderTypeBracket   OrderType = "BRACKET"
	OrderTypeTWAP      OrderType = "TWAP"
)

type OrdersParams

type OrdersParams struct {
	PaginationParams
	OrderIDs     []string      `url:"order_ids,omitempty"`
	ProductIDs   []ProductID   `url:"product_ids,omitempty"`
	OrderStatus  OrderStatus   `url:"order_status,omitempty"`
	TimeInForces []TimeInForce `url:"time_in_forces,omitempty"`
	OrderTypes   []OrderType   `url:"order_types,omitempty"`
	OrderSide    OrderSide     `url:"order_side,omitempty"`
	StartDate    time.Time     `url:"start_date,omitempty"` // RFC3339 timestamp, e.g. 2006-01-02T15:04:05Z
	EndDate      time.Time     `url:"end_date,omitempty"`   // RFC3339 timestamp, e.g. 2006-01-02T15:04:05Z
}

type OrdersResponse added in v1.3.0

type OrdersResponse struct {
	PaginationResponse
	Orders []Order `json:"orders"`
}

type PaginationParams

type PaginationParams struct {
	Cursor string `url:"cursor,omitempty"`
	Limit  int    `url:"limit" binding:"required"`
}

type PaginationResponse

type PaginationResponse struct {
	HasNext bool   `json:"has_next"`
	Cursor  string `json:"cursor"`
	Size    int32  `json:"size"`
}

type Portfolio added in v1.3.0

type Portfolio struct {
	Name    string `json:"name"`
	UUID    string `json:"uuid"`
	Type    string `json:"type"`
	Deleted bool   `json:"deleted"`
}

type PortfoliosResponse added in v1.3.0

type PortfoliosResponse struct {
	Portfolios []Portfolio
}

type Product

type Product struct {
	ProductID                 string `json:"product_id"`
	Price                     string `json:"price"`
	PricePercentageChange24H  string `json:"price_percentage_change_24h"`
	Volume24H                 string `json:"volume_24h"`
	VolumePercentageChange24H string `json:"volume_percentage_change_24h"`
	BaseIncrement             string `json:"base_increment"`
	QuoteIncrement            string `json:"quote_increment"`
	QuoteMinSize              string `json:"quote_min_size"`
	QuoteMaxSize              string `json:"quote_max_size"`
	BaseMinSize               string `json:"base_min_size"`
	BaseName                  string `json:"base_name"`
	QuoteName                 string `json:"quote_name"`
	Watched                   bool   `json:"watched"`
	IsDisabled                bool   `json:"is_disabled"`
	New                       bool   `json:"new"`
	Status                    string `json:"status"`
	CancelOnly                bool   `json:"cancel_only"`
	LimitOnly                 bool   `json:"limit_only"`
	PostOnly                  bool   `json:"post_only"`
	TradingDisabled           bool   `json:"trading_disabled"`
	AuctionMode               bool   `json:"auction_mode"`
	ProductType               string `json:"product_type"`
	QuoteCurrencyID           string `json:"quote_currency_id"`
	BaseCurrencyID            string `json:"base_currency_id"`
}

func (*Product) FixPrice

func (p *Product) FixPrice(size float64) float64

type ProductID

type ProductID string

type ProductsParams

type ProductsParams struct {
	PaginationParams
}

type Request

type Request struct {
	Method  string
	PathURL string
	Body    []byte
	Params  interface{}
}

type SorLimitIOC added in v1.4.0

type SorLimitIOC struct {
	QuoteSize  string `json:"quote_size,omitempty"`
	BaseSize   string `json:"base_size,omitempty"`
	LimitPrice string `json:"limit_price,omitempty"`
}

type TimeInForce

type TimeInForce string
const (
	TimeInForceUnknown            TimeInForce = "UNKNOWN_TIME_IN_FORCE"
	TimeInForceGoodUntilDateTime  TimeInForce = "GOOD_UNTIL_DATE_TIME"
	TimeInForceGoodUntilCancelled TimeInForce = "GOOD_UNTIL_CANCELLED"
	TimeInForceImmediateOrCancel  TimeInForce = "IMMEDIATE_OR_CANCEL"
	TimeInForceFillOrKill         TimeInForce = "FILL_OR_KILL"
)

Jump to

Keyboard shortcuts

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