coinbasepro

package module
v3.0.7 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareProperties

func CompareProperties(a, b interface{}, properties []string) (bool, error)

func Ensure

func Ensure(a interface{}) error

func EnsureProperties

func EnsureProperties(a interface{}, properties []string) error

func NewTestWebsocketClient

func NewTestWebsocketClient() (*ws.Conn, error)

func StructHasZeroValues

func StructHasZeroValues(i interface{}) bool

Types

type Account

type Account struct {
	ID        string `json:"id"`
	Balance   string `json:"balance"`
	Hold      string `json:"hold"`
	Available string `json:"available"`
	Currency  string `json:"currency"`
}

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 CancelAllOrdersParams

type CancelAllOrdersParams struct {
	ProductID string
}

type Client

type Client struct {
	WsURL      string
	BaseURL    string
	Secret     string
	Key        string
	Passphrase string
	HTTPClient *http.Client
	RetryCount int
}

func NewClient

func NewClient() *Client

func NewTestClient

func NewTestClient() *Client

func (*Client) CancelAllOrders

func (c *Client) CancelAllOrders(ctx context.Context, p ...CancelAllOrdersParams) ([]string, error)

func (*Client) CancelOrder

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

func (*Client) CreateOrder

func (c *Client) CreateOrder(ctx context.Context, order *Order) (Order, error)

func (*Client) CreateReport

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

func (*Client) CreateTransfer

func (c *Client) CreateTransfer(ctx context.Context, transfer *Transfer) (Transfer, error)

func (*Client) CreateWithdrawalCoinbase

func (c *Client) CreateWithdrawalCoinbase(ctx context.Context, withdrawal *WithdrawalCoinbase) (WithdrawalCoinbase, error)

func (*Client) CreateWithdrawalCrypto

func (c *Client) CreateWithdrawalCrypto(ctx context.Context, withdrawal *WithdrawalCrypto) (WithdrawalCrypto, error)

func (*Client) GetAccount

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

func (*Client) GetAccounts

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

Client Funcs

func (*Client) GetBook

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

func (*Client) GetCurrencies

func (c *Client) GetCurrencies(ctx context.Context) ([]Currency, error)

func (*Client) GetFees added in v3.0.5

func (c *Client) GetFees(ctx context.Context) (Fee, 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 string) (Order, error)

func (*Client) GetProducts

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

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) Headers

func (c *Client) Headers(method, url, timestamp, data string) (map[string]string, error)

Headers generates a map that can be used as headers to authenticate a request

func (*Client) ListAccountLedger

func (c *Client) ListAccountLedger(ctx context.Context, id string, p ...GetAccountLedgerParams) *Cursor

func (*Client) ListFills

func (c *Client) ListFills(ctx context.Context, p ListFillsParams) *Cursor

func (*Client) ListHolds

func (c *Client) ListHolds(ctx context.Context, id string, p ...ListHoldsParams) *Cursor

func (*Client) ListOrders

func (c *Client) ListOrders(ctx context.Context, p ...ListOrdersParams) *Cursor

func (*Client) ListTrades

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

func (*Client) Request

func (c *Client) Request(
	ctx context.Context, method string, url string, params, result interface{}) (res *http.Response, err error)

func (*Client) Subscribe added in v3.0.4

func (c *Client) Subscribe(ctx context.Context, auth bool, msg *Message) (*websocket.Conn, error)

type ClientConfig

type ClientConfig struct {
	WsURL      string
	BaseURL    string
	Key        string
	Passphrase string
	Secret     string
}

type CreateReportParams

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

type Currency

type Currency struct {
	ID            string                 `json:"id"`
	Name          string                 `json:"name"`
	MinSize       string                 `json:"min_size"`
	Status        string                 `json:"status"`
	StatusMessage string                 `json:"status_message"`
	MaxPrecision  string                 `json:"max_precision"`
	ConvertibleTo []string               `json:"convertible_to"`
	Details       map[string]interface{} `json:"details"`
}

see https://docs.pro.coinbase.com/#the-status-channel for an enumeration of the available fields.

type Cursor

type Cursor struct {
	Client     *Client
	Pagination *PaginationParams
	Method     string
	Params     interface{}
	URL        string
	HasMore    bool
	// contains filtered or unexported fields
}

func NewCursor

func NewCursor(ctx context.Context, client *Client, method, url string, paginationParams *PaginationParams) *Cursor

func (*Cursor) NextPage

func (c *Cursor) NextPage(i interface{}) error

func (*Cursor) Page

func (c *Cursor) Page(i interface{}, direction string) error

func (*Cursor) PrevPage

func (c *Cursor) PrevPage(i interface{}) error

type Error

type Error struct {
	StatusCode int    `json:"-"`
	Message    string `json:"message"`
}

func (Error) Error

func (e Error) Error() string

type Fee added in v3.0.5

type Fee struct {
	MakerFeeRate string `json:"maker_fee_rate"`
	TakerFeeRate string `json:"taker_fee_rate"`
	USDVolume    string `json:"usd_volume"`
}

type Fill

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

type GetAccountLedgerParams

type GetAccountLedgerParams struct {
	Pagination PaginationParams
}

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 Hold

type Hold struct {
	AccountID string `json:"account_id"`
	CreatedAt Time   `json:"created_at,string"`
	UpdatedAt Time   `json:"updated_at,string"`
	Amount    string `json:"amount"`
	Type      string `json:"type"`
	Ref       string `json:"ref"`
}

type LedgerDetails

type LedgerDetails struct {
	OrderID   string `json:"order_id"`
	TradeID   string `json:"trade_id"`
	ProductID string `json:"product_id"`
}

type LedgerEntry

