kd

package module
v0.0.0-...-eb9b55e Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: Unlicense Imports: 19 Imported by: 0

README

Configuration

kd requires a .config.json file in your process's root directory with the following structure:

{
    "kd": {
        "getWebSocketsTokenOrigin": "https://api.kraken.com",
        "getWebSocketsTokenRoute": "/0/private/GetWebSocketsToken",
        "webSocketProtocol": "wss",
        "webSocketOrigin": "https://ws.kraken.com",
        "webSocketURLv2": "wss://ws.kraken.com/v2",
        "authWebSocketOrigin": "https://ws-auth.kraken.com",
        "authWebSocketURLv2": "wss://ws-auth.kraken.com/v2",
        "publicKey": "",
        "privateKey": ""
    }
}

If required, replace publicKey and privateKey with your actual Kraken API credentials. Alternatively, you can omit privateKey and set your process's KRAKEN_PRIVATE_KEY environment variable.

There are three helpers for fetching tokens:

func MustNewWebSocketTokenFromCfg() string
func NewWebSocketTokenFromCfg() (string, time.Time, error)
func NewWebSocketToken(public, private string) (string, time.Time, error)

Introduction

This document outlines the core concepts of the kd library, focusing on its single responsibility subscription model and the key interfaces and types for message handling.

Single Responsibility Subscription Model

The kd library employs a single responsibility principle for its subscriptions. Each subscription is designed to handle a specific type of IncomingMessage and cease on any error. A subscription is a websocket connection to a Kraken channel.

Core Interfaces

IncomingMessage

The IncomingMessage interface defines the contract for messages received.

type IncomingMessage interface {
	IsSnapshot() bool
	IsUpdate() bool
	IsValid() bool
	Error() error
}
  • IsValid() bool: true the message will be passed to IncomingMessageHandler.
  • Error() error: any non nil error will cause Subscription[T] to end.
OutgoingMessage

The OutgoingMessage interface defines the contract for messages sent.

type OutgoingMessage interface {
	SetToken(token string)
}
  • SetToken(token string): Sets an authentication token for the message.
IncomingMessageHandler

The IncomingMessageHandler interface defines the contract for incoming message handlers.

type IncomingMessageHandler[T IncomingMessage] interface {
	Handle(message T) error
	Close()
}
  • Handle(message T) error: any non nil error will cause Subscription[T] to end.
  • Close(): called by Subscription[T] when it ends.

Core Types

Subscription[T IncomingMessage]

The Subscription[T] type maintains a connection with Kraken and sends valid T messages to it's IncomingMessageHandler.

  • sends an OutgoingUnsubscribeMessage and calls IncomingMessageHandler.Close() on error.
func (this *Subscription[T]) Send(message OutgoingMessage) error
func (this *Subscription[T]) ErrCh() <-chan error
BaseOutgoingSubscriptionMessage and BaseAuthOutgoingSubscriptionMessage

The BaseOutgoingSubscriptionMessage and BaseAuthOutgoingSubscriptionMessage type both implement OutgoingSubscriptionMessage.

func NewBaseSubOut(params ChannelParams) BaseOutgoingSubscriptionMessage
func NewBaseAuthSubOut(params ChannelParams) BaseAuthOutgoingSubscriptionMessage
  • wraps Out for channel subscription messages.
  • can be used to make any subscription.
BaseIncomingChannelMessage[D any]

The BaseIncomingChannelMessage[D] type is used to receive channel messages.

func NewBaseIncomingChannelMessage[D any](scope string) BaseIncomingChannelMessage[D]
  • wraps In with scope for channel messages.
  • scope filters out heartbeats and other admin messages.
  • D is the data field payload type.
In and Out

These are used for all incoming and outgoing messages. You can use them too.

Helpers

kd provides some helpers for basics like candles, order book, account balances and market orders. These may or may not change and are opinionated.

// There's non channel messages you probably care about.
// IncomingAddOrderMessage wraps In with AddOrderResult.
type IncomingAddOrderMessage struct {
	In[any, AddOrderResult]
}

func NewOutMarketBuyOrder(symbol string, quote float64) *OutgoingMarketBuyOrder
func NewOutMarketSellOrder(symbol string, base float64) *OutgoingMarketSellOrder

