coinbase_adv_go

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CoinbaseAdvancesValidGranularity = map[string]bool{
	"UNKNOWN_GRANULARITY": true,
	"ONE_MINUTE":          true,
	"FIVE_MINUTE":         true,
	"FIFTEEN_MINUTE":      true,
	"THIRTY_MINUTE":       true,
	"ONE_HOUR":            true,
	"TWO_HOUR":            true,
	"FOUR_HOUR":           false,
	"SIX_HOUR":            true,
	"TWELVE_HOUR":         false,
	"ONE_DAY":             true,
	"ONE_WEEK":            false,
	"ONE_MONTH":           false,
}
View Source
var Granularity = map[string]time.Duration{
	"UNKNOWN_GRANULARITY": 0 * time.Minute,
	"ONE_MINUTE":          1 * time.Minute,
	"FIVE_MINUTE":         5 * time.Minute,
	"FIFTEEN_MINUTE":      15 * time.Minute,
	"THIRTY_MINUTE":       30 * time.Minute,
	"ONE_HOUR":            60 * time.Minute,
	"TWO_HOUR":            120 * time.Minute,
	"FOUR_HOUR":           240 * time.Minute,
	"SIX_HOUR":            360 * time.Minute,
	"TWELVE_HOUR":         720 * time.Minute,
	"ONE_DAY":             1440 * time.Minute,
	"ONE_WEEK":            10080 * time.Minute,
	"ONE_MONTH":           43200 * time.Minute,
}

Functions

func Dispatcher

func Dispatcher(ws *WebSocketConnection)

TODO: Rewrite the dispatcher to allow multiple subscriptions to the same go channel.

This will require a change to the Channel struct to allow multiple output channels.
Also allow certain channels to be filtered from the output channel. (ie. heartbeat)

Dispatcher reads messages from the websocket connection and sends them to the appropriate output channels. The function runs in a separate goroutine and returns when the shutdown channel is closed. The output channels are NOT closed when the function returns. The messages are filtered by websocket channel and sent to the appropriate output channels. Multiple dispatchers may not be registered to the same output channel. (not enforced, caller beware) Parameters:

ws - a pointer to a WebSocketConnection object representing the websocket connection

Types

type Account

type Account struct {
	UUID             string `json:"uuid"`     // Unique identifier for the account
	Name             string `json:"name"`     // User-defined name for the account
	Currency         string `json:"currency"` // Currency of the account
	AvailableBalance struct {
		Value    string `json:"value"`    // Available balance in the account
		Currency string `json:"currency"` // Currency of the account
	} `json:"available_balance"`
	Default   bool      `json:"default"`    // True if this is the default account for the currency
	Active    bool      `json:"active"`     // True if the account is active
	CreatedAt time.Time `json:"created_at"` // Timestamp indicating when the account was created
	UpdatedAt time.Time `json:"updated_at"` // Timestamp indicating when the account was last updated
	DeletedAt time.Time `json:"deleted_at"` // Timestamp indicating when the account was deleted
	Type      string    `json:"type"`       // Type of the account
	Ready     bool      `json:"ready"`      // True if the account is ready to transact
	Hold      struct {
		Value    string `json:"value"`    // Amount of funds held in the account
		Currency string `json:"currency"` // Currency of the account
	} `json:"hold"` // Amount of funds held in the account
}

type AccountsList

type AccountsList struct {
	Accounts []Account `json:"accounts"`
	HasNext  bool      `json:"has_next"`
	Cursor   string    `json:"cursor"`
	Size     int       `json:"size"`
}

type Balance

type Balance struct {
	Currency  string  `json:"currency"`
	Available float64 `json:"available"`
	Reserved  float64 `json:"reserved"`
}

type CandleList

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

type Candles

type Candles struct {
	Start  string `json:"start"`
	Low    string `json:"low"`
	High   string `json:"high"`
	Open   string `json:"open"`
	Close  string `json:"close"`
	Volume string `json:"volume"`
}

type Channel

type Channel struct {
	ChannelName string // the name of the websocket channel

	Outputs map[chan<- string]chan<- string // the output go channels for this websocket channel
	// contains filtered or unexported fields
}

Channel represents a channel subscription for an application routine.

type ChannelMap added in v0.0.3

type ChannelMap[K comparable, V comparable] struct {
	// contains filtered or unexported fields
}

ChannelMap is a generic map-like structure with duplicate keys. It associates multiple values with each key and allows concurrent access.

func NewChannelMap added in v0.0.3

func NewChannelMap[K comparable, V comparable]() *ChannelMap[K, V]

NewChannelMap creates a new instance of ChannelMap with the specified data types for keys and values.

