coinbase

package module
v0.0.0-...-b0b098f Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 22 Imported by: 0

README

Go Coinbase Pro GoDoc

v3 CoinBase Pro API client fork, though it has basically zero resemblance to the origin

Go get

go get github.com/AnthonyHewins/coinbase

Decimal management

To manage precision correctly, this library sends all price values as strings for now. Considering building a decimal library directly into the codebase, but not sure which one

Examples

Create order

All order types are available. To specify which one you want you need to pick an implementation of the OrderConfig interface:

  • MarketOrder
  • LimitOrderIOC
  • LimitOrderFOK
  • LimitOrderGTC
  • LimitOrderGTD
  • StopLimitOrderGTC
  • StopLimitOrderGTD
  • TriggerBracketOrderGTC
  • TriggerBracketOrderGTD
idemKey := uuid.New() // idempotency ID you create
wasCreated, err := client.CreateOrder(ctx, &coinbase.Order{
  ID: idemKey.String(),
  ProductID: "BTC-USD",
  Side: coinbase.SideBuy,
  Leverage: "2",
  MarginType: MarginTypeCross,
  RetailPortfolioID: "123153432",
  PreviewID: "1",
  Config: &MarketOrder{ // or any other implementation
    BaseSize: "1",
    QuoteSize: "1",
  },
})
Cancel order(s)
err := client.CancelOrders(ctx, "id", "id2") // returns any failures, any error
List orders

Partial implementation; no query parameters are allowed. Implementing the websocket version is more important for now

order, err := client.ListOrders(ctx)

Documentation

Index

Constants

View Source
const DefaultProdURL = "https://api.coinbase.com/api/v3/brokerage"
View Source
const DefaultSandboxURL = "https://api.sandbox.coinbase.com"

Variables

This section is empty.

Functions

func AcctTypeStrings

func AcctTypeStrings() []string

AcctTypeStrings returns a slice of all String values of the enum

func FuturesPositionStrings

func FuturesPositionStrings() []string

FuturesPositionStrings returns a slice of all String values of the enum

func MarginTypeStrings

func MarginTypeStrings() []string

MarginTypeStrings returns a slice of all String values of the enum

func OrderPlacementSrcStrings

func OrderPlacementSrcStrings() []string

OrderPlacementSrcStrings returns a slice of all String values of the enum

func OrderTypeStrings

func OrderTypeStrings() []string

OrderTypeStrings returns a slice of all String values of the enum

func PortfolioTypeStrings

func PortfolioTypeStrings() []string

PortfolioTypeStrings returns a slice of all String values of the enum

func ProductTypeStrings

func ProductTypeStrings() []string

ProductTypeStrings returns a slice of all String values of the enum

func RejectReasonStrings

func RejectReasonStrings() []string

RejectReasonStrings returns a slice of all String values of the enum

func SideStrings

func SideStrings() []string

SideStrings returns a slice of all String values of the enum

func StatusStrings

func StatusStrings() []string

StatusStrings returns a slice of all String values of the enum

func StopDirectionStrings

func StopDirectionStrings() []string

StopDirectionStrings returns a slice of all String values of the enum

func TIFStrings

func TIFStrings() []string

TIFStrings returns a slice of all String values of the enum

func TriggerStatusStrings

func TriggerStatusStrings() []string

TriggerStatusStrings returns a slice of all String values of the enum

Types

type Account

type Account struct {
	ID                uuid.UUID `json:"uuid"`
	Name              string    `json:"name"`
	Currency          string    `json:"currency"`
	AvailableBalance  Balance   `json:"available_balance"`
	Default           bool      `json:"default"`
	Active            bool      `json:"active"`
	Created           time.Time `json:"created_at"`
	Updated           time.Time `json:"updated_at"`
	Deleted           time.Time `json:"deleted_at"`
	Type              AcctType  `json:"type"`
	Ready             bool      `json:"ready"`
	Hold              Balance   `json:"hold"`
	RetailPortfolioID string    `json:"retail_portfolio_id"`
}

type AcctType

type AcctType byte
const (
	AccountTypeUnspecified AcctType = iota
	AccountTypeCrypto
	AccountTypeFiat
	AccountTypeVault
	AccountTypePerpFutures
)

func AcctTypeString

func AcctTypeString(s string) (AcctType, error)

AcctTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func AcctTypeValues

func AcctTypeValues() []AcctType

AcctTypeValues returns all values of the enum

func (AcctType) IsAAcctType

func (i AcctType) IsAAcctType() bool

IsAAcctType returns "true" if the value is listed in the enum definition. "false" otherwise

func (AcctType) MarshalJSON