// Because naming things is hard.
type Channel[T any] struct {
	OutCh <-chan T
	ErrCh <-chan error
	Send  func(message OutgoingMessage) error
	Close func()
}

func NewSubExecution(ctx context.Context, wg *sync.WaitGroup) (*Channel[[]string], error) {
	handler := NewExecutionSubscriptionHandler(ctx)
	message := NewOutExecutionSubscriptionMessage()
	return NewSubChannel(ctx, wg, message, handler, handler.outCh)
}

Note:
If you use the provided helpers, you may ignore a channel’s ErrCh, but you must read from OutCh—otherwise, the subscription's receive will block until the context is canceled.

Documentation

Index

Constants

View Source
const (
	Spot = "spot"
	Earn = "earn"

	Main     = "main"
	Flex     = "flex"
	Bonded   = "bonded"
	Flexible = "flexible"
	Liquid   = "liquid"
	Locked   = "locked"
	Closed   = "closed"
)

Variables

This section is empty.

Functions

func AskCmp

func AskCmp(a, b Level) int

func BalDescCmp

func BalDescCmp(a, b Asset) int

func BidCmp

func BidCmp(a, b Level) int

func Epoch

func Epoch(duration time.Duration) time.Time

Epoch returns the next boundary after the current time.

func IsSnapshot

func IsSnapshot(channel, target, typ string) bool

func IsUpdate

func IsUpdate(channel, target, typ string) bool

func IsValid

func IsValid(channel, target string) bool

func MustNewWebSocketTokenFromCfg

func MustNewWebSocketTokenFromCfg() string

MustNewWebSocketTokenFromCfg fetches a new WebSocket token using the global config. Panics on error.

func NewErrorOrNil

func NewErrorOrNil(message string) error

func NewTicker

func NewTicker(ctx context.Context, epoch time.Time, duration time.Duration, outCh chan time.Time)

func NewWebSocketToken

func NewWebSocketToken(public, private string) (string, time.Time, error)

NewWebSocketToken fetches a new WebSocket token using the provided public and private keys. Returns the token and its approximate expiration time.

func NewWebSocketTokenFromCfg

func NewWebSocketTokenFromCfg() (string, time.Time, error)

NewWebSocketTokenFromCfg fetches a new WebSocket token using the global config. Returns the token and its approximate expiration time.

func WithDepth

func WithDepth(depth int) func(*ChannelParams)

func WithSymbols

func WithSymbols(symbols []string) func(*ChannelParams)

Types

type Account

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

func NewAccount

func NewAccount() *Account

NewAccount creates a new Account instance.

func (*Account) Add

func (this *Account) Add(entry Entry)

func (*Account) Balance

func (this *Account) Balance(asset string) float64

Balance returns the balance of the specified asset's main spot wallet as a float64.

func (*Account) List

func (this *Account) List() []Asset

func (*Account) Set

func (this *Account) Set(asset Asset)

type AddOrderResult

type AddOrderResult struct {
	OrderID      string   `json:"order_id"`
	ClOrdID      string   `json:"cl_ord_id"`
	OrderUserRef int      `json:"order_userref"`
	Warnings     []string `json:"warnings"`
}

AddOrderResult contains the details for a successfully placed order.

func (AddOrderResult) IsZero

func (this AddOrderResult) IsZero() bool

type Asset

type Asset struct {
	Asset      string   `json:"asset"`
	AssetClass string   `json:"asset_class"`
	Balance    Decimal  `json:"balance"`
	Wallets    []Wallet `json:"wallets"`
}

Asset represents a financial asset stored within an account with its balance and associated wallets.

func NewAssetFrom

func NewAssetFrom(entry Entry) Asset

type BalanceSubscriptionHandler

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

func NewBalanceSubscriptionHandler

func NewBalanceSubscriptionHandler(ctx context.Context) *BalanceSubscriptionHandler

func (*BalanceSubscriptionHandler) Close

func (this *BalanceSubscriptionHandler) Close()

func (*BalanceSubscriptionHandler) Handle

func (*BalanceSubscriptionHandler) OutCh

func (this *BalanceSubscriptionHandler) OutCh() <-chan *Account

type BaseAuthOutgoingSubscriptionMessage

type BaseAuthOutgoingSubscriptionMessage struct {
	BaseOutgoingSubscriptionMessage
}

BaseAuthOutgoingSubscriptionMessage wraps BaseOutgoingSubscriptionMessage for authenticated channel subscription messages.