func (*ChannelMap[K, V]) Add added in v0.0.3

func (cm *ChannelMap[K, V]) Add(key K, values ...V)

func (*ChannelMap[K, V]) GetKeysForValue added in v0.0.3

func (cm *ChannelMap[K, V]) GetKeysForValue(value V) []K

func (*ChannelMap[K, V]) GetValuesForKey added in v0.0.3

func (cm *ChannelMap[K, V]) GetValuesForKey(key K) []V

func (*ChannelMap[K, V]) Remove added in v0.0.3

func (cm *ChannelMap[K, V]) Remove(key K, values ...V) (isEmpty bool)

type ChannelParams

type ChannelParams struct {
	ChannelName string        // the name of the websocket channel
	Output      chan<- string // the output go channel for this websocket channel
}

ChannelParams represents the parameters for a websocket channel subscription.

type CoinbaseAdvanced

type CoinbaseAdvanced struct {
	Name        string
	Description string
	// contains filtered or unexported fields
}

func NewCoinbaseAdvanced

func NewCoinbaseAdvanced(key, secret string) *CoinbaseAdvanced

func (*CoinbaseAdvanced) CancelOrders

func (c *CoinbaseAdvanced) CancelOrders(ctx context.Context, order_ids []string) (interface{}, error)

Not fully implemented

func (*CoinbaseAdvanced) CreateOrder

func (c *CoinbaseAdvanced) CreateOrder(ctx context.Context, params *CreateOrderParams) (interface{}, error)

Not fully implemented

func (*CoinbaseAdvanced) GetAccount

func (c *CoinbaseAdvanced) GetAccount(ctx context.Context, params *GetAccountParams) (Account, error)

func (*CoinbaseAdvanced) GetMarketTrades

func (c *CoinbaseAdvanced) GetMarketTrades(ctx context.Context, params *GetMarketTradesParams) (MarketTradeList, error)

func (*CoinbaseAdvanced) GetOrder

func (c *CoinbaseAdvanced) GetOrder(ctx context.Context, order_id string) (Order, error)

func (*CoinbaseAdvanced) GetProduct

func (c *CoinbaseAdvanced) GetProduct(ctx context.Context, product_id string) (interface{}, error)

func (*CoinbaseAdvanced) GetProductCandles

func (c *CoinbaseAdvanced) GetProductCandles(ctx context.Context, params *GetProductCandlesParams) (CandleList, error)

func (*CoinbaseAdvanced) GetTransactionsSummary

func (c *CoinbaseAdvanced) GetTransactionsSummary(ctx context.Context, params *GetTransactionsSummaryParams) (TransactionsSummary, error)

func (*CoinbaseAdvanced) ListAccounts

func (c *CoinbaseAdvanced) ListAccounts(ctx context.Context) (AccountsList, error)

func (*CoinbaseAdvanced) ListFills

func (c *CoinbaseAdvanced) ListFills(ctx context.Context, params *ListFillsParams) (FillList, error)

func (*CoinbaseAdvanced) ListOrders

func (c *CoinbaseAdvanced) ListOrders(ctx context.Context, params *ListOrdersParams) (OrderList, error)

Iterate through all orders if HasNext is true

func (*CoinbaseAdvanced) ListProducts

func (c *CoinbaseAdvanced) ListProducts(ctx context.Context, params *ListProductsParams) (ProductList, error)

func (*CoinbaseAdvanced) Subscribe

func (c *CoinbaseAdvanced) Subscribe(ctx context.Context, sub *ChannelParams, productIDs ...string) (webSocket *WebSocketConnection, err error)

func (*CoinbaseAdvanced) Unsubscribe

func (c *CoinbaseAdvanced) Unsubscribe(ctx context.Context, wsConnection *WebSocketConnection, sub *ChannelParams) error

type CreateOrderParams

type CreateOrderParams struct {
	ClientOrderId      string             `param:"client_order_id,required"`
	ProductId          string             `param:"product_id,required"`
	Side               string             `param:"side,required"`
	OrderConfiguration OrderConfiguration `param:"order_configuration,required"`
}

type FeeTier

type FeeTier struct {
	Pricing_tier   string `json:"pricing_tier"`
	Usd_from       string `json:"usd_from"`
	Usd_to         string `json:"usd_to"`
	Taker_fee_rate string `json:"taker_fee_rate"`
	Maker_fee_rate string `json:"maker_fee_rate"`
}

type Fill

