coinbasego

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 15 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 (
	TimeInForceGoodTillCanceled = "GTC"
	TimeInForceGoodTillTime     = "GTT"
)
View Source
const (
	CancelAfterMin  = "min"
	CancelAFterHour = "hour"
	CancelAfterDay  = "day"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID             string  `json:"id" binding:"required"`
	Currency       string  `json:"currency" binding:"required"`
	Balance        float64 `json:"balance,string" binding:"required"`
	Available      float64 `json:"available,string" binding:"required"`
	Hold           string  `json:"hold" binding:"required"`
	ProfileId      string  `json:"profile_id" binding:"required"`
	TradingEnabled bool    `json:"trading_enabled" binding:"required"`
}

type AccountsParams

type AccountsParams struct {
	PaginationParams
}

type CancelAfter

type CancelAfter string

type Candle

type Candle struct {
	Timestamp  int     `json:"timestamp"`
	PriceLow   float64 `json:"price_low"`
	PriceHigh  float64 `json:"price_high"`
	PriceOpen  float64 `json:"price_open"`
	PriceClose float64 `json:"price_close"`
}

func (*Candle) UnmarshalJSON

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

type CandlesParams

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

type Channel

type Channel struct {
	Name       string   `json:"name" binding:"required"`
	ProductIDs []string `json:"product_ids" binding:"required"`
}

type Client

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

func NewClient

func NewClient(credentials ClientCredentials) *Client

func (*Client) Account

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

func (*Client) Accounts

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

func (*Client) Candles

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

func (*Client) Currencies

func (client *Client) Currencies() ([]Currency, error)

func (*Client) Currency

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

func (*Client) Fills

func (client *Client) Fills() ([]Fill, error)

func (*Client) Ledger

func (client *Client) Ledger(p LedgerParams) ([]Ledger, *PaginationResponse, error)

func (*Client) Order

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

func (*Client) OrderCreate

func (client *Client) OrderCreate(body OrderCreateBody) (*Order, error)

func (*Client) Orders

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

func (*Client) Product

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

func (*Client) Products

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

func (*Client) Profiles

func (client *Client) Profiles() ([]Profile, error)

func (*Client) Transfers

func (client *Client) Transfers(accountID string, p TransfersParams) ([]Transfer, *PaginationResponse, error)

func (*Client) WebSocketCreate

func (client *Client) WebSocketCreate(channels []Channel, wsh WebSockerHandler) *WebSocket

type ClientCredentials

type ClientCredentials struct {
	ApiKey     string
	SecretKey  string
	Passphrase string
}

type Currency

type Currency struct {
	ID            string   `json:"id" binding:"required"`
	Name          string   `json:"name" binding:"required"`
	MinSize       float64  `json:"min_size,string" binding:"required"`
	Status        string   `json:"status" binding:"required"`
	Message       string   `json:"message"`
	MaxPrecision  float64  `json:"max_precision,string" binding:"required"`
	ConvertibleTo []string `json:"convertible_to"`
}

func (*Currency) FixSize

func (c *Currency) FixSize(size float64) float64

type Fill

type Fill struct {
	TradeID   string `json:"trade_id" binding:"required"`
	ProductID string `json:"product_id" binding:"required"`
	OrderID   string `json:"order_id" binding:"required"`
	UserID    string `json:"user_id" binding:"required"`
	ProfileID string `json:"profile_id" binding:"required"`
	Liquidity string `json:"liquidity" binding:"required"`
}

type Granularity

type Granularity int
var (
	GranularityMinute         Granularity = 60
	GranularityFiveMinutes    Granularity = 300
	GranularityFifteenMinutes Granularity = 900
	GranularityHour           Granularity = 3600
	GranularitySixHours       Granularity = 21600
	GranularityDay            Granularity = 86400
)

type Ledger

type Ledger struct {
	ID        string                 `url:"id"`
	Amount    string                 `url:"amount"`
	CreatedAt time.Time              `url:"created_at"`
	Balance   string                 `url:"balance"`
	Type      string                 `url:"type"`
	Details   map[string]interface{} `url:"details"`
}

type LedgerParams

