streaming

package
v1.0.31 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package streaming implements a client for the Luno Streaming API.

Example:

c, err := streaming.Dial(keyID, keySecret, "XBTZAR")
if err != nil {
	log.Fatal(err)
}
defer c.Close()

for {
	seq, bids, asks := c.OrderBookSnapshot()
	log.Printf("%d: %v %v\n", seq, bids[0], asks[0])
	time.Sleep(time.Minute)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

func Dial

func Dial(keyID, keySecret, pair string, onUpdate func(Snapshot), opts ...DialOption) (*Conn, error)

Dial initiates a connection to the streaming service and starts processing data for the given market pair. The connection will automatically reconnect on error.

func (*Conn) Close

func (c *Conn) Close()

Close the stream. After calling this the client will stop receiving new updates and the results of querying the Conn struct (Snapshot, Status...) will be zeroed values.

func (*Conn) IsClosed

func (c *Conn) IsClosed() bool

IsClosed returns true if the Conn has been closed.

func (*Conn) OrderBookSnapshot

func (c *Conn) OrderBookSnapshot() (
	int64, []luno.OrderBookEntry, []luno.OrderBookEntry)

OrderBookSnapshot returns the latest order book. Deprecated at v0.0.8, use Snapshot().

func (*Conn) Snapshot

func (c *Conn) Snapshot() Snapshot

Snapshot returns the current state of the streamed data.

func (*Conn) Status

func (c *Conn) Status() luno.Status

Status returns the currenct status of the streaming connection.

type ConnectCallback

type ConnectCallback func(*Conn)

type CreateUpdate

type CreateUpdate struct {
	OrderID string          `json:"order_id"`
	Type    string          `json:"type"`
	Price   decimal.Decimal `json:"price,string"`
	Volume  decimal.Decimal `json:"volume,string"`
}

type DeleteUpdate

type DeleteUpdate struct {
	OrderID string `json:"order_id"`
}

type DialOption

type DialOption func(*Conn)

func WithConnectCallback

func WithConnectCallback(fn ConnectCallback) DialOption

WithConnectCallback returns an options which sets a callback function for when the connection is fully initialised and the orderbook has been set up.

func WithUpdateCallback

func WithUpdateCallback(fn UpdateCallback) DialOption

WithUpdateCallback returns an options which sets a callback function for streaming updates. Each update will first be applied to the order book, and then passed to the callback function.

type Snapshot

type Snapshot struct {
	Sequence   int64
	Bids, Asks []luno.OrderBookEntry
	Status     luno.Status
	LastTrade  TradeUpdate
}

type StatusUpdate

type StatusUpdate struct {
	Status string `json:"status"`
}

type TradeUpdate

type TradeUpdate struct {
	Base    decimal.Decimal `json:"base,string"`
	Counter decimal.Decimal `json:"counter,string"`
	OrderID string          `json:"order_id"`
}

type Update

type Update struct {
	Sequence     int64          `json:"sequence,string"`
	TradeUpdates []*TradeUpdate `json:"trade_updates"`
	CreateUpdate *CreateUpdate  `json:"create_update"`
	DeleteUpdate *DeleteUpdate  `json:"delete_update"`
	StatusUpdate *StatusUpdate  `json:"status_update"`
	Timestamp    int64          `json:"timestamp"`
}

type UpdateCallback

type UpdateCallback func(Update)

Jump to

Keyboard shortcuts

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