type Fill struct {
	Entry_id            string    `json:"entry_id"`
	Trade_id            string    `json:"trade_id"`
	Order_id            string    `json:"order_id"`
	Trade_time          time.Time `json:"trade_time"`
	Trade_type          string    `json:"trade_type"`
	Price               string    `json:"price"`
	Size                string    `json:"size"`
	Commission          string    `json:"commission"`
	Product_id          string    `json:"product_id"`
	Sequence_timestamp  time.Time `json:"sequence_timestamp"`
	Liquidity_indicator string    `json:"liquidity_indicator"`
	Size_in_quote       bool      `json:"size_in_quote"`
	User_id             string    `json:"user_id"`
	Side                string    `json:"side"`
}

type FillList

type FillList struct {
	Fills  []Fill `json:"fills"`
	Cursor string `json:"cursor"`
}

type FillLister

type FillLister interface {
	GetFills() []Fill
	GetCursor() string
}

type GetAccountParams

type GetAccountParams struct {
	AccountID string `param:"account_id,-"`
}

type GetAccountResponse

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

type GetMarketTradesParams

type GetMarketTradesParams struct {
	Product_id string `param:"product_id,-"`
	Limit      int    `param:"limit,required,100"`
}

type GetOrderResponse

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

type GetProductCandlesParams

type GetProductCandlesParams struct {
	Product_id  string `param:"product_id,-"`
	Start       string `param:"start"`
	End         string `param:"end"`
	Granularity string `param:"granularity"`
}

type GetTransactionsSummaryParams

type GetTransactionsSummaryParams struct {
	StartDate          time.Time `param:"start_date,required"`
	EndDate            time.Time `param:"end_date,required"`
	UserNativeCurrency string    `param:"user_native_Currency,,USD"`
	ProductType        string    `param:"product_type,required,SPOT"`
}

type GoodsAndServicesTax

type GoodsAndServicesTax struct {
	Rate string `json:"rate"`
	Type string `json:"type"`
}

type LimitLimitGTC

type LimitLimitGTC struct {
	BaseSize   string `json:"base_size" param:"base_size"`
	LimitPrice string `json:"limit_price" param:"limit_price"`
	PostOnly   bool   `json:"post_only" param:"post_only"`
}

type LimitLimitGTD

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

type Limit_limit_gtc

type Limit_limit_gtc struct {
	BaseSize   string `json:"base_size"`
	LimitPrice string `json:"limit_price"`
	PostOnly   bool   `json:"post_only"`
}

type Limit_limit_gtd

type Limit_limit_gtd struct {
	BaseSize   string    `json:"base_size"`
	LimitPrice string    `json:"limit_price"`
	EndTime    time.Time `json:"end_time"`
	PostOnly   bool      `json:"post_only"`
}

type ListAccountParams

type ListAccountParams struct {
	Limit  int32  `param:"limit"`
	Cursor string `param:"cursor"`
}

type ListFillsParams

type ListFillsParams struct {
	OrderID                string    `param:"order_id"`
	ProductID              string    `param:"product_id"`
	StartSequenceTimestamp time.Time `param:"start_sequence_timestamp,required"`
	EndSequenceTimestamp   time.Time `param:"end_sequence_timestamp,required"`
	Limit                  int64     `param:"limit,,100"`
	Cursor                 string    `param:"cursor"`
}

type ListOrdersParams

type ListOrdersParams struct {
	ProductID            string    `param:"product_id"`
	OrderStatus          string    `param:"order_status"`
	Limit                int       `param:"limit"`
	StartDate            time.Time `param:"start_date"`
	EndDate              time.Time `param:"end_date"`
	UserNativeCurrency   string    `param:"user_native_currency"`
	OrderType            string    `param:"order_type"`
	OrderSide            string    `param:"order_side"`
	Cursor               string    `param:"cursor"`
	ProductType          string    `param:"product_type"`
	OrderPlacementSource string    `param:"order_placement_source"`
}

type ListProductsParams

type ListProductsParams struct {
	Limit       int32  `param:"limit"`
	Offset      int32  `param:"offset"`
	ProductType string `param:"product_type"`
}

type MarginRate

type MarginRate struct {
	Value string `json:"value"`
}

type MarketMarketIOC

type MarketMarketIOC struct {
	QuoteSize string `json:"quote_size" param:"quote_size"`
	BaseSize  string `json:"base_size" param:"base_size"`
}

type MarketTrade

type MarketTrade struct {
	Trade_id   string    `json:"trade_id"`
	Product_id string    `json:"product_id"`
	Price      string    `json:"price"`
	Size       string    `json:"size"`
	Time       time.Time `json:"time"`
	Side       string    `json:"side"`
	Bid        string    `json:"bid"`
	Ask        string    `json:"ask"`
}