type LedgerParams struct {
	PaginationParams
	ProductID ProductID `url:"product_id,omitempty"`
	StartDate time.Time `url:"start_date,omitempty"`
	EndDate   time.Time `url:"end_date,omitempty"`
	ProfileID string    `url:"profile_id"`
	AccountID string
}

type Order

type Order struct {
	ID             string      `json:"id" binding:"required"`
	Price          string      `json:"price"`
	Size           string      `json:"size"`
	ProductID      ProductID   `json:"product_id" binding:"required"`
	ProfileID      string      `json:"profile_id"`
	Side           OrderSide   `json:"side" binding:"required"`
	Funds          string      `json:"funds"`
	SpecifiedFunds string      `json:"specified_funds"`
	Type           OrderType   `json:"type" binding:"required"`
	TimeInForce    string      `json:"time_in_force"`
	ExpireTime     string      `json:"expire_time"`
	PostOnly       bool        `json:"post_only" binding:"required"`
	CreatedAt      string      `json:"created_at" binding:"required"`
	DoneAt         string      `json:"done_at"`
	DoneReason     string      `json:"done_reason"`
	RejectReason   string      `json:"reject_reason"`
	FillFees       string      `json:"fill_fees" binding:"required"`
	FilledSize     string      `json:"filled_size" binding:"required"`
	ExecutedValue  string      `json:"executed_value"`
	Status         OrderStatus `json:"status" binding:"required"`
	Settled        bool        `json:"settled" binding:"required"`
	Stop           string      `json:"stop"`
	StopPrice      string      `json:"stop_price"`
	FundingAmount  string      `json:"funding_amount"`
	ClientOID      string      `json:"client_oid"`
}

type OrderCreateBody

type OrderCreateBody struct {
	ProfileID   string      `json:"profile_id,omitempty"`
	Type        OrderType   `json:"type,omitempty"`
	Side        OrderSide   `json:"side" binding:"required"`
	ProductID   ProductID   `json:"product_id" binding:"required"`
	STP         string      `json:"stp,omitempty"`
	Stop        string      `json:"stop,omitempty"`
	StopPrice   string      `json:"stop_price,omitempty"`
	Price       string      `json:"price,omitempty"`
	Size        string      `json:"size,omitempty"`
	Funds       string      `json:"funds,omitempty"`
	TimeInForce TimeInForce `json:"time_in_force,omitempty"`
	CancelAfter CancelAfter `json:"cancel_after,omitempty"`
	PostOnly    bool        `json:"post_only,omitempty"`
	ClientOID   string      `json:"client_oid,omitempty"`
}

type OrderSide

type OrderSide string
const (
	OrderSideBuy  OrderSide = "buy"
	OrderSideSell OrderSide = "sell"
)

type OrderStatus

type OrderStatus string
const (
	OrderStatusOpen     OrderStatus = "open"
	OrderStatusPending  OrderStatus = "pending"
	OrderStatusRejected OrderStatus = "rejected"
	OrderStatusDone     OrderStatus = "done"
	OrderStatusActive   OrderStatus = "active"
	OrderStatusReceived OrderStatus = "received"
	OrderStatusAll      OrderStatus = "all"
)

type OrderType

type OrderType string
const (
	OrderTypeLimit  OrderType = "limit"
	OrderTypeMarket OrderType = "market"
	OrderTypeStop   OrderType = "stop"
)

type OrdersParams

type OrdersParams struct {
	PaginationParams
	ProfileID string        `url:"profile_id,omitempty"`
	ProductID ProductID     `url:"product_id,omitempty"`
	SortedBy  string        `url:"sortedBy,omitempty"`
	Sorting   Sorting       `url:"sorting,omitempty"`
	StartDate time.Time     `url:"start_date,omitempty"`
	EndDate   time.Time     `url:"end_date,omitempty"`
	Status    []OrderStatus `url:"status" binding:"required"`
}

type PaginationParams

type PaginationParams struct {
	Before string `url:"before,omitempty"`
	After  string `url:"after,omitempty"`
	Limit  int    `url:"limit" binding:"required"`
}

type PaginationResponse

type PaginationResponse struct {
	Before string
	After  string
}

type Product