func (*BaseAuthOutgoingSubscriptionMessage) GetToken

func (*BaseAuthOutgoingSubscriptionMessage) Origin

func (*BaseAuthOutgoingSubscriptionMessage) SetToken

func (this *BaseAuthOutgoingSubscriptionMessage) SetToken(token string)

func (*BaseAuthOutgoingSubscriptionMessage) Url

type BaseIncomingChannelMessage

type BaseIncomingChannelMessage[D any] struct {
	In[D, any]
	Scope string `json:"-"`
}

BaseIncomingChannelMessage wraps In with Scope for channel messages.

func NewBaseIncomingChannelMessage

func NewBaseIncomingChannelMessage[D any](scope string) BaseIncomingChannelMessage[D]

func (*BaseIncomingChannelMessage[D]) Error

func (this *BaseIncomingChannelMessage[D]) Error() error

func (*BaseIncomingChannelMessage[D]) IsSnapshot

func (this *BaseIncomingChannelMessage[D]) IsSnapshot() bool

func (*BaseIncomingChannelMessage[D]) IsUpdate

func (this *BaseIncomingChannelMessage[D]) IsUpdate() bool

func (*BaseIncomingChannelMessage[D]) IsValid

func (this *BaseIncomingChannelMessage[D]) IsValid() bool

type BaseOutgoingSubscriptionMessage

type BaseOutgoingSubscriptionMessage struct {
	Out[ChannelParams]
}

BaseOutgoingSubscriptionMessage wraps Out for channel subscription messages.

func (*BaseOutgoingSubscriptionMessage) GetToken

func (this *BaseOutgoingSubscriptionMessage) GetToken() string

func (*BaseOutgoingSubscriptionMessage) Origin

func (this *BaseOutgoingSubscriptionMessage) Origin() string

func (*BaseOutgoingSubscriptionMessage) Protocol

func (this *BaseOutgoingSubscriptionMessage) Protocol() string

func (*BaseOutgoingSubscriptionMessage) SetToken

func (this *BaseOutgoingSubscriptionMessage) SetToken(token string)

func (*BaseOutgoingSubscriptionMessage) UnsubscribeMessage

func (this *BaseOutgoingSubscriptionMessage) UnsubscribeMessage() *OutgoingUnsubscribeMessage

func (*BaseOutgoingSubscriptionMessage) Url

type Binder

type Binder struct {
	Symbol string `json:"symbol"`

	sync.Mutex
	Page
	// contains filtered or unexported fields
}

func NewBinder

func NewBinder(symbol string, depth int) *Binder

func (*Binder) Update

func (this *Binder) Update(update Page)

func (*Binder) UpdateSide

func (this *Binder) UpdateSide(current []Level, updates []Level, cmp func(a, b Level) int) []Level

type BookSubscriptionHandler

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

func NewBookSubscriptionHandler

func NewBookSubscriptionHandler(ctx context.Context, symbol string, depth int) *BookSubscriptionHandler

func (*BookSubscriptionHandler) Close

func (this *BookSubscriptionHandler) Close()

func (*BookSubscriptionHandler) Handle

func (*BookSubscriptionHandler) OutCh

func (this *BookSubscriptionHandler) OutCh() <-chan *Binder

type Candle

type Candle struct {
	StartTime  time.Time
	EndTime    time.Time
	Open       Decimal
	High       Decimal
	Low        Decimal
	Close      Decimal
	Volume     Decimal
	TradeCount int
}

Candle represents a OHLCV candle.

func NewCandle

func NewCandle(startTime time.Time, duration time.Duration) *Candle

NewCandle creates a new candle with the given start time and duration.

type CandleBuilder

type CandleBuilder struct {
	Epoch    time.Time
	Duration time.Duration
	Candle   *Candle
}

CandleBuilder builds candles.

func NewCandleBuilder

func NewCandleBuilder(duration time.Duration) *CandleBuilder

NewCandleBuilder creates a new CandleBuilder for the given duration. The initial epoch is set to the next boundary after the current time. Trades with timestamps before this epoch will be discarded by Sink.

func (*CandleBuilder) Cooked

func (this *CandleBuilder) Cooked() (completed *Candle)

Cooked checks if the current candle's EndTime has passed and, if so, finalizes and returns the candle if it contains trades. It then initializes a new candle for the next period. This method is intended to be called periodically (e.g., by a ticker).