func (i AcctType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for AcctType

func (AcctType) String

func (i AcctType) String() string

func (*AcctType) UnmarshalJSON

func (i *AcctType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for AcctType

type Balance

type Balance struct {
	Currency string          `json:"currency"`
	Value    decimal.Decimal `json:"value"`
}

type BidAsk

type BidAsk struct {
	ProductID string           `json:"product_id"`
	Time      time.Time        `json:"time"`
	Bids      []OrderBookEntry `json:"bids"`
	Asks      []OrderBookEntry `json:"asks"`
}

type Book

type Book struct {
	Sequence int64       `json:"sequence"`
	Bids     []BookEntry `json:"bids"`
	Asks     []BookEntry `json:"asks"`
}

type BookEntry

type BookEntry struct {
	Price          string
	Size           string
	NumberOfOrders int
	OrderID        string
}

func (*BookEntry) UnmarshalJSON

func (e *BookEntry) UnmarshalJSON(data []byte) error

type Client

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

func NewClient

func NewClient(baseURL, keyName, keySecret string, httpClient *http.Client) (*Client, error)

func NewClientWithPrivateKey

func NewClientWithPrivateKey(baseURL, keyName string, privateKey *ecdsa.PrivateKey, httpClient *http.Client) (*Client, error)

func (*Client) BidAsk

func (c *Client) BidAsk(ctx context.Context, pairs ...string) ([]BidAsk, error)

func (*Client) CancelOrders

func (c *Client) CancelOrders(ctx context.Context, ids ...string) error

func (*Client) CreateOrder

func (c *Client) CreateOrder(ctx context.Context, newOrder *CreateOrderArgs) (*CreateOrderResp, error)

func (*Client) CreateProfileTransfer

func (c *Client) CreateProfileTransfer(ctx context.Context, newTransfer *ProfileTransfer) error

CreateProfileTransfer transfers a currency amount from one profile to another

func (*Client) CreateReport

func (c *Client) CreateReport(ctx context.Context, newReport *Report) (Report, error)

func (*Client) GetAccount

func (c *Client) GetAccount(ctx context.Context, id uuid.UUID) (*Account, error)

func (*Client) GetBook

func (c *Client) GetBook(ctx context.Context, product string, level int) (Book, error)

func (*Client) GetHistoricRates

func (c *Client) GetHistoricRates(ctx context.Context, product string,
	p ...GetHistoricRatesParams) ([]HistoricRate, error)

func (*Client) GetOrder

func (c *Client) GetOrder(ctx context.Context, id uuid.UUID) (*Order, error)

func (*Client) GetPortfolio

func (c *Client) GetPortfolio(ctx context.Context, id uuid.UUID) (*Portfolio, error)

func (*Client) GetProducts

func (c *Client) GetProducts(ctx context.Context) ([]Product, error)

func (*Client) GetProfile

func (c *Client) GetProfile(ctx context.Context, id string) (Profile, error)

GetProfile retrieves a single profile

func (*Client) GetProfiles

func (c *Client) GetProfiles(ctx context.Context) ([]Profile, error)

GetProfiles retrieves a list of profiles

func (*Client) GetReportStatus

func (c *Client) GetReportStatus(ctx context.Context, id string) (Report, error)

func (*Client) GetStats

func (c *Client) GetStats(ctx context.Context, product string) (Stats, error)

func (*Client) GetTicker

func (c *Client) GetTicker(ctx context.Context, product string) (Ticker, error)

func (*Client) GetTime

func (c *Client) GetTime(ctx context.Context) (ServerTime, error)

func (*Client) ListAccounts

func (c *Client) ListAccounts(ctx context.Context) ([]Account, error)

func (*Client) ListFills

func (c *Client) ListFills(p ListFillsParams) *Cursor

func (*Client) ListOrders

func (c *Client) ListOrders(ctx context.Context) (*ListOrdersResp, error)

func (*Client) ListPortfolios

func (c *Client) ListPortfolios(ctx context.Context) ([]PortfolioView, error)

func (*Client) ListTrades

func (c *Client) ListTrades(ctx context.Context, product string,
	p ...ListTradesParams) *Cursor

type CreateOrderArgs

type CreateOrderArgs struct {
	ID        string      `json:"client_order_id"`
	ProductID string      `json:"product_id"`
	Side      Side        `json:"side"`
	Config    OrderConfig `json:"order_configuration"`

	// Optional: empty string will omit leverage
	Leverage string `json:"leverage,omitempty"`

	// Optional: default value will not send
	MarginType MarginType `json:"margin_type,omitempty"`

	// Optional: empty string will omit
	RetailPortfolioID string `json:"retail_portfolio_id,omitempty"`

	// Optional: empty string will omit
	PreviewID string `json:"preview_id,omitempty"`
}

type CreateOrderResp

type CreateOrderResp struct {
	ID         uuid.UUID
	WasCreated bool
}

type CreateReportParams

type CreateReportParams struct {
	Start time.Time
	End   time.Time
}

type Currency

type Currency struct {
	UserNativeCurrency Balance `json:"userNativeCurrency"`
	RawCurrency        Balance `json:"rawCurrency"`
}

type Cursor

type Cursor struct {
	Client     *Client
	Pagination *PaginationParams
	Method     string
	Params     interface{}
	URL        string
	HasMore    bool
}

func NewCursor

func NewCursor(client *Client, method, url string, paginationParams *PaginationParams) *Cursor

func (*Cursor) NextPage

func (c *Cursor) NextPage(ctx context.Context, i interface{}) error

func (*Cursor) Page

func (c *Cursor) Page(ctx context.Context, i interface{}, direction string) error

func (*Cursor) PrevPage

func (c *Cursor) PrevPage(ctx context.Context, i interface{}) error

type EditHistory

type EditHistory struct {
	Price                  string
	Size                   string
	ReplaceAcceptTimestamp time.Time
}

type Error

type Error struct {
	Err     string `json:"error"`
	Code    int    `json:"code"`
	Message string `json:"message"`
	Details string `json:"error_details"`
}

func (Error) Error

func (e Error) Error() string

type Fill

type Fill struct {
	TradeID   int             `json:"trade_id"`
	ProductID string          `json:"product_id"`
	Price     decimal.Decimal `json:"price"`
	Size      string          `json:"size"`
	FillID    string          `json:"order_id"`
	CreatedAt Time            `json:"created_at"`
	Fee       string          `json:"fee"`
	Settled   bool            `json:"settled"`
	Side      string          `json:"side"`
	Liquidity string          `json:"liquidity"`
}

type FuturePosition

type FuturePosition struct {
	ProductId       string          `json:"product_id"`
	ContractSize    string          `json:"contract_size"`
	Side            string          `json:"side"`
	Amount          decimal.Decimal `json:"amount"`
	AvgEntryPrice   decimal.Decimal `json:"avg_entry_price"`
	CurrentPrice    decimal.Decimal `json:"current_price"`
	UnrealizedPnl   string          `json:"unrealized_pnl"`
	Expiry          time.Time       `json:"expiry"`
	UnderlyingAsset string          `json:"underlying_asset"`
	AssetImgUrl     string          `json:"asset_img_url"`
	ProductName     string          `json:"product_name"`
	Venue           string          `json:"venue"`
	NotionalValue   string          `json:"notional_value"`
}

type FuturesPosition

type FuturesPosition byte
const (
	FuturesPositionSideUnspecified FuturesPosition = iota
	FuturesPositionSideLong
	FuturesPositionSideShort
)

func FuturesPositionString

func FuturesPositionString(s string) (FuturesPosition, error)

FuturesPositionString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func FuturesPositionValues

func FuturesPositionValues() []FuturesPosition

FuturesPositionValues returns all values of the enum

func (FuturesPosition) IsAFuturesPosition

func (i FuturesPosition) IsAFuturesPosition() bool

IsAFuturesPosition returns "true" if the value is listed in the enum definition. "false" otherwise

func (FuturesPosition) MarshalJSON

func (i FuturesPosition) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for FuturesPosition

func (FuturesPosition) String

func (i FuturesPosition) String() string

func (*FuturesPosition) UnmarshalJSON

func (i *FuturesPosition) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for FuturesPosition

type GetHistoricRatesParams

type GetHistoricRatesParams struct {
	Start       time.Time
	End         time.Time
	Granularity int
}

type HistoricRate

type HistoricRate struct {
	Time   time.Time
	Low    float64
	High   float64
	Open   float64
	Close  float64
	Volume float64
}

func (*HistoricRate) UnmarshalJSON

func (e *HistoricRate) UnmarshalJSON(data []byte) error

type LimitOrderFOK

type LimitOrderFOK struct {
	// The amount of the first Asset in the Trading Pair. For example, on the
	// BTC-USD Order Book, BTC is the Base Asset.
	BaseSize decimal.Decimal `json:"base_size"`

	// The specified price, or better, that the Order should be executed at. A
	// Buy Order will execute at or lower than the limit price. A Sell Order
	// will execute at or higher than the limit price.
	LimitPrice decimal.Decimal `json:"limit_price"`
}

func (*LimitOrderFOK) MarshalJSON

func (l *LimitOrderFOK) MarshalJSON() ([]byte, error)

func (*LimitOrderFOK) OrderType

func (l *LimitOrderFOK) OrderType() OrderType

func (*LimitOrderFOK) UnmarshalJSON

func (l *LimitOrderFOK) UnmarshalJSON(b []byte) error

type LimitOrderGTC

type LimitOrderGTC struct {
	// The amount of the first Asset in the Trading Pair. For example, on the
	// BTC-USD Order Book, BTC is the Base Asset.
	BaseSize decimal.Decimal

	// The specified price, or better, that the Order should be executed at. A
	// Buy Order will execute at or lower than the limit price. A Sell Order
	// will execute at or higher than the limit price.
	LimitPrice decimal.Decimal

	// Enable or disable Post-only Mode. When enabled, only Maker Orders will be
	// posted to the Order Book. Orders that will be posted as a Taker Order
	// will be rejected.
	PostOnly bool
}

func (*LimitOrderGTC) MarshalJSON

func (l *LimitOrderGTC) MarshalJSON() ([]byte, error)

func (*LimitOrderGTC) OrderType

func (l *LimitOrderGTC) OrderType() OrderType

func (*LimitOrderGTC) UnmarshalJSON

func (l *LimitOrderGTC) UnmarshalJSON(b []byte) error

type LimitOrderGTD

type LimitOrderGTD struct {
	// The amount of the first Asset in the Trading Pair. For example, on the
	// BTC-USD Order Book, BTC is the Base Asset.
	BaseSize decimal.Decimal

	// The specified price, or better, that the Order should be executed at. A
	// Buy Order will execute at or lower than the limit price. A Sell Order
	// will execute at or higher than the limit price.
	LimitPrice decimal.Decimal
	EndTime    time.Time

	// Enable or disable Post-only Mode. When enabled, only Maker Orders will be
	// posted to the Order Book. Orders that will be posted as a Taker Order
	// will be rejected.
	PostOnly bool
}

func (*LimitOrderGTD) MarshalJSON

func (l *LimitOrderGTD) MarshalJSON() ([]byte, error)

func (*LimitOrderGTD) OrderType

func (l *LimitOrderGTD) OrderType() OrderType

func (*LimitOrderGTD) UnmarshalJSON

func (l *LimitOrderGTD) UnmarshalJSON(b []byte) error

type LimitOrderIOC

type LimitOrderIOC struct {
	// The amount of the first Asset in the Trading Pair. For example, on the
	// BTC-USD Order Book, BTC is the Base Asset.
	BaseSize decimal.Decimal

	// The specified price, or better, that the Order should be executed at. A
	// Buy Order will execute at or lower than the limit price. A Sell Order
	// will execute at or higher than the limit price.
	LimitPrice decimal.Decimal
}

func (*LimitOrderIOC) MarshalJSON

func (l *LimitOrderIOC) MarshalJSON() ([]byte, error)

func (*LimitOrderIOC) OrderType

func (l *LimitOrderIOC) OrderType() OrderType

func (*LimitOrderIOC) UnmarshalJSON

func (l *LimitOrderIOC) UnmarshalJSON(b []byte) error

type ListFillsParams

type ListFillsParams struct {
	OrderID    string
	ProductID  string
	Pagination PaginationParams
}

type ListOrdersParams

type ListOrdersParams struct {
	Status     string
	ProductID  string
	Pagination PaginationParams
}

type ListOrdersResp

type ListOrdersResp struct {
	Orders  []Order `json:"orders"`
	HasNext bool    `json:"has_next"`
}

type ListTradesParams

type ListTradesParams struct {
	Pagination PaginationParams
}

type MarginType

type MarginType byte
const (
	UnknownMarginType MarginType = iota
	MarginTypeCross
	MarginTypeIsolated
)

func MarginTypeString

func MarginTypeString(s string) (MarginType, error)

MarginTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func MarginTypeValues

func MarginTypeValues() []MarginType

MarginTypeValues returns all values of the enum

func (MarginType) IsAMarginType

func (i MarginType) IsAMarginType() bool

IsAMarginType returns "true" if the value is listed in the enum definition. "false" otherwise

func (MarginType) MarshalJSON

func (i MarginType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for MarginType

func (MarginType) String

func (i MarginType) String() string

func (*MarginType) UnmarshalJSON

func (i *MarginType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for MarginType

type MarketOrder

type MarketOrder struct {
	// The amount of the second Asset in the Trading Pair. For example, on the
	// BTC/USD Order Book, USD is the Quote Asset.
	QuoteSize decimal.Decimal

	// The amount of the first Asset in the Trading Pair. For example, on the
	// BTC-USD Order Book, BTC is the Base Asset.
	BaseSize decimal.Decimal
}

func (*MarketOrder) MarshalJSON

func (m *MarketOrder) MarshalJSON() ([]byte, error)

func (*MarketOrder) OrderType

func (m *MarketOrder) OrderType() OrderType

func (*MarketOrder) UnmarshalJSON

func (m *MarketOrder) UnmarshalJSON(b []byte) error

type Order

type Order struct {
	ID                    uuid.UUID // Coinbase's ID
	IdemKey               string    // idempotency key you used to create it
	ProductID             string
	User                  string
	Config                OrderConfig
	Side                  Side
	Status                Status
	TIF                   TIF // Time in force
	Created               time.Time
	Completion            string // amount of the order that's been filled
	FilledSize            string
	AvgFillPrice          string
	NumberOfFills         string
	FilledValue           string
	PendingCancel         bool
	SizeInQuote           bool
	TotalFees             string
	SizeInclusiveOfFees   bool
	TotalValueAfterFees   string
	TriggerStatus         TriggerStatus
	RejectReason          RejectReason
	Settled               bool
	ProductType           ProductType
	RejectMsg             string
	CancelMsg             string
	OrderPlacementSrc     OrderPlacementSrc
	OutstandingHoldAmount string
	Liquidation           bool
	LastFillTime          time.Time
	Edits                 []EditHistory
	Leverage              string
	MarginType            MarginType
	RetailPortfolioID     string
}

func (*Order) UnmarshalJSON

func (o *Order) UnmarshalJSON(b []byte) error

type OrderBookEntry

type OrderBookEntry struct {
	Price decimal.Decimal `json:"price"`
	Size  string          `json:"size"`
}

type OrderConfig

type OrderConfig interface {
	json.Marshaler
	json.Unmarshaler
	OrderType() OrderType
}

type OrderPlacementSrc

type OrderPlacementSrc byte
const (
	UnknownPlacementSource OrderPlacementSrc = iota
	OrderPlacementSrcRetailSimple
	OrderPlacementSrcRetailAdvanced
)

func OrderPlacementSrcString

func OrderPlacementSrcString(s string) (OrderPlacementSrc, error)

OrderPlacementSrcString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func OrderPlacementSrcValues

func OrderPlacementSrcValues() []OrderPlacementSrc

OrderPlacementSrcValues returns all values of the enum

func (OrderPlacementSrc) IsAOrderPlacementSrc

func (i OrderPlacementSrc) IsAOrderPlacementSrc() bool

IsAOrderPlacementSrc returns "true" if the value is listed in the enum definition. "false" otherwise

func (OrderPlacementSrc) MarshalJSON

func (i OrderPlacementSrc) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for OrderPlacementSrc

func (OrderPlacementSrc) String

func (i OrderPlacementSrc) String() string

func (*OrderPlacementSrc) UnmarshalJSON

func (i *OrderPlacementSrc) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for OrderPlacementSrc

type OrderType

type OrderType byte
const (
	OrderTypeUnspecified OrderType = iota
	Market
	LimitIOC // Immediate or cancel (has to fill some part of the order immediately, if it fails, cancel the rest)
	LimitFOK // Fill or Kill
	LimitGTC // Good til Canceled
	LimitGTD // Good til date
	StopLimitGTC
	StopLimitGTD
	TriggerBracketGTC
	TriggerBracketGTD
)

func OrderTypeString

func OrderTypeString(s string) (OrderType, error)

OrderTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func OrderTypeValues

func OrderTypeValues() []OrderType

OrderTypeValues returns all values of the enum

func (OrderType) IsAOrderType

func (i OrderType) IsAOrderType() bool

IsAOrderType returns "true" if the value is listed in the enum definition. "false" otherwise

func (OrderType) String

func (i OrderType) String() string

type PaginationParams

type PaginationParams struct {
	Limit  int
	Before string
	After  string
	Extra  map[string]string
}

func (*PaginationParams) AddExtraParam

func (p *PaginationParams) AddExtraParam(key, value string)

func (*PaginationParams) Done

func (p *PaginationParams) Done(direction string) bool

func (*PaginationParams) Encode

func (p *PaginationParams) Encode(direction string) string

type PerpetualPosition

type PerpetualPosition struct {
	ProductId          string     `json:"product_id"`
	ProductUuid        string     `json:"product_uuid"`
	Symbol             string     `json:"symbol"`
	AssetImageUrl      string     `json:"asset_image_url"`
	NetSize            string     `json:"net_size"`
	BuyOrderSize       string     `json:"buy_order_size"`
	SellOrderSize      string     `json:"sell_order_size"`
	IMContribution     string     `json:"im_contribution"`
	VWAP               Currency   `json:"vwap"`
	UnrealizedPNL      Currency   `json:"unrealized_pnl"`
	MarkPrice          Currency   `json:"mark_price"`
	LiquidationPrice   Currency   `json:"liquidation_price"`
	Leverage           string     `json:"leverage"`
	IMNotational       Currency   `json:"im_notional"`
	MMNotational       Currency   `json:"mm_notional"`
	PositionNotational Currency   `json:"position_notional"`
	MarginType         MarginType `json:"margin_type"`
	LiquidationBuffer  string     `json:"liquidation_buffer"`
	LiquidationPct     string     `json:"liquidation_percentage"`
}

type Portfolio

type Portfolio struct {
	PortfolioView PortfolioView
	Balances      TotalBalances
	SpotPositions []SpotPosition
	Perpetuals    []PerpetualPosition
	Futures       []FuturePosition
}

type PortfolioType

type PortfolioType byte
const (
	PortfolioTypeUndefined PortfolioType = iota
	PortfolioTypeDefault
	PortfolioTypeConsumer
	PortfolioTypeIntx
)

func PortfolioTypeString

func PortfolioTypeString(s string) (PortfolioType, error)

PortfolioTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func PortfolioTypeValues

func PortfolioTypeValues() []PortfolioType

PortfolioTypeValues returns all values of the enum

func (PortfolioType) IsAPortfolioType

func (i PortfolioType) IsAPortfolioType() bool

IsAPortfolioType returns "true" if the value is listed in the enum definition. "false" otherwise

func (PortfolioType) MarshalJSON

func (i PortfolioType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for PortfolioType

func (PortfolioType) String

func (i PortfolioType) String() string

func (*PortfolioType) UnmarshalJSON

func (i *PortfolioType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for PortfolioType

type PortfolioView

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

type Product

type Product struct {
	ID              string `json:"id"`
	BaseCurrency    string `json:"base_currency"`
	QuoteCurrency   string `json:"quote_currency"`
	BaseMinSize     string `json:"base_min_size"`
	BaseMaxSize     string `json:"base_max_size"`
	QuoteIncrement  string `json:"quote_increment"`
	BaseIncrement   string `json:"base_increment"`
	DisplayName     string `json:"display_name"`
	MinMarketFunds  string `json:"min_market_funds"`
	MaxMarketFunds  string `json:"max_market_funds"`
	MarginEnabled   bool   `json:"margin_enabled"`
	PostOnly        bool   `json:"post_only"`
	LimitOnly       bool   `json:"limit_only"`
	CancelOnly      bool   `json:"cancel_only"`
	TradingDisabled bool   `json:"trading_disabled"`
	Status          string `json:"status"`
	StatusMessage   string `json:"status_message"`
}

type ProductType

type ProductType byte
const (
	UnknownProductType ProductType = iota
	ProductTypeSpot
	ProductTypeFuture
)

func ProductTypeString

func ProductTypeString(s string) (ProductType, error)

ProductTypeString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ProductTypeValues

func ProductTypeValues() []ProductType

ProductTypeValues returns all values of the enum

func (ProductType) IsAProductType

func (i ProductType) IsAProductType() bool

IsAProductType returns "true" if the value is listed in the enum definition. "false" otherwise

func (ProductType) MarshalJSON

func (i ProductType) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ProductType

func (ProductType) String

func (i ProductType) String() string

func (*ProductType) UnmarshalJSON

func (i *ProductType) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ProductType

type Profile

type Profile struct {
	ID        string `json:"id"`
	UserID    string `json:"user_id"`
	Name      string `json:"name"`
	Active    bool   `json:"active"`
	IsDefault bool   `json:"is_default"`
	CreatedAt Time   `json:"created_at,string"`
}

type ProfileTransfer

type ProfileTransfer struct {
	From     string `json:"from"`
	To       string `json:"to"`
	Currency string `json:"currency"`
	Amount   string `json:"amount"`
}

type RejectReason

type RejectReason byte
const (
	// These values vary wildly for some reason. The API in coinbase for this is
	// not consistent
	RejectReasonUnspecified RejectReason = iota
	HoldFailure
	TooManyOpenOrders
	RejectReasonInsufficientFunds
	RateLimitExceeded
)

func RejectReasonString

func RejectReasonString(s string) (RejectReason, error)

RejectReasonString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func RejectReasonValues

func RejectReasonValues() []RejectReason

RejectReasonValues returns all values of the enum

func (RejectReason) IsARejectReason

func (i RejectReason) IsARejectReason() bool

IsARejectReason returns "true" if the value is listed in the enum definition. "false" otherwise

func (RejectReason) MarshalJSON

func (i RejectReason) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for RejectReason

func (RejectReason) String

func (i RejectReason) String() string

func (*RejectReason) UnmarshalJSON

func (i *RejectReason) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for RejectReason

type Report

type Report struct {
	ID          string       `json:"id"`
	Type        string       `json:"type"`
	Status      string       `json:"status"`
	CreatedAt   Time         `json:"created_at,string"`
	CompletedAt Time         `json:"completed_at,string,"`
	ExpiresAt   Time         `json:"expires_at,string"`
	FileURL     string       `json:"file_url"`
	Params      ReportParams `json:"params"`
	StartDate   time.Time
	EndDate     time.Time
}

type ReportParams

type ReportParams struct {
	StartDate time.Time
	EndDate   time.Time
}

type ServerTime

type ServerTime struct {
	ISO   string  `json:"iso"`
	Epoch float64 `json:"epoch"`
}

type Side

type Side byte
const (
	SideUnspecified Side = iota
	SideBuy
	SideSell
)

func SideString

func SideString(s string) (Side, error)

SideString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func SideValues

func SideValues() []Side

SideValues returns all values of the enum

func (Side) IsASide

func (i Side) IsASide() bool

IsASide returns "true" if the value is listed in the enum definition. "false" otherwise

func (Side) MarshalJSON

func (i Side) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Side

func (Side) String

func (i Side) String() string

func (*Side) UnmarshalJSON

func (i *Side) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Side

type SpotPosition

type SpotPosition struct {
	Asset                string  `json:"asset"`
	AccountUUID          string  `json:"account_uuid"`
	TotalBalanceFiat     float64 `json:"total_balance_fiat"`
	TotalBalanceCrypto   float64 `json:"total_balance_crypto"`
	AvailableToTradeFiat float64 `json:"available_to_trade_fiat"`
	Allocation           float64 `json:"allocation"`
	OneDayChange         float64 `json:"one_day_change"`
	Cost_basis           Balance `json:"cost_basis"`
	AssetImgUrl          string  `json:"asset_img_url"`
	IsCash               bool    `json:"is_cash"`
}

type Stats

type Stats struct {
	Low         string `json:"low"`
	High        string `json:"high"`
	Open        string `json:"open"`
	Volume      string `json:"volume"`
	Last        string `json:"last"`
	Volume30Day string `json:"volume_30day"`
}

type Status

type Status byte
const (
	StatusUnknown Status = iota
	StatusPending
	StatusOpen
	StatusFilled
	StatusCancelled
	StatusExpired
	StatusFailed
	StatusQueued
	StatusCancelQueued
)

func StatusString

func StatusString(s string) (Status, error)

StatusString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func StatusValues

func StatusValues() []Status

StatusValues returns all values of the enum

func (Status) IsAStatus

func (i Status) IsAStatus() bool

IsAStatus returns "true" if the value is listed in the enum definition. "false" otherwise

func (Status) MarshalJSON

func (i Status) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Status

func (Status) String

func (i Status) String() string

func (*Status) UnmarshalJSON

func (i *Status) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Status

type StopDirection

type StopDirection byte
const (
	StopDirectionUnspecified StopDirection = iota
	StopDirectionStopUp                    // buy side
	StopDirectionStopDown                  // sell side
)

func StopDirectionString

func StopDirectionString(s string) (StopDirection, error)

StopDirectionString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func StopDirectionValues

func StopDirectionValues() []StopDirection

StopDirectionValues returns all values of the enum

func (StopDirection) IsAStopDirection

func (i StopDirection) IsAStopDirection() bool

IsAStopDirection returns "true" if the value is listed in the enum definition. "false" otherwise

func (StopDirection) MarshalJSON

func (i StopDirection) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for StopDirection

func (StopDirection) String

func (i StopDirection) String() string

func (*StopDirection) UnmarshalJSON

func (i *StopDirection) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for StopDirection

type StopLimitOrderGTC

type StopLimitOrderGTC struct {
	// The amount of the first Asset in the Trading Pair. For example, on the
	// BTC-USD Order Book, BTC is the Base Asset.
	BaseSize decimal.Decimal

	// The specified price, or better, that the Order should be executed at. A
	// Buy Order will execute at or lower than the limit price. A Sell Order
	// will execute at or higher than the limit price.
	LimitPrice decimal.Decimal
	Stop       decimal.Decimal

	// on which side should the limit trigger.
	// if you specify Buy then the stop is triggered once the stop EXCEEDS.
	// if you specify Sell then the stop is triggered once the stop FALLS BELOW
	// If you don't specify one, the payload to coinbase will not have one,
	// and will result in an error
	Side Side
}

func (*StopLimitOrderGTC) MarshalJSON

func (s *StopLimitOrderGTC) MarshalJSON() ([]byte, error)

func (*StopLimitOrderGTC) OrderType

func (s *StopLimitOrderGTC) OrderType() OrderType

func (*StopLimitOrderGTC) UnmarshalJSON

func (s *StopLimitOrderGTC) UnmarshalJSON(buf []byte) error

type StopLimitOrderGTD

type StopLimitOrderGTD struct {
	// The amount of the first Asset in the Trading Pair. For example, on the
	// BTC-USD Order Book, BTC is the Base Asset.
	BaseSize decimal.Decimal

	// The specified price, or better, that the Order should be executed at. A
	// Buy Order will execute at or lower than the limit price. A Sell Order
	// will execute at or higher than the limit price.
	LimitPrice decimal.Decimal
	Stop       decimal.Decimal
	EndTime    time.Time

	// on which side should the limit trigger.
	// if you specify Buy then the stop is triggered once the stop EXCEEDS.
	// if you specify Sell then the stop is triggered once the stop FALLS BELOW
	// If you don't specify one, the payload to coinbase will not have one,
	// and will result in an error
	Side Side
}

func (*StopLimitOrderGTD) MarshalJSON

func (s *StopLimitOrderGTD) MarshalJSON() ([]byte, error)

func (*StopLimitOrderGTD) OrderType

func (s *StopLimitOrderGTD) OrderType() OrderType

func (*StopLimitOrderGTD) UnmarshalJSON

func (s *StopLimitOrderGTD) UnmarshalJSON(buf []byte) error

type TIF

type TIF byte
const (
	TIFUnknown TIF = iota
	TIFGoodUntilDateTime
	TIFGoodUntilCancelled
	TIFImmediateOrCancel
	TIFFillOrKill
)

func TIFString

func TIFString(s string) (TIF, error)

TIFString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func TIFValues

func TIFValues() []TIF

TIFValues returns all values of the enum

func (TIF) IsATIF

func (i TIF) IsATIF() bool

IsATIF returns "true" if the value is listed in the enum definition. "false" otherwise

func (TIF) MarshalJSON

func (i TIF) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for TIF

func (TIF) String

func (i TIF) String() string

func (*TIF) UnmarshalJSON

func (i *TIF) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for TIF

type Ticker

type Ticker struct {
	TradeID int    `json:"trade_id"`
	Price   string `json:"price"`
	Size    string `json:"size"`
	Time    Time   `json:"time"`
	Bid     string `json:"bid"`
	Ask     string `json:"ask"`
	Volume  string `json:"volume"`
}

type Time

type Time time.Time

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON marshal time back to time.Time for json encoding

func (*Time) Scan

func (t *Time) Scan(value interface{}) error

Scan implements the sql.Scanner interface for database deserialization.

func (*Time) Time

func (t *Time) Time() time.Time

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database serialization.

type TotalBalances

type TotalBalances struct {
	TotalBalance      Balance `json:"total_balance"`
	Futures           Balance `json:"total_futures_balance"`
	CashEq            Balance `json:"total_cash_equivalent_balance"`
	Crypto            Balance `json:"total_crypto_balance"`
	FuturesUnrealized Balance `json:"futures_unrealized_pnl"`
	PerpUnrealized    Balance `json:"perp_unrealized_pnl"`
}

type Trade

type Trade struct {
	TradeID int    `json:"trade_id"`
	Price   string `json:"price"`
	Size    string `json:"size"`
	Time    Time   `json:"time"`
	Side    string `json:"side"`
}

type TriggerBracketOrderGTC

type TriggerBracketOrderGTC struct {
	// The amount of the first Asset in the Trading Pair. For example, on the
	// BTC-USD Order Book, BTC is the Base Asset.
	BaseSize decimal.Decimal `json:"base_size"`

	// The specified price, or better, that the Order should be executed at. A
	// Buy Order will execute at or lower than the limit price. A Sell Order
	// will execute at or higher than the limit price.
	LimitPrice decimal.Decimal `json:"limit_price"`

	// The price level (in quote currency) where the position will be exited.
	// When triggered, a stop limit order is automatically placed with a limit
	// price 5% higher for BUYS and 5% lower for SELLS.
	StopTriggerPrice decimal.Decimal `json:"stop_trigger_price"`
}

func (*TriggerBracketOrderGTC) MarshalJSON

func (t *TriggerBracketOrderGTC) MarshalJSON() ([]byte, error)

func (*TriggerBracketOrderGTC) OrderType

func (t *TriggerBracketOrderGTC) OrderType() OrderType

func (*TriggerBracketOrderGTC) UnmarshalJSON

func (t *TriggerBracketOrderGTC) UnmarshalJSON(b []byte) error

type TriggerBracketOrderGTD

type TriggerBracketOrderGTD struct {
	// The amount of the first Asset in the Trading Pair. For example, on the
	// BTC-USD Order Book, BTC is the Base Asset.
	BaseSize decimal.Decimal `json:"base_size"`

	// The specified price, or better, that the Order should be executed at. A
	// Buy Order will execute at or lower than the limit price. A Sell Order
	// will execute at or higher than the limit price.
	LimitPrice decimal.Decimal `json:"limit_price"`
	EndTime    time.Time       `json:"end_time"`

	// The price level (in quote currency) where the position will be exited.
	// When triggered, a stop limit order is automatically placed with a limit
	// price 5% higher for BUYS and 5% lower for SELLS.
	StopTriggerPrice decimal.Decimal `json:"stop_trigger_price"`
}

func (*TriggerBracketOrderGTD) MarshalJSON

func (t *TriggerBracketOrderGTD) MarshalJSON() ([]byte, error)

func (*TriggerBracketOrderGTD) OrderType

func (t *TriggerBracketOrderGTD) OrderType() OrderType

func (*TriggerBracketOrderGTD) UnmarshalJSON

func (t *TriggerBracketOrderGTD) UnmarshalJSON(b []byte) error

type TriggerStatus

type TriggerStatus byte
const (
	UnknownTriggerStatus TriggerStatus = iota
	TriggerStatusInvalidOrderType
	TriggerStatusStopPending
	TriggerStatusStopTriggered
)

func TriggerStatusString

func TriggerStatusString(s string) (TriggerStatus, error)

TriggerStatusString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func TriggerStatusValues

func TriggerStatusValues() []TriggerStatus

TriggerStatusValues returns all values of the enum

func (TriggerStatus) IsATriggerStatus

func (i TriggerStatus) IsATriggerStatus() bool

IsATriggerStatus returns "true" if the value is listed in the enum definition. "false" otherwise

func (TriggerStatus) MarshalJSON

func (i TriggerStatus) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for TriggerStatus

func (TriggerStatus) String

func (i TriggerStatus) String() string

func (*TriggerStatus) UnmarshalJSON

func (i *TriggerStatus) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for TriggerStatus

type UnmarshalErr

type UnmarshalErr struct {
	Err      error
	Buf      string
	RespCode int
}

func (*UnmarshalErr) Error

func (u *UnmarshalErr) Error() string

Jump to

Keyboard shortcuts

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