coinbase

package
v1.62.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: AGPL-3.0 Imports: 21 Imported by: 0

README

Order Life Cycle

  • market/limit orders
    • Once received and the order is not immediately filled, it will becom open. Or it will go straight to done.
    • Optionally, there might be changes to the order.
    • If a match event is generated and the order is still fillable, a new open event will be generated
    • done is the terminate state of the order life cycle
                                           
 Received ───► Open ───► [Change* ───► Open]* ───► Done 
    │                                               ▲   
    └───────────────────────────────────────────────┘   
                                           
  • stop order
    • After being created, it will generate an activate event.
    • [Need to confirm] After that, it will become a limit order and go through the life cycle depicted above.

Documentation

Overview

Code generated by go generate; DO NOT EDIT. generated on 2025-03-10 16:00:56.10256 +0000 UTC

Index

Constants

View Source
const (
	ID                = "coinbase"
	PlatformToken     = "COIN"
	PaginationLimit   = 100
	DefaultKLineLimit = 300
)

Variables

This section is empty.

Functions

func FNV64a

func FNV64a(text string) uint64

Types

type ActivateMessage

type ActivateMessage struct {
	ProductID string           `json:"product_id"`
	Timestamp string           `json:"timestamp"` // ex: "1483736448.299000"
	UserID    string           `json:"user_id"`
	ProfileID string           `json:"profile_id"`
	OrderID   string           `json:"order_id"`
	StopType  string           `json:"stop_type"`
	Side      api.SideType     `json:"side"`
	StopPrice fixedpoint.Value `json:"stop_price"`
	Size      fixedpoint.Value `json:"size"`
	Funds     fixedpoint.Value `json:"funds"`
	Private   bool             `json:"private"`
	// contains filtered or unexported fields
}

type AuctionMessage

type AuctionMessage struct {
	AuctionState string           `json:"auction_state"`
	BestBidPrice fixedpoint.Value `json:"best_bid_price"` // ex: 333.98
	BestBidSize  fixedpoint.Value `json:"best_bid_size"`  // ex: 4.39088265
	BestAskPrice fixedpoint.Value `json:"best_ask_price"`
	BestAskSize  fixedpoint.Value `json:"best_ask_size"`
	OpenPrice    fixedpoint.Value `json:"open_price"`
	OpenSize     fixedpoint.Value `json:"open_size"`
	CanOpen      string           `json:"can_open"`
	Timestamp    time.Time        `json:"timestamp"` // ex: "2015-11-14T20:46:03.511254Z"
	// contains filtered or unexported fields
}

auction channel

func (*AuctionMessage) QuoteCurrency

func (s *AuctionMessage) QuoteCurrency() string

type BalanceMessage

type BalanceMessage struct {
	AccountID string           `json:"account_id"`
	Currency  string           `json:"currency"`
	Holds     fixedpoint.Value `json:"holds"`
	Available fixedpoint.Value `json:"available"`
	Updated   types.Time       `json:"updated"`
	Timestamp types.Time       `json:"timestamp"`
	// contains filtered or unexported fields
}

balance channel

type ChangeMessage

type ChangeMessage struct {
	Reason  string           `json:"reason"` // "STP" or "modify_order"
	Time    time.Time        `json:"time"`
	OrderID string           `json:"order_id"`
	Side    api.SideType     `json:"side"`
	OldSize fixedpoint.Value `json:"old_size"`
	NewSize fixedpoint.Value `json:"new_size"`

	// STP fields
	Price fixedpoint.Value `json:"price,omitempty"`

	// modify_order fields
	OldPrice fixedpoint.Value `json:"old_price,omitempty"`
	NewPrice fixedpoint.Value `json:"new_price,omitempty"`
	// contains filtered or unexported fields
}

func (*ChangeMessage) IsModifyOrder

func (m *ChangeMessage) IsModifyOrder() bool

func (*ChangeMessage) IsStp

func (m *ChangeMessage) IsStp() bool

func (*ChangeMessage) QuoteCurrency

func (s *ChangeMessage) QuoteCurrency() string

type DoneMessage

type DoneMessage struct {
	Time          time.Time        `json:"time"`
	Price         fixedpoint.Value `json:"price"`
	OrderID       string           `json:"order_id"`
	Reason        string           `json:"reason"` // filled, canceled
	Side          api.SideType     `json:"side"`
	RemainingSize fixedpoint.Value `json:"remaining_size"`
	CancelReason  string           `json:"cancel_reason,omitempty"` // non-empty if reason is canceled
	// contains filtered or unexported fields
}

func (*DoneMessage) QuoteCurrency

func (s *DoneMessage) QuoteCurrency() string

type ErrorMessage

