cbp

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CancelOrder added in v1.0.5

func CancelOrder(id string, attempt ...int) error

CancelOrder is a recursive function that cancels an order equal to the given id.

func CreateOrder added in v1.0.5

func CreateOrder(order *cb.Order, attempt ...int) (*cb.Order, error)

CreateOrder creates an order on Coinbase and returns the order once it is no longer pending and has settled. Given that there are many different types of orders that can be created in many different scenarios, it is the responsibility of the method calling this function to perform logging.

func GetActivePositions added in v1.0.5

func GetActivePositions() (map[string]Position, error)

func GetAllProductIDs added in v1.0.2

func GetAllProductIDs() []string

func GetFills added in v1.0.5

func GetFills(productID string) (*[]cb.Fill, error)

func GetOrder added in v1.0.5

func GetOrder(id string, attempt ...int) (*cb.Order, error)

GetOrder is a recursive function that returns an order equal to the given id once it is settled and not pending. This function also performs extensive logging given its variable and seriously critical nature.

func GetOrders added in v1.0.5

func GetOrders(productID string) (*[]cb.Order, error)

func GetPrice added in v1.0.2

func GetPrice(wsConn *ws.Conn, productID string) (*float64, error)

GetPrice gets the latest ticker price for the given productID. This method does not perform logging as it is executed thousands of times per second.

func GetTickerPrice added in v1.0.5

func GetTickerPrice(productID string) (*float64, error)

func GetTradingPositions added in v1.0.6

func GetTradingPositions() (map[string]Position, error)

GetTradingPositions returns a map of trading positions.

func Init added in v1.0.2

func Init(name string, dbProducts *[]Product) (*time.Time, error)

func Maker added in v1.0.3

func Maker() float64

func Taker added in v1.0.3

func Taker() float64

Types

type Config added in v1.0.2

type Config struct {
	Api struct {
		Key        string `envconfig:"COINBASE_PRO_KEY" yaml:"key"`
		Passphrase string `envconfig:"COINBASE_PRO_PASSPHRASE" yaml:"pass"`
		Secret     string `envconfig:"COINBASE_PRO_SECRET" yaml:"secret"`
		Fees       struct {
			Maker float64 `envconfig:"COINBASE_PRO_MAKER_FEE" yaml:"maker"`
			Taker float64 `envconfig:"COINBASE_PRO_TAKER_FEE" yaml:"taker"`
		} `yaml:"fees"`
	} `yaml:"cbp"`
}

type Pattern

type Pattern struct {

	// Id is concatenation of two currencies. eg. BTC-USD
	ID string `yaml:"id" json:"id"`

	// Gain is a percentage used to produce the goal sell price from the entry buy price.
	Gain float64 `yaml:"gain" json:"gain"`

	// Loss is a percentage used to derive a limit sell price from the entry buy price.
	Loss float64 `yaml:"loss" json:"loss"`

	// Size is the amount of the transaction, using the products native quote increment.
	Size float64 `yaml:"size" json:"size"`

	// Delta is the size of an acceptable difference between tweezer bottom candlesticks.
	Delta float64 `yaml:"delta" json:"delta"`
}

Pattern defines the criteria for matching rates and placing orders.

func (*Pattern) GoalPrice

func (p *Pattern) GoalPrice(price float64) float64

func (*Pattern) InitPattern added in v1.0.1

func (p *Pattern) InitPattern(size, gain, loss, delta float64)

func (*Pattern) LossPrice

func (p *Pattern) LossPrice(price float64) float64

func (*Pattern) MatchesTweezerBottomPattern

func (p *Pattern) MatchesTweezerBottomPattern(then, that, this Rate) bool

func (*Pattern) NewLimitLossOrder added in v1.0.5

func (p *Pattern) NewLimitLossOrder(price float64, size string) *cb.Order

func (*Pattern) NewLimitSellEntryOrder added in v1.0.5

func (p *Pattern) NewLimitSellEntryOrder(price float64, size string) *cb.Order

func (*Pattern) NewLimitSellEntryOrderAtGoalPrice added in v1.0.5

func (p *Pattern) NewLimitSellEntryOrderAtGoalPrice(trade *Trade) *cb.Order

func (*Pattern) NewMarketBuyOrder added in v1.0.5

func (p *Pattern) NewMarketBuyOrder() *cb.Order

func (*Pattern) NewMarketSellOrder added in v1.0.5

func (p *Pattern) NewMarketSellOrder(size string) *cb.Order

func (*Pattern) PrecisePrice added in v1.0.9

func (p *Pattern) PrecisePrice(f float64) string

func (*Pattern) PrecisePriceFromString added in v1.0.9

func (p *Pattern) PrecisePriceFromString(s string) string

func (*Pattern) PreciseSize added in v1.0.9

func (p *Pattern) PreciseSize(s string) string

type Position

type Position struct {
	cb.Account
	cb.Ticker
	// contains filtered or unexported fields
}

func NewPosition

func NewPosition(account cb.Account, ticker cb.Ticker, fills []cb.Fill) *Position

func (Position) Balance

func (p Position) Balance() float64

func (*Position) GetActiveTrades

func (p *Position) GetActiveTrades() []Trade

func (*Position) IsHeld

func (p *Position) IsHeld() bool

func (Position) Price

func (p Position) Price() float64

func (Position) Value

func (p Position) Value() float64

type Posture added in v1.0.9

type Posture interface {
	ID() string
}

type Product

type Product struct {
	gorm.Model
	cb.Product
	Pattern
}

func GetProduct added in v1.0.2

func GetProduct(productID string) *Product

func NewProduct added in v1.0.9

func NewProduct(product cb.Product) Product

func (*Product) ID added in v1.0.9

func (p *Product) ID() string

type Rate

type Rate struct {
	Unix      int64  `json:"unix" gorm:"primaryKey"`
	ProductId string `json:"product_id" gorm:"primaryKey"`
	cb.HistoricRate
}

func GetHistoricRates added in v1.0.5

func GetHistoricRates(productID string, alpha, omega time.Time) ([]Rate, error)

func GetRate added in v1.0.2

func GetRate(productID string) (*Rate, error)

func GetRates added in v1.0.9

func GetRates(productID string, params *[]cb.GetHistoricRatesParams) ([]Rate, error)

func NewRate

func NewRate(productID string, historicRate cb.HistoricRate) *Rate

func (*Rate) Data

func (v *Rate) Data() [4]float64

func (*Rate) IsDown

func (v *Rate) IsDown() bool

func (*Rate) IsInit

func (v *Rate) IsInit() bool

func (*Rate) IsUp

func (v *Rate) IsUp() bool

func (*Rate) Label

func (v *Rate) Label() string

func (*Rate) Time

func (v *Rate) Time() time.Time

type Trade

type Trade struct {
	cb.Fill
}

func NewTrade

func NewTrade(cbFill cb.Fill) *Trade

func (Trade) Price

func (t Trade) Price() float64

func (Trade) Size

func (t Trade) Size() float64

func (Trade) Total

func (t Trade) Total() float64

Jump to

Keyboard shortcuts

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