gdax

package module
v0.0.0-...-0a251c6 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2018 License: MIT Imports: 18 Imported by: 0

README

gdax - a Go wrapper for the GDAX API

Build Status Codecov private license Work Status

This is a work in progress.

Installation

go get github.com/ljeabmreosn/gdax

Examples

See here.

Documentation

Overview

Package gdax is a wrapper for the GDAX API.

Index

Constants

View Source
const (
	TransferEntry = "transfer"
	MatchEntry    = "match"
	FeeEntry      = "fee"
	RebateEntry   = "rebate"
)

Entries

View Source
const (
	SubscriptionsType = "subscriptions"
	HeartbeatType     = "heartbeat"
	TickerType        = "ticker"
	Level2Type        = "level2"
	L2UpdateType      = "l2update"
	SnapshotType      = "snapshot"
	UserType          = "user"
	MatchesType       = "matches"
	MatchType         = "match"
	FullType          = "full"
	ErrorType         = "error"
	SubscribeType     = "subscribe"
)

Subscriptions

View Source
const (
	Maker = "M"
	Taker = "T"
)

Fills

View Source
const (
	Buy  = "buy" // Side
	Sell = "sell"

	Limit  = "limit" // Type
	Market = "market"

	Loss  = "loss" // Stop
	Entry = "entry"

	GoodTillTime      = "GTT" // Order Policy
	GoodTillCancelled = "GTC"
	ImmediateOrCancel = "IOC"
	FillOrKill        = "FOK"

	DecreaseAndCancel = "dc" // Self-Trade Prevention
	CancelOldest      = "co"
	CancelNewest      = "cn"

	Open    = "open" // Status
	Pending = "pending"
	Active  = "active"
	Done    = "done"
	All     = "all"
)

Order Constants

View Source
const (
	Fills = "fills"
	Pdf   = "pdf"
	Csv   = "csv"
)

Formats

View Source
const EndPoint = "https://api-public.sandbox.gdax.com"

EndPoint is the GDAX sandbox endpoint.

Variables

This section is empty.

Functions

func Feed

func Feed(s *Subscription, messageHandler func(Message)) error

Feed makes a subscription to the specified channel and sends any incoming messages to the specified message handler. Note that this function is blocking; this function only terminates if the connection is dropped/terminated or an error is sent.

Types

type AccessInfo

type AccessInfo struct {
	PublicKey  string `json:"public_api"`
	PrivateKey string `json:"private_api"`
	Passphrase string `json:"passphrase"`
	Client     *http.Client
}

An AccessInfo stores credentials.

func RetrieveAccessInfoFromEnvironmentVariables

func RetrieveAccessInfoFromEnvironmentVariables() (*AccessInfo, error)

RetrieveAccessInfoFromEnvironmentVariables retrieves credentials from environment variables.

func RetrieveAccessInfoFromFile

func RetrieveAccessInfoFromFile(fileName string) (*AccessInfo, error)

RetrieveAccessInfoFromFile retrieves credentials from a specified file.

func (*AccessInfo) CancelAllOrders

func (accessInfo *AccessInfo) CancelAllOrders() *UUIDCollection

CancelAllOrders cancels all orders. Note that this function is lazy.

func (*AccessInfo) CancelAllOrdersForProduct

func (accessInfo *AccessInfo) CancelAllOrdersForProduct(productID string) *UUIDCollection

CancelAllOrdersForProduct cancels all orders with the specified productID. Note that this function is lazy.

func (*AccessInfo) CancelOrder

func (accessInfo *AccessInfo) CancelOrder(orderID *uuid.UUID) *UUIDCollection

CancelOrder cancels an order with the specified orderID. Note that this function is lazy.

func (*AccessInfo) CreateReport

func (accessInfo *AccessInfo) CreateReport(report *Report) (*Report, error)

CreateReport submits a report request.

func (*AccessInfo) GetAccount

func (accessInfo *AccessInfo) GetAccount(accountID *uuid.UUID) (*Account, error)

GetAccount gets an Account with a specified accountID.

func (*AccessInfo) GetAccountHistory

func (accessInfo *AccessInfo) GetAccountHistory(accountID *uuid.UUID) *AccountHistoryCollection

GetAccountHistory gets all AccountHistorys with a specified accountID.

func (*AccessInfo) GetAccountHolds

func (accessInfo *AccessInfo) GetAccountHolds(accountID *uuid.UUID) *AccountHoldCollection

GetAccountHolds gets all AcountHolds with a specified accountID.

func (*AccessInfo) GetAccounts