type ErrorMessage struct {
	Reason string `json:"reason"`
	// contains filtered or unexported fields
}

type Exchange

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

func New

func New(key, secret, passphrase string, timeout time.Duration) *Exchange

func (*Exchange) CancelOrders

func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) error

func (*Exchange) CancelOrdersBySymbol

func (e *Exchange) CancelOrdersBySymbol(ctx context.Context, symbol string) ([]types.Order, error)

tradingutil.CancelAllOrdersBySymbolService

func (*Exchange) Client

func (e *Exchange) Client() *api.RestAPIClient

func (*Exchange) IsSupportedInterval

func (e *Exchange) IsSupportedInterval(interval types.Interval) bool

func (*Exchange) Name

func (e *Exchange) Name() types.ExchangeName

ExchangeMinimal

func (*Exchange) NewStream

func (e *Exchange) NewStream() types.Stream

ExchangeMarketDataService

func (*Exchange) PlatformFeeCurrency

func (e *Exchange) PlatformFeeCurrency() string

func (*Exchange) QueryAccount

func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error)

ExchangeAccountService

func (*Exchange) QueryAccountBalances

func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error)

func (*Exchange) QueryKLines

func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error)

func (*Exchange) QueryMarkets

func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error)

func (*Exchange) QueryOpenOrders

func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) ([]types.Order, error)

func (*Exchange) QueryOrder

func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error)

ExchangeOrderQueryService

func (*Exchange) QueryOrderTrades

func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) ([]types.Trade, error)

func (*Exchange) QueryTicker

func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error)

func (*Exchange) QueryTickers

func (e *Exchange) QueryTickers(ctx context.Context, symbol ...string) (map[string]types.Ticker, error)

func (*Exchange) SubmitOrder

func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (createdOrder *types.Order, err error)

ExchangeTradeService For the stop-limit order, we only support the long position For the market order, though Coinbase supports both funds and size, we only support size in order to simplify the stream handler logic We do not support limit order with funds.

func (*Exchange) SupportedInterval

func (e *Exchange) SupportedInterval() map[types.Interval]int

type HeartbeatMessage

type HeartbeatMessage struct {
	LastTradeID int       `json:"last_trade_id"`
	Time        time.Time `json:"time"`
	// contains filtered or unexported fields
}

heartbeat channel

func (*HeartbeatMessage) QuoteCurrency

func (s *HeartbeatMessage) QuoteCurrency() string

type MatchMessage

type MatchMessage struct {
	TradeID      int              `json:"trade_id"`
	MakerOrderID string           `json:"maker_order_id"`
	TakerOrderID string           `json:"taker_order_id"`
	Time         time.Time        `json:"time"`
	Size         fixedpoint.Value `json:"size"`
	Price        fixedpoint.Value `json:"price"`
	Side         api.SideType     `json:"side"`

	UserID    string `json:"user_id"`
	ProfileID string `json:"profile_id"`

	// extra fields for taker
	TakerUserID    string           `json:"taker_user_id,omitempty"`
	TakerProfileID string           `json:"taker_profile_id,omitempty"`
	TakerFeeRate   fixedpoint.Value `json:"taker_fee_rate,omitempty"`

	// extra fields for maker
	MakerUserID    string           `json:"maker_user_id,omitempty"`
	MakerProfileID string           `json:"maker_profile_id,omitempty"`
	MakerFeeRate   fixedpoint.Value `json:"maker_fee_rate,omitempty"`
	// contains filtered or unexported fields
}

func (*MatchMessage) IsAuthMaker

func (m *MatchMessage) IsAuthMaker() bool

func (*MatchMessage) QuoteCurrency

func (s *MatchMessage) QuoteCurrency() string

func (*MatchMessage) Trade

func (msg *MatchMessage) Trade() types.Trade

type MessageType

type MessageType string

type OpenMessage

type OpenMessage struct {
	Time          time.Time        `json:"time"`
	OrderID       string           `json:"order_id"`
	Price         fixedpoint.Value `json:"price"`
	RemainingSize fixedpoint.Value `json:"remaining_size"`
	Side          api.SideType     `json:"side"`
	// contains filtered or unexported fields
}

func (*OpenMessage) QuoteCurrency

func (s *OpenMessage) QuoteCurrency() string

type OrderBookSnapshotMessage

type OrderBookSnapshotMessage struct {
	ProductID string               `json:"product_id"`
	Bids      [][]fixedpoint.Value `json:"bids"` // [["price", "size"], ...]
	Asks      [][]fixedpoint.Value `json:"asks"` // [["price", "size"], ...]
	// contains filtered or unexported fields
}

level2 channel

type OrderBookUpdateMessage