type LedgerEntry struct {
	ID        int           `json:"id,number"`
	CreatedAt Time          `json:"created_at,string"`
	Amount    string        `json:"amount"`
	Balance   string        `json:"balance"`
	Type      string        `json:"type"`
	Details   LedgerDetails `json:"details"`
}

type ListFillsParams

type ListFillsParams struct {
	OrderID    string
	ProductID  string
	Pagination PaginationParams
}

type ListHoldsParams

type ListHoldsParams struct {
	Pagination PaginationParams
}

type ListOrdersParams

type ListOrdersParams struct {
	Status     string
	ProductID  string
	Pagination PaginationParams
}

type ListTradesParams

type ListTradesParams struct {
	Pagination PaginationParams
}

type Message

type Message struct {
	Type          string           `json:"type"`
	ProductID     string           `json:"product_id"`
	ProductIds    []string         `json:"product_ids"`
	TradeID       int              `json:"trade_id,number"`
	OrderID       string           `json:"order_id"`
	ClientOID     string           `json:"client_oid"`
	Sequence      int64            `json:"sequence,number"`
	MakerOrderID  string           `json:"maker_order_id"`
	TakerOrderID  string           `json:"taker_order_id"`
	Time          Time             `json:"time,string"`
	RemainingSize string           `json:"remaining_size"`
	NewSize       string           `json:"new_size"`
	OldSize       string           `json:"old_size"`
	Size          string           `json:"size"`
	Price         string           `json:"price"`
	Side          string           `json:"side"`
	Reason        string           `json:"reason"`
	OrderType     string           `json:"order_type"`
	Funds         string           `json:"funds"`
	NewFunds      string           `json:"new_funds"`
	OldFunds      string           `json:"old_funds"`
	Message       string           `json:"message"`
	Bids          []SnapshotEntry  `json:"bids,omitempty"`
	Asks          []SnapshotEntry  `json:"asks,omitempty"`
	Changes       []SnapshotChange `json:"changes,omitempty"`
	LastSize      string           `json:"last_size"`
	BestBid       string           `json:"best_bid"`
	BestAsk       string           `json:"best_ask"`
	Channels      []MessageChannel `json:"channels"`
	UserID        string           `json:"user_id"`
	ProfileID     string           `json:"profile_id"`
	LastTradeID   int              `json:"last_trade_id"`
}

type MessageChannel

type MessageChannel struct {
	Name       string   `json:"name"`
	ProductIds []string `json:"product_ids"`
}

type Order

type Order struct {
	Type      string `json:"type"`
	Size      string `json:"size,omitempty"`
	Side      string `json:"side"`
	ProductID string `json:"product_id"`
	ClientOID string `json:"client_oid,omitempty"`
	Stp       string `json:"stp,omitempty"`
	Stop      string `json:"stop,omitempty"`
	StopPrice string `json:"stop_price,omitempty"`
	// Limit Order
	Price       string `json:"price,omitempty"`
	TimeInForce string `json:"time_in_force,omitempty"`
	PostOnly    bool   `json:"post_only,omitempty"`
	CancelAfter string `json:"cancel_after,omitempty"`
	// Market Order
	Funds string `json:"funds,omitempty"`
	// Response Fields
	ID            string `json:"id"`
	Status        string `json:"status,omitempty"`
	Settled       bool   `json:"settled,omitempty"`
	DoneReason    string `json:"done_reason,omitempty"`
	CreatedAt     Time   `json:"created_at,string,omitempty"`
	FillFees      string `json:"fill_fees,omitempty"`
	FilledSize    string `json:"filled_size,omitempty"`
	ExecutedValue string `json:"executed_value,omitempty"`
}

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 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"`
	BaseIncrement  string `json:"base_increment"`
	QuoteIncrement string `json:"quote_increment"`
	DisplayName    string `json:"display_name"`
	Status         string `json:"status"`
	StatusMessage  string `json:"status_message"`
	MinMarketFunds string `json:"min_market_funds"`
	MaxMarketFunds string `json:"max_market_funds"`
	PostOnly       bool   `json:"post_only"`
	LimitOnly      bool   `json:"limit_only"`
	CancelOnly     bool   `json:"cancel_only"`
}

see https://docs.pro.coinbase.com/#the-status-channel for an enumeration of the available fields.

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,number"`
}

type SnapshotChange

type SnapshotChange struct {
	Side  string
	Price string
	Size  string
}

func (*SnapshotChange) UnmarshalJSON

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

type SnapshotEntry

type SnapshotEntry struct {
	Price string
	Size  string
}

func (*SnapshotEntry) UnmarshalJSON

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

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 StringNumber

type StringNumber string

func (*StringNumber) UnmarshalJSON

func (s *StringNumber) UnmarshalJSON(data []byte) error

type Ticker

type Ticker struct {
	TradeID int          `json:"trade_id,number"`
	Price   string       `json:"price"`
	Size    string       `json:"size"`
	Time    Time         `json:"time,string"`
	Bid     string       `json:"bid"`
	Ask     string       `json:"ask"`
	Volume  StringNumber `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) Time

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

func (*Time) UnmarshalJSON

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

type Trade

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

type Transfer

type Transfer struct {
	Type              string `json:"type"`
	Amount            string `json:"amount"`
	CoinbaseAccountID string `json:"coinbase_account_id,string"`
}

type WithdrawalCoinbase

type WithdrawalCoinbase struct {
	Currency          string `json:"currency"`
	Amount            string `json:"amount"`
	CoinbaseAccountID string `json:"coinbase_account_id"`
}

type WithdrawalCrypto

type WithdrawalCrypto struct {
	Currency      string `json:"currency"`
	Amount        string `json:"amount"`
	CryptoAddress string `json:"crypto_address"`
}

Jump to

Keyboard shortcuts

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