func (accessInfo *AccessInfo) GetAccounts() *AccountCollection

GetAccounts gets all associated Accounts.

func (*AccessInfo) GetCoinbaseAccounts

func (accessInfo *AccessInfo) GetCoinbaseAccounts() *CoinbaseAccountCollection

GetCoinbaseAccounts gets all coinbase accounts.

func (*AccessInfo) GetFills

func (accessInfo *AccessInfo) GetFills(orderIDs ...*uuid.UUID) *FillCollection

GetFills gets all fills with the specified orderIDs.

func (*AccessInfo) GetFillsForProduct

func (accessInfo *AccessInfo) GetFillsForProduct(productID string, orderIDs ...*uuid.UUID) *FillCollection

GetFillsForProduct gets all fills for a specified productID and specified orderIDs.

func (*AccessInfo) GetOrder

func (accessInfo *AccessInfo) GetOrder(orderID *uuid.UUID) (*Order, error)

GetOrder gets the order with the specified orderID.

func (*AccessInfo) GetOrders

func (accessInfo *AccessInfo) GetOrders(statuses ...string) *OrderCollection

GetOrders gets all orders with the given statuses.

func (*AccessInfo) GetOrdersForProduct

func (accessInfo *AccessInfo) GetOrdersForProduct(productID string, statuses ...string) *OrderCollection

GetOrdersForProduct gets all orders with the specified productID and specified statuses.

func (*AccessInfo) GetReportStatus

func (accessInfo *AccessInfo) GetReportStatus(reportID *uuid.UUID) (*Report, error)

GetReportStatus retrieves the status of a submitted report.

func (*AccessInfo) PlaceLimitOrder

func (accessInfo *AccessInfo) PlaceLimitOrder(order *Order) (*Order, error)

PlaceLimitOrder places a limit order.

func (*AccessInfo) PlaceMarketOrder

func (accessInfo *AccessInfo) PlaceMarketOrder(order *Order) (*Order, error)

PlaceMarketOrder places a market order.

type Account

type Account struct {
	ID        *uuid.UUID `json:"id,string"`
	Currency  string     `json:"currency"`
	Balance   float64    `json:"balance,string"`
	Available float64    `json:"available,string"`
	Holds     float64    `json:"holds,string"`
	ProfileID string     `json:"profile_id,omitempty"`
}

An Account represents the user's account.

type AccountCollection

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

An AccountCollection is an iterator of Accounts.

func (*AccountCollection) HasNext

func (c *AccountCollection) HasNext() bool

HasNext determines if there is another Account in this iterator.

func (*AccountCollection) Next

func (c *AccountCollection) Next() (*Account, error)

Next gets the next Account from the iterator.

type AccountHistory

type AccountHistory struct {
	ID        int64                 `json:"id"`
	CreatedAt time.Time             `json:"created_at,string"`
	Amount    float64               `json:"amount,string"`
	Balance   float64               `json:"balance,string"`
	Type      string                `json:"type"`
	Details   AccountHistoryDetails `json:"details"`
}

An AccountHistory represents information about the past state(s) of the user's account.

type AccountHistoryCollection

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

An AccountHistoryCollection is an iterator of AccountHistorys.

func (*AccountHistoryCollection) HasNext

func (c *AccountHistoryCollection) HasNext() bool

HasNext determines if there is another AccountHistory in this iterator.

func (*AccountHistoryCollection) Next

Next gets the next AccountHistory from the iterator.

type AccountHistoryDetails

type AccountHistoryDetails struct {
	OrderID   *uuid.UUID `json:"order_id,string"`
	TradeID   string     `json:"trade_id"`
	ProductID string     `json:"product_id"`
}

An AccountHistoryDetails represents information about past trades that the user has made.

type AccountHold

type AccountHold struct {
	ID        *uuid.UUID `json:"id,string"`
	AccountID *uuid.UUID `json:"account_id,string"`
	CreatedAt time.Time  `json:"created_at,string"`
	UpdatedAt time.Time  `json:"updated_at,string"`
	Amount    float64    `json:"amount,string"`
	Type      string     `json:"type"`
	Ref       string     `json:"ref"`
}

An AccountHold represents any holds that the user has.

type AccountHoldCollection

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

An AccountHoldCollection is an iterator of AccountHoldCollections.

func (*AccountHoldCollection) HasNext

func (c *AccountHoldCollection) HasNext() bool

HasNext determines if there is another AccountHold in this iterator.

func (*AccountHoldCollection) Next

func (c *AccountHoldCollection) Next() (*AccountHold, error)