type OrderBookUpdateMessage struct {
	ProductID string     `json:"product_id"`
	Time      time.Time  `json:"time"`
	Changes   [][]string `json:"changes"` // [["side", "price", "size"], ...]
	// contains filtered or unexported fields
}

type ReceivedMessage

type ReceivedMessage struct {
	ClientOid string       `json:"client-oid"`
	OrderID   string       `json:"order_id"`
	OrderType string       `json:"order_type"`
	Side      api.SideType `json:"side"`
	Time      time.Time    `json:"time"`

	// limit order fields
	Size  fixedpoint.Value `json:"size,omitempty"`
	Price fixedpoint.Value `json:"price,omitempty"`

	// market order fields
	Funds fixedpoint.Value `json:"funds,omitempty"`
	// contains filtered or unexported fields
}

full channel

func (*ReceivedMessage) IsMarketOrder

func (m *ReceivedMessage) IsMarketOrder() bool

func (*ReceivedMessage) QuoteCurrency

func (s *ReceivedMessage) QuoteCurrency() string

func (*ReceivedMessage) ToGlobalOrder

func (m *ReceivedMessage) ToGlobalOrder() types.Order

type RfqMessage

type RfqMessage struct {
	MakerOrderID string           `json:"maker_order_id"`
	TakerOrderID string           `json:"taker_order_id"`
	Time         time.Time        `json:"time"`
	TradeID      int              `json:"trade_id"`
	ProductID    string           `json:"product_id"`
	Size         fixedpoint.Value `json:"size"`
	Price        fixedpoint.Value `json:"price"`
	Side         api.SideType     `json:"side"`
	// contains filtered or unexported fields
}

rfq_matches channel

type SequenceNumberType

type SequenceNumberType uint64

type StatusMessage

type StatusMessage struct {
	Products []struct {
		ID             string           `json:"id"`
		BaseCurrency   string           `json:"base_currency"`
		QuoteCurrency  string           `json:"quote_currency"`
		BaseIncrement  fixedpoint.Value `json:"base_increment"`  // ex: 0.00000001
		QuoteIncrement fixedpoint.Value `json:"quote_increment"` // ex: 0.01
		DisplayName    string           `json:"display_name"`
		Status         string           `json:"status"`
		StatusMessage  any              `json:"status_message"`
		MinMarketFunds fixedpoint.Value `json:"min_market_funds"` // ex: 10
		PostOnly       bool             `json:"post_only"`
		LimitOnly      bool             `json:"limit_only"`
		CancelOnly     bool             `json:"cancel_only"`
		FxStablecoin   bool             `json:"fx_stablecoin"`
	} `json:"products"`
	Currencies []struct {
		ID            string           `json:"id"`
		Name          string           `json:"name"`
		DisplayName   string           `json:"display_name"`
		MinSize       fixedpoint.Value `json:"min_size"` // ex: 0.01
		Status        string           `json:"status"`
		StatusMessage any              `json:"status_message"`
		MaxPrecision  fixedpoint.Value `json:"max_precision"` // ex: 0.01
		ConvertibleTo []string         `json:"convertible_to"`
		Details       struct {
		} `json:"details"`
		DefaultNetwork    string `json:"default_network"`
		SupportedNetworks []struct {
			ID                    string           `json:"id"`
			Name                  string           `json:"name"`
			Status                string           `json:"status"`
			ContractAddress       string           `json:"contract_address"`
			CryptoTransactionLink string           `json:"crypto_transaction_link"`
			MinWithdrawalAmount   fixedpoint.Value `json:"min_withdrawal_amount"`   // ex: 0.001
			MaxWithdrawalAmount   fixedpoint.Value `json:"max_withdrawal_amount"`   // ex: 300000000
			NetworkConfirmations  int              `json:"network_confirmations"`   // ex: 14
			ProcessingTimeSeconds int              `json:"processing_time_seconds"` // ex: 0
			DestinationTagRegex   string           `json:"destination_tag_regex"`
		} `json:"supported_networks"`
	} `json:"currencies"`
	// contains filtered or unexported fields
}

status channel

type Stream

type Stream struct {
	types.StandardStream
	// contains filtered or unexported fields
}

func NewStream

func NewStream(
	exchange *Exchange,
	apiKey string,
	secretKey string,
	passphrase string,
) *Stream

func (*Stream) EmitActivateMessage

func (s *Stream) EmitActivateMessage(m *ActivateMessage)

func (*Stream) EmitAuctionMessage

func (s *Stream) EmitAuctionMessage(m *AuctionMessage)

func (*Stream) EmitBalanceMessage

func (s *Stream) EmitBalanceMessage(m *BalanceMessage)

func (*Stream) EmitChangeMessage