func (*CandleBuilder) Sink

func (this *CandleBuilder) Sink(trade Trade) (completed *Candle)

Sink returns the completed candle if a candle was finalized, otherwise nil.

func (*CandleBuilder) Ticker

func (this *CandleBuilder) Ticker(ctx context.Context) <-chan time.Time

Ticker returns a read-only channel that emits a time.Time value at precisely one second after each Candle's scheduled completion.

type Channel

type Channel[T any] struct {
	OutCh <-chan T
	ErrCh <-chan error
	Send  func(message OutgoingMessage) error
	Close func()
}

func NewSubBalance

func NewSubBalance(ctx context.Context, wg *sync.WaitGroup) (*Channel[*Account], error)

func NewSubBook

func NewSubBook(ctx context.Context, wg *sync.WaitGroup, symbol string, depth int) (*Channel[*Binder], error)

func NewSubChannel

func NewSubChannel[M IncomingMessage, T any](ctx context.Context, wg *sync.WaitGroup, message OutgoingSubscriptionMessage, handler IncomingMessageHandler[M], outCh <-chan T) (*Channel[T], error)

func NewSubExecution

func NewSubExecution(ctx context.Context, wg *sync.WaitGroup) (*Channel[[]string], error)

func NewSubTrade

func NewSubTrade(ctx context.Context, wg *sync.WaitGroup, symbol string, candleDuration time.Duration) (*Channel[*Candle], error)

type ChannelParams

type ChannelParams struct {
	Channel     string   `json:"channel,omitempty"`
	Symbol      []string `json:"symbol,omitempty"`
	Depth       int      `json:"depth,omitempty"`
	Snapshot    bool     `json:"snapshot,omitempty"`
	SnapTrades  bool     `json:"snap_trades,omitempty"`
	SnapOrders  bool     `json:"snap_orders,omitempty"`
	OrderStatus bool     `json:"order_status,omitempty"`
	RateCounter bool     `json:"ratecounter,omitempty"`
	Users       string   `json:"users,omitempty"` // If all, events for master and subaccounts are streamed, otherwise only master account events are published. No snapshot is provided.
	Token       string   `json:"token,omitempty"`
}

type Conditional

type Conditional struct {
	OrderType        string  `json:"order_type,omitempty"`
	LimitPrice       float64 `json:"limit_price,omitempty"`
	LimitPriceType   string  `json:"limit_price_type,omitempty"`
	TriggerPrice     float64 `json:"trigger_price,omitempty"`
	TriggerPriceType string  `json:"trigger_price_type,omitempty"`
}

Conditional type for secondary close orders.

func (Conditional) IsZero

func (this Conditional) IsZero() bool

type Config

type Config struct {
	GetWebSocketsTokenOrigin string `json:"getWebSocketsTokenOrigin"`
	GetWebSocketsTokenRoute  string `json:"getWebSocketsTokenRoute"`
	WebSocketProtocol        string `json:"webSocketProtocol"`
	WebSocketOrigin          string `json:"webSocketOrigin"`
	WebSocketURLv2           string `json:"webSocketURLv2"`
	AuthWebSocketOrigin      string `json:"authWebSocketOrigin"`
	AuthWebSocketURLv2       string `json:"authWebSocketURLv2"`

	PublicKey  string `json:"publicKey"`
	PrivateKey string `json:"privateKey"`
}

func (Config) MarshalJSON

func (this Config) MarshalJSON() ([]byte, error)

func (Config) String

func (this Config) String() string

type Decimal

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

func (*Decimal) Add

func (this *Decimal) Add(that Decimal)

func (*Decimal) Cmp

func (this *Decimal) Cmp(that Decimal) int

func (*Decimal) Float64

func (this *Decimal) Float64() float64

func (*Decimal) GreaterThan

func (this *Decimal) GreaterThan(that Decimal) bool

func (*Decimal) IsZero

func (this *Decimal) IsZero() bool

func (*Decimal) LessThan

func (this *Decimal) LessThan(that Decimal) bool

func (*Decimal) MarshalJSON

func (this *Decimal) MarshalJSON() ([]byte, error)

func (*Decimal) Set

func (this *Decimal) Set(that Decimal)

func (*Decimal) String

func (this *Decimal) String() string