Next gets the next AccountHold from the iterator.

type Ask

type Ask struct {
	Price float64 `json:"price"`
	Size  float64 `json:"size"`
}

A Ask stores a single ask from a snapshot.

type Bid

type Bid struct {
	Price float64 `json:"price"`
	Size  float64 `json:"size"`
}

A Bid stores a single bid from a snapshot.

type Change

type Change struct {
	Side  string  `json:"side"`
	Price float64 `json:"price"`
	Size  float64 `json:"size"`
}

A Change stores a single change from an L2Update.

type CoinbaseAccount

type CoinbaseAccount struct {
	ID       *uuid.UUID `json:"id,string"`
	Name     string     `json:"name"`
	Balance  float64    `json:"balance,string"`
	Currency string     `json:"currency"`
	Type     string     `json:"wallet"`
	Primary  bool       `json:"primary"`
	Active   bool       `json:"active"`
}

A CoinbaseAccount stores information about a specific coinbase account.

type CoinbaseAccountCollection

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

A CoinbaseAccountCollection is an iterator of CoinbaseAccounts.

func (*CoinbaseAccountCollection) HasNext

func (c *CoinbaseAccountCollection) HasNext() bool

HasNext determines if there is another CoinbaseAccount in this iterator.

func (*CoinbaseAccountCollection) Next

Next gets the next CoinbaseAccount from the iterator.

type DayHourMin

type DayHourMin struct {
	time.Time
}

A DayHourMin is a time struct with format mm,hh,dd.

func (*DayHourMin) MarshalJSON

func (d *DayHourMin) MarshalJSON() ([]byte, error)

MarshalJSON creates JSON from a DayHourMin struct.

type Error

type Error struct {
	Message string `json:"message"`
	// contains filtered or unexported fields
}

An Error stores information about the error message in the event something invalid was sent across the channel.

func (Error) Error

func (err Error) Error() string

Error returns the message of an Error.

func (Error) MessageType

func (m Error) MessageType() string

MessageType returns the Type of a message.

type Fill

type Fill struct {
	TradeID   int64      `json:"trade_id"`
	ProductID string     `json:"product_id"`
	Price     float64    `json:"price,string"`
	Size      float64    `json:"size,string"`
	OrderID   *uuid.UUID `json:"order_id,string"`
	CreatedAt *time.Time `json:"created_at,string"`
	Liquidity string     `json:"liquidity"`
	Fee       float64    `json:"fee,string"`
	Settled   bool       `json:"settled"`
	Side      string     `json:"side"`
}

A Fill represents a fill order.

type FillCollection

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

A FillCollection is an iterator of Fills.

func (*FillCollection) HasNext

func (c *FillCollection) HasNext() bool

HasNext determines if there is another Fill in this iterator.

func (*FillCollection) Next

func (c *FillCollection) Next() (*Fill, error)

Next gets the next Fill from the iterator.

type Heartbeat

type Heartbeat struct {
	Sequence    int64      `json:"sequence"`
	LastTradeID int64      `json:"last_trade_id"`
	Time        *time.Time `json:"time,string"`
	// contains filtered or unexported fields
}

A Heartbeat is channel message sent after subscribing to the heartbeat channel.

func (Heartbeat) MessageType

func (m Heartbeat) MessageType() string

MessageType returns the Type of a message.

type L2Update

type L2Update struct {
	Changes []Change `json:"changes"`
	// contains filtered or unexported fields
}

A L2Update is channel message sent after subscribing to the L2Update channel.

func (L2Update) MessageType

func (m L2Update) MessageType() string

MessageType returns the Type of a message.

func (*L2Update) UnmarshalJSON

func (m *L2Update) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a JSON bytes stream into an L2Update.

type Match

type Match struct {
	Time         *time.Time `json:"time,string"`
	Sequence     int64      `json:"sequence"`
	TradeID      int64      `json:"trade_id"`
	MakerOrderID *uuid.UUID `json:"maker_order_id,string"`
	TakerOrderID *uuid.UUID `json:"taker_order_id,string"`
	Size         float64    `json:"size,string"`
	Price        float64    `json:"price,string"`
	Side         string     `json:"side"`
	// contains filtered or unexported fields
}

A Match is channel message sent after subscribing to the match channel.

func (Match) MessageType

func (m Match) MessageType() string

MessageType returns the Type of a message.

type Message

type Message interface {
	MessageType() string
}

A Message allows for the retrieval of the type of the message.

type Order