type MarketTradeList

type MarketTradeList struct {
	Trades   []MarketTrade `json:"trades"`
	Best_bid string        `json:"best_bid"`
	Best_ask string        `json:"best_ask"`
}

type Market_market_ioc

type Market_market_ioc struct {
	QuoteSize string `json:"quote_size"`
	BaseSize  string `json:"base_size"`
}

type Order

type Order struct {
	OrderID              string             `json:"order_id,omitempty"`
	ProductID            string             `json:"product_id,omitempty"`
	UserID               string             `json:"user_id,omitempty"`
	OrderConfiguration   OrderConfiguration `json:"order_configuration,omitempty"`
	Side                 string             `json:"side,omitempty"`
	ClientOrderID        string             `json:"client_order_id,omitempty"`
	Status               string             `json:"status,omitempty"`
	TimeInForce          string             `json:"time_in_force,omitempty"`
	CreatedTime          time.Time          `json:"created_time,omitempty"`
	CompletionPercentage string             `json:"completion_percentage,omitempty"`
	FilledSize           string             `json:"filled_size,omitempty"`
	AverageFilledPrice   string             `json:"average_filled_price,omitempty"`
	Fee                  string             `json:"fee,omitempty"`
	NumberOfFills        string             `json:"number_of_fills,omitempty"`
	FilledValue          string             `json:"filled_value,omitempty"`
	PendingCancel        bool               `json:"pending_cancel,omitempty"`
	SizeInQuote          bool               `json:"size_in_quote,omitempty"`
	TotalFees            string             `json:"total_fees,omitempty"`
	SizeInclusiveOfFees  bool               `json:"size_inclusive_of_fees,omitempty"`
	TotalValueAfterFees  string             `json:"total_value_after_fees,omitempty"`
	TriggerStatus        string             `json:"trigger_status,omitempty"`
	OrderType            string             `json:"order_type,omitempty"`
	RejectReason         string             `json:"reject_reason,omitempty"`
	Settled              bool               `json:"settled,omitempty"`
	ProductType          string             `json:"product_type,omitempty"`
	RejectMessage        string             `json:"reject_message,omitempty"`
	CancelMessage        string             `json:"cancel_message,omitempty"`
	OrderPlacementSource string             `json:"order_placement_source,omitempty"`
}

type OrderBook

type OrderBook struct {
	Bids [][]float64 `json:"bids"`
	Asks [][]float64 `json:"asks"`
}

type OrderConfiguration

type OrderConfiguration struct {
	MarketMarketIOC       MarketMarketIOC       `json:"market_market_ioc,omitempty" param:"market_market_ioc"`
	LimitLimitGTC         LimitLimitGTC         `json:"limit_limit_gtc,omitempty" param:"limit_limit_gtc"`
	LimitLimitGTD         LimitLimitGTD         `json:"limit_limit_gtd,omitempty" param:"limit_limit_gtd"`
	StopLimitStopLimitGTC StopLimitStopLimitGTC `json:"stop_limit_stop_limit_gtc,omitempty" param:"stop_limit_stop_limit_gtc"`
	StopLimitStopLimitGTD StopLimitStopLimitGTD `json:"stop_limit_stop_limit_gtd,omitempty" param:"stop_limit_stop_limit_gtd"`
}

type OrderList

type OrderList struct {
	Orders  []Order `json:"orders"`
	HasNext bool    `json:"has_next"`
	Cursor  string  `json:"cursor"`
}

type OrdersResponse

type OrdersResponse struct {
	Orders   Order  `json:"orders"`
	Sequence string `json:"sequence"`
	HasNext  bool   `json:"has_next"`
	Cursor   string `json:"cursor"`
}

type Product

type Product struct {
	Product_id                   string `json:"product_id"`
	Price                        string `json:"price"`
	Price_percentage_change_24h  string `json:"price_percentage_change_24h"`
	Volume_24h                   string `json:"volume_24h"`
	Volume_percentage_change_24h string `json:"volume_percentage_change_24h"`
	Base_increment               string `json:"base_increment"`
	Quote_increment              string `json:"quote_increment"`
	Quote_min_size               string `json:"quote_min_size"`
	Quote_max_size               string `json:"quote_max_size"`
	Base_min_size                string `json:"base_min_size"`
	Base_max_size                string `json:"base_max_size"`
	Base_name                    string `json:"base_name"`
	Quote_name                   string `json:"quote_name"`
	Watched                      bool   `json:"watched"`
	Is_disabled                  bool   `json:"is_disabled"`
	New                          bool   `json:"new"`
	Status                       string `json:"status"`
	Cancel_only                  bool   `json:"cancel_only"`
	Limit_only                   bool   `json:"limit_only"`
	Post_only                    bool   `json:"post_only"`
	Trading_disabled             bool   `json:"trading_disabled"`
	Auction_mode                 bool   `json:"auction_mode"`
	Product_type                 string `json:"product_type"`
	Quote_currency_id            string `json:"quote_currency_id"`
	Base_currency_id             string `json:"base_currency_id"`
	Mid_market_price             string `json:"mid_market_price"`
	Base_display_symbol          string `json:"base_display_symbol"`
	Quote_display_symbol         string `json:"quote_display_symbol"`
}