func (*Decimal) UnmarshalJSON

func (this *Decimal) UnmarshalJSON(data []byte) error

type Entry

type Entry struct {
	Asset      string    `json:"asset"`
	AssetClass string    `json:"asset_class"`
	Amount     Decimal   `json:"amount"`
	Balance    Decimal   `json:"balance"`
	Fee        Decimal   `json:"fee"`
	LedgerID   string    `json:"ledger_id"`
	RefID      string    `json:"ref_id"`
	Timestamp  time.Time `json:"timestamp"`
	Type       string    `json:"type"`
	Subtype    string    `json:"subtype"`
	Category   string    `json:"category"`
	WalletType string    `json:"wallet_type"`
	WalletID   string    `json:"wallet_id"`
}

Entry represents a single wallet ledger entry.

type ExecutionSubscriptionHandler

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

func NewExecutionSubscriptionHandler

func NewExecutionSubscriptionHandler(ctx context.Context) *ExecutionSubscriptionHandler

func (*ExecutionSubscriptionHandler) Close

func (this *ExecutionSubscriptionHandler) Close()

func (*ExecutionSubscriptionHandler) Handle

func (*ExecutionSubscriptionHandler) OutCh

func (this *ExecutionSubscriptionHandler) OutCh() <-chan []string

type In

type In[D, R any] struct {
	Channel string    `json:"channel,omitempty"`
	Type    string    `json:"type,omitempty"`
	Data    D         `json:"data,omitempty,omitzero"`
	User    string    `json:"user,omitempty"`
	Method  string    `json:"method,omitempty"`
	Result  R         `json:"result,omitempty,omitzero"`
	Success bool      `json:"success,omitempty"`
	ReqID   uint32    `json:"req_id,omitempty"`
	TimeIn  time.Time `json:"time_in,omitzero"`
	TimeOut time.Time `json:"time_out,omitzero"`
	Err     string    `json:"error,omitempty"`
}

In is a generic websocket receive message for any connection.

type IncomingAddOrderMessage

type IncomingAddOrderMessage struct {
	In[any, AddOrderResult]
}

IncomingAddOrderMessage wraps In with AddOrderResult.

func (*IncomingAddOrderMessage) Error

func (this *IncomingAddOrderMessage) Error() error

func (*IncomingAddOrderMessage) IsSnapshot

func (this *IncomingAddOrderMessage) IsSnapshot() bool

func (*IncomingAddOrderMessage) IsUpdate

func (this *IncomingAddOrderMessage) IsUpdate() bool

func (*IncomingAddOrderMessage) IsValid

func (this *IncomingAddOrderMessage) IsValid() bool

type IncomingBalanceChannelMessage

type IncomingBalanceChannelMessage struct {
	BaseIncomingChannelMessage[json.RawMessage]
}

IncomingBalanceChannelMessage wraps BaseIncomingChannelMessage for balances channel with RawMessage for flexible decoding.

func NewIncomingBalanceChannelMessage

func NewIncomingBalanceChannelMessage() *IncomingBalanceChannelMessage

type IncomingBalanceChannelSnapshotMessage

type IncomingBalanceChannelSnapshotMessage struct {
	BaseIncomingChannelMessage[[]Asset]
}

IncomingBalanceChannelSnapshotMessage wraps BaseIncomingChannelMessage for balances channel with []Asset.

func NewIncomingBalanceChannelSnapshotMessage

func NewIncomingBalanceChannelSnapshotMessage() *IncomingBalanceChannelSnapshotMessage

type IncomingBalanceChannelUpdateMessage

type IncomingBalanceChannelUpdateMessage struct {
	BaseIncomingChannelMessage[[]Entry]
}

IncomingBalanceChannelUpdateMessage wraps BaseIncomingChannelMessage for balances channel with []Entry.

func NewIncomingBalanceChannelUpdateMessage

func NewIncomingBalanceChannelUpdateMessage() *IncomingBalanceChannelUpdateMessage

type IncomingBookChannelMessage

type IncomingBookChannelMessage struct {
	BaseIncomingChannelMessage[[]Page]
}

IncomingBookChannelMessage wraps BaseIncomingChannelMessage for the book channel.

func NewIncomingBookChannelMessage

func NewIncomingBookChannelMessage() *IncomingBookChannelMessage

type IncomingMessage