func (s *Stream) EmitChangeMessage(m *ChangeMessage)

func (*Stream) EmitDoneMessage

func (s *Stream) EmitDoneMessage(m *DoneMessage)

func (*Stream) EmitErrorMessage

func (s *Stream) EmitErrorMessage(m *ErrorMessage)

func (*Stream) EmitMatchMessage

func (s *Stream) EmitMatchMessage(m *MatchMessage)

func (*Stream) EmitOpenMessage

func (s *Stream) EmitOpenMessage(m *OpenMessage)

func (*Stream) EmitOrderbookSnapshotMessage

func (s *Stream) EmitOrderbookSnapshotMessage(m *OrderBookSnapshotMessage)

func (*Stream) EmitOrderbookUpdateMessage

func (s *Stream) EmitOrderbookUpdateMessage(m *OrderBookUpdateMessage)

func (*Stream) EmitReceivedMessage

func (s *Stream) EmitReceivedMessage(m *ReceivedMessage)

func (*Stream) EmitRfqMessage

func (s *Stream) EmitRfqMessage(m *RfqMessage)

func (*Stream) EmitStatusMessage

func (s *Stream) EmitStatusMessage(m *StatusMessage)

func (*Stream) EmitSubscriptions

func (s *Stream) EmitSubscriptions(m *SubscriptionsMessage)

func (*Stream) EmitTickerMessage

func (s *Stream) EmitTickerMessage(m *TickerMessage)

func (*Stream) OnActivateMessage

func (s *Stream) OnActivateMessage(cb func(m *ActivateMessage))

func (*Stream) OnAuctionMessage

func (s *Stream) OnAuctionMessage(cb func(m *AuctionMessage))

func (*Stream) OnBalanceMessage

func (s *Stream) OnBalanceMessage(cb func(m *BalanceMessage))

func (*Stream) OnChangeMessage

func (s *Stream) OnChangeMessage(cb func(m *ChangeMessage))

func (*Stream) OnDoneMessage

func (s *Stream) OnDoneMessage(cb func(m *DoneMessage))

func (*Stream) OnErrorMessage

func (s *Stream) OnErrorMessage(cb func(m *ErrorMessage))

func (*Stream) OnMatchMessage

func (s *Stream) OnMatchMessage(cb func(m *MatchMessage))

func (*Stream) OnOpenMessage

func (s *Stream) OnOpenMessage(cb func(m *OpenMessage))

func (*Stream) OnOrderbookSnapshotMessage

func (s *Stream) OnOrderbookSnapshotMessage(cb func(m *OrderBookSnapshotMessage))

func (*Stream) OnOrderbookUpdateMessage

func (s *Stream) OnOrderbookUpdateMessage(cb func(m *OrderBookUpdateMessage))

func (*Stream) OnReceivedMessage

func (s *Stream) OnReceivedMessage(cb func(m *ReceivedMessage))

func (*Stream) OnRfqMessage

func (s *Stream) OnRfqMessage(cb func(m *RfqMessage))

func (*Stream) OnStatusMessage

func (s *Stream) OnStatusMessage(cb func(m *StatusMessage))

func (*Stream) OnSubscriptions

func (s *Stream) OnSubscriptions(cb func(m *SubscriptionsMessage))

func (*Stream) OnTickerMessage

func (s *Stream) OnTickerMessage(cb func(m *TickerMessage))

type SubscriptionsMessage

type SubscriptionsMessage struct {
	Channels []channelType `json:"channels"`
	// contains filtered or unexported fields
}

Websocket message types

type TickerMessage

type TickerMessage struct {
	Price       fixedpoint.Value `json:"price"`
	Open24H     fixedpoint.Value `json:"open_24h"` // ex: 1310.79
	Volume24H   fixedpoint.Value `json:"volume_24h"`
	Low24H      fixedpoint.Value `json:"low_24h"`
	High24H     fixedpoint.Value `json:"high_24h"`
	Volume30D   fixedpoint.Value `json:"volume_30d"`
	BestBid     fixedpoint.Value `json:"best_bid"`
	BestBidSize fixedpoint.Value `json:"best_bid_size"`
	BestAsk     fixedpoint.Value `json:"best_ask"`
	BestAskSize fixedpoint.Value `json:"best_ask_size"`
	Side        api.SideType     `json:"side"`
	Time        time.Time        `json:"time"`
	TradeID     int              `json:"trade_id"`
	LastSize    fixedpoint.Value `json:"last_size"`
	// contains filtered or unexported fields
}

ticker channel

func (*TickerMessage) QuoteCurrency

func (s *TickerMessage) QuoteCurrency() string

Directories

Path Synopsis
api
v1

Jump to

Keyboard shortcuts

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