type Product struct {
	ID              ProductID `json:"id" binding:"required"`
	QuoteCurrency   string    `json:"quote_currency" binding:"required"`
	QuoteIncrement  float64   `json:"quote_increment,string" binding:"required"`
	BaseIncrement   float64   `json:"base_increment,string" binding:"required"`
	DisplayName     string    `json:"display_name" binding:"required"`
	PostOnly        bool      `json:"post_only" binding:"required"`
	LimitOnly       bool      `json:"limit_only" binding:"required"`
	CancelOnly      bool      `json:"cancel_only" binding:"required"`
	Status          string    `json:"status" binding:"required"`
	StatusMessage   string    `json:"status_message" binding:"required"`
	TradingDisabled bool      `json:"trading_disabled"`
}

func (*Product) FixPrice

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

type ProductID

type ProductID string

type ProductsParams

type ProductsParams struct {
	PaginationParams
}

type Profile

type Profile struct {
	ID        string    `json:"id" binding:"required"`
	UserID    string    `json:"user_id" binding:"required"`
	Name      string    `json:"name" binding:"required"`
	Active    bool      `json:"active" binding:"required"`
	IsDefault bool      `json:"is_default" binding:"required"`
	HasMargin bool      `json:"has_margin" binding:"required"`
	CreatedAt time.Time `json:"creatd_at" binding:"required"`
}

type Request

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

type Sorting

type Sorting string
const (
	SortingAsc  Sorting = "asc"
	SortingDesc Sorting = "desc"
)

type SubscribeRequest

type SubscribeRequest struct {
	Type       string    `json:"type" binding:"required"`
	Channels   []Channel `json:"channels" binding:"required"`
	Signature  string    `json:"signature"`
	Key        string    `json:"key"`
	Passphrase string    `json:"passphrase"`
	Timestamp  string    `json:"timestamp"`
}

type TickerMessage

type TickerMessage struct {
	WebsocketResponse
	// Sequence  int                `json:"sequence"`
	ProductID ProductID `json:"product_id"`
	Price     float64   `json:"price,string"`
	Open24H   float64   `json:"open_24h,string"`
	Volume24H float64   `json:"volume_24h,string"`
	Low24H    float64   `json:"low_24h,string"`
	High24H   float64   `json:"high_24h,string"`
	Volume30D float64   `json:"volume_30d,string"`
	BestBid   string    `json:"best_bid"`
	BestAsk   string    `json:"best_ask"`
	Side      string    `json:"side"`
	Time      time.Time `json:"time"`
	TradeID   int       `json:"trade_id"`
	LastSize  float64   `json:"last_size,string"`
}

type TimeInForce

type TimeInForce string

type Transfer

type Transfer struct {
	ID          string                 `url:"id"`
	Type        string                 `url:"type"`
	CreatedAt   time.Time              `url:"created_at"`
	CompletedAt time.Time              `url:"completed_at"`
	CanceledAt  time.Time              `url:"canceled_at"`
	ProcessedAt time.Time              `url:"processed_at"`
	Amount      string                 `url:"amount"`
	UserNonce   string                 `url:"user_nonce"`
	Details     map[string]interface{} `url:"details"`
}

type TransfersParams

type TransfersParams struct {
	PaginationParams
	Type string `url:"type,omitempty"`
}

type WebSockerHandler

type WebSockerHandler interface {
	ReceiveHandler(conn *websocket.Conn)
}

type WebSocket

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

func (*WebSocket) Close

func (ws *WebSocket) Close() error

Close the websocket connection

type WebsocketResponse

type WebsocketResponse struct {
	Type          string `json:"type"`
	Message       string `json:"message"`
	OrderID       string `json:"order_id"`
	OrderType     string `json:"order_type"`
	Size          string `json:"size"`
	RemainingSize string `json:"remaining_size"`
	Price         string `json:"price"`
	ClientOID     string `json:"client_oid"`
	Side          string `json:"side"`
	ProductID     string `json:"product_id"`
	Time          string `json:"time"`
	// Sequence      int  `json:"sequence"`
	ProfileID string `json:"profile_id"`
	UserID    string `json:"user_id"`
	Reason    string `json:"reason"`
}

Jump to

Keyboard shortcuts

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