type IncomingMessage interface {
	IsSnapshot() bool
	IsUpdate() bool
	IsValid() bool
	Error() error
}

type IncomingMessageHandler

type IncomingMessageHandler[T IncomingMessage] interface {
	Handle(message T) error
	Close()
}

type IncomingTradeChannelMessage

type IncomingTradeChannelMessage struct {
	BaseIncomingChannelMessage[[]Trade]
}

IncomingTradeChannelMessage wraps BaseIncomingChannelMessage for the trade channel.

func NewIncomingTradeChannelMessage

func NewIncomingTradeChannelMessage() *IncomingTradeChannelMessage

type Level

type Level struct {
	Price Decimal `json:"price"`
	Qty   Decimal `json:"qty"`
}

type OrderParams

type OrderParams struct {
	OrderType      string      `json:"order_type,omitempty"`
	Side           string      `json:"side,omitempty"`
	OrderQty       float64     `json:"order_qty,omitempty"`
	Symbol         string      `json:"symbol,omitempty"`
	LimitPrice     float64     `json:"limit_price,omitempty"`
	LimitPriceType string      `json:"limit_price_type,omitempty"`
	Triggers       Triggers    `json:"triggers,omitzero"`
	TimeInForce    string      `json:"time_in_force,omitempty"`
	Margin         bool        `json:"margin,omitempty"`
	PostOnly       bool        `json:"post_only,omitempty"`
	ReduceOnly     bool        `json:"reduce_only,omitempty"`
	EffectiveTime  time.Time   `json:"effective_time,omitzero"`
	ExpireTime     time.Time   `json:"expire_time,omitzero"`
	Deadline       time.Time   `json:"deadline,omitzero"`
	ClOrdID        string      `json:"cl_ord_id,omitempty"`
	OrderUserRef   int         `json:"order_userref,omitempty"`
	Conditional    Conditional `json:"conditional,omitzero"`
	DisplayQty     float64     `json:"display_qty,omitempty"`
	FeePreference  string      `json:"fee_preference,omitempty"`
	NoMPP          bool        `json:"no_mpp,omitempty"`
	STPType        string      `json:"stp_type,omitempty"`
	CashOrderQty   float64     `json:"cash_order_qty,omitempty"`
	Validate       bool        `json:"validate,omitempty"`
	SenderSubID    string      `json:"sender_sub_id,omitempty"`
	Token          string      `json:"token,omitempty"`
}

type Out

type Out[P any] struct {
	Method string `json:"method,omitempty"`
	Params P      `json:"params,omitempty,omitzero"`
	ReqID  uint32 `json:"req_id,omitempty"`
	Users  string `json:"users,omitempty"` // If all, events for master and subaccounts are streamed, otherwise only master account events are published. No snapshot is provided.
}

Out is a generic websocket send message for any channel.

func NewOut

func NewOut[P any](method string, params P) Out[P]

type OutgoingBalanceSubscriptionMessage

type OutgoingBalanceSubscriptionMessage struct {
	BaseAuthOutgoingSubscriptionMessage
}

OutgoingBalanceSubscriptionMessage wraps BaseAuthOutgoingSubscriptionMessage for balances channel.

func NewOutBalanceSubscriptionMessage

func NewOutBalanceSubscriptionMessage(snapshot bool) *OutgoingBalanceSubscriptionMessage

type OutgoingBookSubscriptionMessage

type OutgoingBookSubscriptionMessage struct {
	BaseOutgoingSubscriptionMessage
}

OutgoingBookSubscriptionMessage wraps BaseOutgoingSubscriptionMessage for book channel.

func NewOutBookSubscriptionMessage

func NewOutBookSubscriptionMessage(symbol string, depth int, snapshot bool) *OutgoingBookSubscriptionMessage

type OutgoingExecutionSubscriptionMessage

type OutgoingExecutionSubscriptionMessage struct {
	BaseAuthOutgoingSubscriptionMessage
}

OutgoingExecutionSubscriptionMessage wraps BaseAuthOutgoingSubscriptionMessage for executions channel.

func NewOutExecutionSubscriptionMessage

func NewOutExecutionSubscriptionMessage() *OutgoingExecutionSubscriptionMessage

type OutgoingMarketBuyOrder

type OutgoingMarketBuyOrder struct {
	Out[OrderParams]
}