type Order struct {
	Side        string      `json:"side"`
	ProductID   string      `json:"product_id"`
	Type        string      `json:"type,omitempty"`
	ClientOid   *uuid.UUID  `json:"client_oid,string,omitempty"`
	Stp         string      `json:"stp,omitempty"`
	Stop        string      `json:"stop,omitempty"`
	StopPrice   float64     `json:"stop_price,string,omitempty"`
	TimeInForce string      `json:"time_in_force,omitempty"`
	CancelAfter *DayHourMin `json:"cancel_after,string,omitempty"`
	Funds       float64     `json:"funds,string,omitempty"`

	// additional fields
	ID            *uuid.UUID `json:"id,string,omitempty"`
	Price         float64    `json:"price,string,omitempty"`
	Size          float64    `json:"size,string,omitempty"`
	PostOnly      bool       `json:"post_only,omitempty"`
	CreatedAt     *time.Time `json:"created_at,string,omitempty"`
	FillFees      float64    `json:"fill_fees,string,omitempty"`
	FilledSize    float64    `json:"filled_size,string,omitempty"`
	ExecutedValue float64    `json:"executed_value,string,omitempty"`
	Status        string     `json:"status,omitempty"`
	Settled       bool       `json:"settled,omitempty"`
}

An Order represents an order.

type OrderCollection

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

An OrderCollection is an iterator of Orders.

func (*OrderCollection) HasNext

func (c *OrderCollection) HasNext() bool

HasNext determines if there is another Order in this iterator.

func (*OrderCollection) Next

func (c *OrderCollection) Next() (*Order, error)

Next gets the next Order from the iterator.

type Report

type Report struct {
	Type      string     `json:"type"`
	StartDate *time.Time `json:"start_date,string"`
	EndDate   *time.Time `json:"end_date,string"`
	ProductID string     `json:"product_id,omitempty"`
	AccountID *uuid.UUID `json:"account_id,string,omitempty"`
	Format    string     `json:"format,omitempty"`
	Email     string     `json:"email,omitempty"`

	// response params
	ID          *uuid.UUID    `json:"id,string,omitempty"`
	Status      string        `json:"status,omitempty"`
	CreatedAt   *time.Time    `json:"created_at,string,omitempty"`
	CompletedAt *time.Time    `json:"completed_at,string,omitempty"`
	ExpiresAt   *time.Time    `json:"expires_at,string,omitempty"`
	FileURL     string        `json:"file_url,omitempty"`
	Params      *ReportParams `json:"params,omitempty"`
}

A Report represents a report.

type ReportParams

type ReportParams struct {
	StartDate *time.Time `json:"start_date,string,omitempty"`
	EndDate   *time.Time `json:"end_date,string,omitempty"`
}

A ReportParams stores the start and end date of a report response.

type Snapshot

type Snapshot struct {
	ProductID string `json:"product_id"`
	Bids      []Bid  `json:"bids"`
	Asks      []Ask  `json:"asks"`
	// contains filtered or unexported fields
}

A Snapshot is channel message sent after subscribing to the snapshot channel.

func (Snapshot) MessageType

func (m Snapshot) MessageType() string

MessageType returns the Type of a message.

func (*Snapshot) UnmarshalJSON

func (m *Snapshot) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a JSON bytes stream into an Snapshot.

type Subscription

type Subscription struct {
	Type       string   `json:"type"`
	Channels   []string `json:"channels"`
	ProductIDs []string `json:"product_ids"`
}

A Subscription stores information about a specific channel subscription. This is needed to initiate any channel communications.

type Ticker

type Ticker struct {
	TradeID   int64      `json:"trade_id"`
	Sequence  int64      `json:"sequence"`
	Time      *time.Time `json:"time,string"`
	ProductID string     `json:"product_id"`
	Price     float64    `json:"price,string"`
	Side      string     `json:"side"`
	LastSize  float64    `json:"last_size,string"`
	BestBid   float64    `json:"best_bid,string"`
	BestAsk   float64    `json:"best_ask,string"`
	// contains filtered or unexported fields
}

A Ticker is channel message sent after subscribing to the ticker channel.

func (Ticker) MessageType

func (m Ticker) MessageType() string

MessageType returns the Type of a message.

type UUIDCollection

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

An UUIDCollection is an iterator of UUIDs.

func (*UUIDCollection) HasNext

func (c *UUIDCollection) HasNext() bool

HasNext determines if there is another UUID in this iterator.

func (*UUIDCollection) Next

func (c *UUIDCollection) Next() (*uuid.UUID, error)

Next gets the next UUID from the iterator.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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