protocol

package
v0.0.0-...-499f638 Latest Latest
Warning

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

Go to latest
Published: May 3, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderbookName = "orderbook"
)

Variables

View Source
var (
	OrderbookProtocol = &protocols.Spec{
		Name:       OrderbookName,
		Version:    42,
		MaxMsgSize: 1024,
		Messages: []interface{}{
			&OrderbookHandshake{},
			&OrderbookMsg{},
		},
	}
)

Functions

func NewProtocol

func NewProtocol(inC <-chan interface{}, quitC <-chan struct{}, orderbookEngine *orderbook.Engine) *p2p.Protocol

create the protocol with the protocols extension

func NewService

func NewService(inC <-chan interface{}, quitC <-chan struct{}, orderbookEngine *orderbook.Engine) func(ctx *node.ServiceContext) (node.Service, error)

NewService: wrapper function for servicenode to start the service, both APIs and Protocols

Types

type OrderbookAPI

type OrderbookAPI struct {
	V      int
	Engine *orderbook.Engine
}

remember that API structs to be offered MUST be exported

func NewOrderbookAPI

func NewOrderbookAPI(v int, orderbookEngine *orderbook.Engine) *OrderbookAPI

func (*OrderbookAPI) GetBestAskList

func (api *OrderbookAPI) GetBestAskList(pairName string) []map[string]string

func (*OrderbookAPI) GetBestBidList

func (api *OrderbookAPI) GetBestBidList(pairName string) []map[string]string

func (*OrderbookAPI) GetOrder

func (api *OrderbookAPI) GetOrder(pairName, orderID string) map[string]string

func (*OrderbookAPI) Version

func (api *OrderbookAPI) Version() (int, error)

Version : return version

type OrderbookHandler

type OrderbookHandler struct {
	Engine *orderbook.Engine
	Peer   *protocols.Peer
	InC    <-chan interface{}
	QuitC  <-chan struct{}
}

the protocols abstraction enables use of an external handler function

type OrderbookHandshake

type OrderbookHandshake struct {
	Nick string
	V    uint
}

type OrderbookMsg

type OrderbookMsg struct {
	PairName  string
	OrderID   string
	Price     string
	Quantity  string
	Side      string
	Timestamp uint64
	TradeID   string
	Type      string
}

func NewOrderbookMsg

func NewOrderbookMsg(quote map[string]string) (*OrderbookMsg, error)

func (*OrderbookMsg) ToQuote

func (msg *OrderbookMsg) ToQuote() map[string]string

type OrderbookService

type OrderbookService struct {
	V      int
	Engine *orderbook.Engine
	// contains filtered or unexported fields
}

the service we want to offer on the node it must implement the node.Service interface

func (*OrderbookService) APIs

func (service *OrderbookService) APIs() []rpc.API

APIs : api service specify API structs that carry the methods we want to use

func (*OrderbookService) Protocols

func (service *OrderbookService) Protocols() []p2p.Protocol

these are needed to satisfy the node.Service interface in this example they do nothing

func (*OrderbookService) Start

func (service *OrderbookService) Start(srv *p2p.Server) error

func (*OrderbookService) Stop

func (service *OrderbookService) Stop() error

Jump to

Keyboard shortcuts

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