OutgoingMarketBuyOrder wraps Out for market buy orders.

func NewOutMarketBuyOrder

func NewOutMarketBuyOrder(symbol string, quote float64) *OutgoingMarketBuyOrder

func (*OutgoingMarketBuyOrder) SetToken

func (this *OutgoingMarketBuyOrder) SetToken(token string)

type OutgoingMarketSellOrder

type OutgoingMarketSellOrder struct {
	Out[OrderParams]
}

OutgoingMarketSellOrder wraps Out for market sell orders.

func NewOutMarketSellOrder

func NewOutMarketSellOrder(symbol string, base float64) *OutgoingMarketSellOrder

func (*OutgoingMarketSellOrder) SetToken

func (this *OutgoingMarketSellOrder) SetToken(token string)

type OutgoingMessage

type OutgoingMessage interface {
	SetToken(token string)
}

type OutgoingSubscriptionMessage

type OutgoingSubscriptionMessage interface {
	OutgoingMessage
	GetToken() string

	UnsubscribeMessage() *OutgoingUnsubscribeMessage
	Protocol() string
	Origin() string
	Url() string
}

type OutgoingTradeSubscriptionMessage

type OutgoingTradeSubscriptionMessage struct {
	BaseOutgoingSubscriptionMessage
}

OutgoingTradeSubscriptionMessage wraps BaseOutgoingSubscriptionMessage for trade channel.

func NewOutTradeSubscriptionMessage

func NewOutTradeSubscriptionMessage(symbol string, snapshot bool) *OutgoingTradeSubscriptionMessage

type OutgoingUnsubscribeMessage

type OutgoingUnsubscribeMessage struct {
	Out[ChannelParams]
}

OutgoingUnsubscribeMessage wraps Out for unsubscribing from any channel.

func NewOutUnsubscribeMessage

func NewOutUnsubscribeMessage(channel string, opts ...func(*ChannelParams)) *OutgoingUnsubscribeMessage

func (*OutgoingUnsubscribeMessage) SetToken

func (this *OutgoingUnsubscribeMessage) SetToken(token string)

type Page

type Page struct {
	Timestamp time.Time `json:"timestamp"`

	Asks     []Level `json:"asks"` // price ascending
	Bids     []Level `json:"bids"` // price descending
	Checksum uint32  `json:"checksum"`
}

func NewPage

func NewPage(depth int) Page

type Subscription

type Subscription[T IncomingMessage] struct {
	// contains filtered or unexported fields
}

func (*Subscription[T]) ErrCh

func (this *Subscription[T]) ErrCh() <-chan error

func (*Subscription[T]) Send

func (this *Subscription[T]) Send(message OutgoingMessage) error

type Trade

type Trade struct {
	Symbol    string    `json:"symbol"`
	Side      string    `json:"side"`
	Qty       Decimal   `json:"qty"`
	Price     Decimal   `json:"price"`
	OrdType   string    `json:"ord_type"`
	TradeID   int       `json:"trade_id"`
	Timestamp time.Time `json:"timestamp"`
}

Trade represents a single trade event.

type TradeSubscriptionHandler

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

func NewTradeSubscriptionHandler

func NewTradeSubscriptionHandler(ctx context.Context, candleDuration time.Duration) *TradeSubscriptionHandler

func (*TradeSubscriptionHandler) Close

func (this *TradeSubscriptionHandler) Close()

func (*TradeSubscriptionHandler) Handle

func (*TradeSubscriptionHandler) OutCh

func (this *TradeSubscriptionHandler) OutCh() <-chan *Candle

type Triggers

type Triggers struct {
	Reference string  `json:"reference,omitempty"`
	Price     float64 `json:"price,omitempty"`
	PriceType string  `json:"price_type,omitempty"`
}

Triggers type for triggered orders.

func (Triggers) IsZero

func (this Triggers) IsZero() bool

type Wallet

type Wallet struct {
	Balance Decimal `json:"balance"`
	Type    string  `json:"type"`
	ID      string  `json:"id"`

	Ledger []Entry `json:"ledger,omitempty"`
}

Wallet represents a wallet holding an asset.

func NewWalletFrom

func NewWalletFrom(entry Entry) Wallet

func (*Wallet) TryAdd

func (this *Wallet) TryAdd(entry Entry) bool

Jump to

Keyboard shortcuts

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