client

package
v0.2.3-beta Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	CoinbaseAdvV3endpoint = "https://api.coinbase.com/api/v3"
	CoinbaseAdvV2endpoint = "https://api.coinbase.com/v2"
	DefaultAPIRateLimit   = 100 // (ms) throttled below
)
View Source
const (
	DefaultLimit = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func (*Client) AddSessionHeader

func (c *Client) AddSessionHeader(k string, v string)

func (*Client) CancelOrders

func (c *Client) CancelOrders(ctx context.Context, ids []string) (*model.CancelOrderResponse, error)

CancelOrders -- cancel orders

func (*Client) CheckAuthentication

func (c *Client) CheckAuthentication(req *http.Request, body []byte)

func (*Client) CreateOrder

CreateOrder -- create order

func (*Client) DoAndDecode

func (c *Client) DoAndDecode(req *http.Request, dest interface{}) (err error)

DoAndDecode provides useful abstractions around common errors and decoding issues. Ideally unmarshals into `dest`. On error, it'll use the Webull `ErrorBody` model. Last fallback is a plain interface.

func (*Client) GetAccount

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

GetAccount -- get account details

func (*Client) GetAndDecode

func (c *Client) GetAndDecode(ctx context.Context, URL url.URL, dest interface{}, headers *map[string]string, urlValues *map[string]string) error

GetAndDecode retrieves from the endpoint and unmarshals resulting json into the provided destination interface, which must be a pointer.

func (*Client) GetExchangeRate

func (c *Client) GetExchangeRate(ctx context.Context, currency string) (*model.GetExchangeRateResponseData, error)

GetExchangeRate -- get exchange rate

func (*Client) GetOrder

func (c *Client) GetOrder(ctx context.Context, id string) (*model.GetOrderResponse, error)

GetOrder -- get order

func (*Client) GetPrice

func (c *Client) GetPrice(ctx context.Context, currency string, side string) (*float64, error)

GetPrice -- get price

func (*Client) GetProduct

func (c *Client) GetProduct(ctx context.Context, productId string) (*model.GetProductResponse, error)

GetProduct -- get product

func (*Client) GetQuote

func (c *Client) GetQuote(ctx context.Context, currency string) (*Quote, error)

GetQuote -- get both sides of price

func (*Client) HttpClient

func (c *Client) HttpClient() *http.Client

func (*Client) IsTokenValid

func (c *Client) IsTokenValid(_ int64) bool

func (*Client) ListAccounts

ListAccounts -- list user's accounts

func (*Client) ListFills

ListFills -- list fills

func (*Client) ListOrders

ListOrders -- list orders

func (*Client) PostAndDecode

func (c *Client) PostAndDecode(ctx context.Context, URL url.URL, dest interface{}, headers *map[string]string, urlValues *map[string]string, payload []byte) error

PostAndDecode retrieves from the endpoint and unmarshals resulting json into the provided destination interface, which must be a pointer.

func (*Client) SetRateLimit

func (c *Client) SetRateLimit(ms int64)

Rate limit the client since Coinbase only allows API calls / second. Default is 100ms - DefaultAPIRateLimit

type CoinbaseClient

type CoinbaseClient interface {

	// coinbase adv api funcs
	ListAccounts(ctx context.Context, p *ListAccountsParams) (*model.ListAccountsResponse, error)
	GetAccount(ctx context.Context, uuid string) (*model.Account, error)
	ListFills(ctx context.Context, p *ListFillsParams) (*model.ListFillsResponse, error)
	GetOrder(ctx context.Context, id string) (*model.GetOrderResponse, error)
	CancelOrders(ctx context.Context, ids []string) (*model.CancelOrderResponse, error)
	CreateOrder(ctx context.Context, p *model.CreateOrderRequest) (*model.CreateOrderResponse, error)
	ListOrders(ctx context.Context, p *ListOrdersParams) (*model.ListOrdersResponse, error)
	GetPrice(ctx context.Context, currency string, side string) (*float64, error)
	GetQuote(ctx context.Context, currency string) (*Quote, error)
	GetExchangeRate(ctx context.Context, currency string) (*model.GetExchangeRateResponseData, error)
	GetProduct(ctx context.Context, productId string) (*model.GetProductResponse, error)

	// utility funcs
	CheckAuthentication(req *http.Request, body []byte)
	HttpClient() *http.Client
	IsTokenValid(timestamp int64) bool
	SetRateLimit(ms int64)
}

func NewClient

func NewClient(creds *Credentials) (cb CoinbaseClient)

type Credentials

type Credentials struct {
	AccessToken string // Bearer token, either a 'test' development key, or one obtained via OAuth2

	ApiKey  string
	ApiSKey string
}

type GetAccountResponse

type GetAccountResponse struct {
	Account model.Account
}

type ListAccountsParams

type ListAccountsParams struct {
	Limit  *int32
	Cursor *string
}

type ListFillsParams

type ListFillsParams struct {
	OrderId                string
	ProductId              string
	Limit                  int32
	StartSequenceTimestamp time.Time
	EndSequenceTimestamp   time.Time

	Cursor *string
}

type ListOrdersParams

type ListOrdersParams struct {
	ProductId          string
	OrderStatus        []string
	Limit              int32
	StartDate          time.Time
	EndDate            time.Time
	UserNativeCurrency string
	OrderType          model.OrderType
	OrderSide          model.OrderSide
	ProductType        model.ProductType

	Cursor *string
}

type Quote

type Quote struct {
	Buy  float64
	Sell float64
}

Jump to

Keyboard shortcuts

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