coinbase

package
v0.0.0-...-8ecd258 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// IDBTCUSD is the coinbase product ID for the BTC-USD pair
	IDBTCUSD = "BTC-USD"
	// IDETHUSD is the coinbase product ID for the ETH-USD pair
	IDETHUSD = "ETH-USD"
	// IDETHBTC is the coinbase prodcut ID for the ETH-BTC pair
	IDETHBTC = "ETH-BTC"
)

Variables

View Source
var (

	// GETMissingTradesRetries is the retry limit for attempting to GET any missing trades from the matches channel for a given TradeReader's productID using the REST API for coinbase
	GETMissingTradesRetries = 3
)

Functions

This section is empty.

Types

type MatchMsg

type MatchMsg struct {
	TypeStr      string `json:"type"`
	TradeID      int    `json:"trade_id"`
	MakerOrderID string `json:"maker_order_id"`
	TakerOrderID string `json:"take_order_id"`
	Side         string `json:"side"`
	Size         string `json:"size"`
	Price        string `json:"price"`
	ProductID    string `json:"product_id"`
	Sequence     int    `json:"sequence"`
	Time         string `json:"time"`
}

MatchMsg maps the JSON received from coinbase for the matches channel

type SubscribeMsg

type SubscribeMsg struct {
	TypeStr    string   `json:"type"`
	ProductIDs []string `json:"product_ids"`
	Channels   []string `json:"channels"`
}

SubscribeMsg maps the JSON subscribe message used by coinbase for different product IDs and channels

type Trade

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

Trade is the JSON representation for trades used by the coinbase /prodcut/{product_id}/trades REST API TODO: maybe rename to RESTtrade

type TradeReader

type TradeReader struct {

	// LastTradeID can be used to initialize a new instance after a failure and fill in any missing gaps in the VWAP
	LastTradeID int
	// contains filtered or unexported fields
}

TradeReader is the

func NewTradeReader

func NewTradeReader(tradeChan chan<- *vwap.Trade, productID string, lastTradeID int) (*TradeReader, error)

NewTradeReader initializes a new coinbase.TradeReader object and dials the coinbase websocket. It takes a trade channel to send out vwap.Trade objects, and a productID to watch. If a connection cannot be dialed it returns an error. Use a buffered channel for better performance, vwap.ChanBuffLen is recommended.

func (*TradeReader) CloseConn

func (tr *TradeReader) CloseConn()

CloseConn closes the websocket connection and logs any close error. Works well with defer

func (*TradeReader) ReadConn

func (tr *TradeReader) ReadConn()

ReadConn reads the websocket connection and gets the information to send a trade on the trade channel for the instance. It checks to ensure message order was maintained and fills in any gaps if any messages were dropped. It should be ran in a separate goroutine and started before Subscribe is called

func (*TradeReader) Subscribe

func (tr *TradeReader) Subscribe() error

Subscribe sends the subscribe message to the websocket for the match channel and uses productID of the instance.

func (*TradeReader) WaitForEnd

func (tr *TradeReader) WaitForEnd(ctx context.Context)

WaitForEnd blocks until an end condition is met. This happens if the given context is cancelled and then the websocket is closed normally. This also happens if reading from the websocket encounters an error.

Jump to

Keyboard shortcuts

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