type ProductList

type ProductList struct {
	Products     []Product `json:"products"`
	Num_products int       `json:"num_products"`
}

type StopLimitStopLimitGTC

type StopLimitStopLimitGTC struct {
	BaseSize      string `json:"base_size" param:"base_size"`
	LimitPrice    string `json:"limit_price" param:"limit_price"`
	StopPrice     string `json:"stop_price" param:"stop_price"`
	StopDirection string `json:"stop_direction" param:"stop_direction"`
}

type StopLimitStopLimitGTD

type StopLimitStopLimitGTD struct {
	BaseSize      string    `json:"base_size" param:"base_size"`
	LimitPrice    string    `json:"limit_price" param:"limit_price"`
	StopPrice     string    `json:"stop_price" param:"stop_price"`
	EndTime       time.Time `json:"end_time" param:"end_time"`
	StopDirection string    `json:"stop_direction" param:"stop_direction"`
}

type Stop_limit_stop_limit_gtc

type Stop_limit_stop_limit_gtc struct {
	BaseSize      string `json:"base_size"`
	LimitPrice    string `json:"limit_price"`
	StopPrice     string `json:"stop_price"`
	StopDirection string `json:"stop_direction"`
}

type Stop_limit_stop_limit_gtd

type Stop_limit_stop_limit_gtd struct {
	BaseSize      string    `json:"base_size"`
	LimitPrice    string    `json:"limit_price"`
	StopPrice     string    `json:"stop_price"`
	EndTime       time.Time `json:"end_time"`
	StopDirection string    `json:"stop_direction"`
}

type Ticker

type Ticker struct {
	TradeID   int64     `json:"trade_id"`
	Price     float64   `json:"price"`
	Size      float64   `json:"size"`
	Bid       float64   `json:"bid"`
	Ask       float64   `json:"ask"`
	Volume    float64   `json:"volume"`
	Timestamp time.Time `json:"timestamp"`
}

type Trade

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

type TransactionsSummary

type TransactionsSummary struct {
	Total_volume               float64             `json:"total_volume"`
	Total_fees                 float64             `json:"total_fees"`
	Fee_tier                   FeeTier             `json:"fee_tier,omitempty"`
	Margin_rate                MarginRate          `json:"margin_rate,omitempty"`            // only for margin accounts
	Goods_and_services_tax     GoodsAndServicesTax `json:"goods_and_services_tax,omitempty"` // only for margin accounts
	Advanced_trade_only_volume float64             `json:"advanced_trade_only_volume"`
	Advanced_trade_only_fees   float64             `json:"advanced_trade_only_fees"`
	Coinbase_pro_volume        float64             `json:"coinbase_pro_volume"`
	Coinbase_pro_fees          float64             `json:"coinbase_pro_fees"`
}

type UserEvent

type UserEvent struct {
	Type   string       `json:"type"`
	Orders []UserOrders `json:"orders"`
}

type UserMessage

type UserMessage struct {
	Channel     string      `json:"channel"`
	ClientID    string      `json:"client_id"`
	Timestamp   time.Time   `json:"timestamp"`
	SequenceNum int         `json:"sequence_num"`
	Events      []UserEvent `json:"events"`
}

Websocket user channel message

type UserOrders

type UserOrders struct {
	OrderID            string    `json:"order_id"`
	ClientOrderIO      string    `json:"client_order_id"`
	CumulativeQuantity string    `json:"cumulative_quantity"`
	LeavesQuantity     string    `json:"leaves_quantity"`
	AverageFilledPrice string    `json:"average_filled_price"`
	TotalFees          string    `json:"total_fees"`
	Status             string    `json:"status"`
	ProductID          string    `json:"product_id"`
	CreationTime       time.Time `json:"creation_time"`
	OrderType          string    `json:"order_type"`
	OrderSide          string    `json:"order_side"`
}

type WebSocketConnection

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

WebSocketConnection represents a websocket connection to the Coinbase Advanced API.

Jump to

Keyboard shortcuts

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