soupbintcp

package
v0.0.0-...-1291686 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: MIT Imports: 10 Imported by: 0

README

SoupBinTCP

This package implements Nasdaq's SoupBinTCP 4.1 protocol.

https://nasdaqtrader.com/content/technicalsupport/specifications/tradingproducts/SoupBinTCP41.pdf

Currently the client should work, the server implementation is stil work in progress.

Documentation

Index

Constants

View Source
const (
	PacketTypeLoginRequest   = 'L'
	PacketLengthLoginRequest = 52

	PacketTypeLoginAccepted   = 'A'
	PacketLengthLoginAccepted = 31

	PacketTypeLoginRejected   = 'J'
	PacketLengthLoginRejected = 2

	PacketTypeLogoutRequest   = 'O'
	PacketLengthLogoutRequest = 1

	PacketTypeClientHeartbeat   = 'R'
	PacketLengthClientHeartbeat = 1

	PacketTypeServerHeartbeat   = 'H'
	PacketLengthServerHeartbeat = 1

	PacketTypeEndOfSession   = 'Z'
	PacketLengthEndOfSession = 1

	// Variable length packets
	PacketTypeSequencedData   = 'S'
	PacketTypeUnsequencedData = 'U'
	PacketTypeDebug           = '+'

	LoginRejectedNotAuthorized      = 'A'
	LoginRejectedSessionUnavailable = 'S'
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(addr string, opts ...ClientOption) *Client

NewClient creates a new soupbintcp client. The default parameters can be configured using ClientOptions passed in as parameters

func (*Client) CurrentSequenceNumber

func (c *Client) CurrentSequenceNumber() uint64

CurrentSequenceNumber returns the client's current sequence number

func (*Client) CurrentSession

func (c *Client) CurrentSession() string

CurrentSession returns the current session id

func (*Client) Login

func (c *Client) Login() error

Login will try to connect to a new session and start receiving the first message If you want to connect to a specific session, use WithSession() in the NewClient options

func (*Client) Logout

func (c *Client) Logout()

Logout will logout from the Server

func (*Client) Receive

func (c *Client) Receive()

Receive will start listening for packets from the Server. Any sequenced or unsequenced data packets will be passed to your PacketCallback function. Receive will also attempt to automatically reconnect to the Server and rejoin the previous session with the current message sequence number. Receive will block until an end of session packet is received.

func (*Client) Send

func (c *Client) Send(data []byte) error

Send sends an unsequenced data packet to the Server

func (*Client) SendDebugMessage

func (c *Client) SendDebugMessage(text string) error

SendDebugMessage sends a debug packet with human readable text to the Server. Not normally used.

type ClientOption

type ClientOption func(client *Client)

func WithAuth

func WithAuth(username, password string) ClientOption

WithAuth sets the username and password to use when connecting to the Server

func WithCallback

func WithCallback(callback func([]byte)) ClientOption

WithCallback sets the callback function for every sequenced packet received

func WithCompression

func WithCompression(enabled bool) ClientOption

WithCompression allows you to enable soupbintcp (zlib) compression mode

func WithDebugCallback

func WithDebugCallback(callback func(string)) ClientOption

WithDebugCallback sets the callback function for every debug packet received. Not normally used

func WithSession

func WithSession(id string, sequence uint64) ClientOption

WithSession sets the initial session and sequence number when connecting to the Server

func WithUnsequencedCallback

func WithUnsequencedCallback(callback func([]byte)) ClientOption

WithUnsequencedCallback sets the callback function for every unsequenced packet received

type DebugPacket

type DebugPacket struct {
	Header
	Text string
}

func (DebugPacket) Bytes

func (p DebugPacket) Bytes() []byte
type Header struct {
	Length [2]byte
	Type   byte
}

func (Header) Bytes

func (h Header) Bytes() []byte

type HeartbeatPacket

type HeartbeatPacket struct {
	Header
}

type LoginAcceptedPacket

type LoginAcceptedPacket struct {
	Header
	Session        [10]byte
	SequenceNumber [20]byte
}

func (LoginAcceptedPacket) Bytes

func (p LoginAcceptedPacket) Bytes() []byte

type LoginRejectedPacket

type LoginRejectedPacket struct {
	Header
	Reason byte
}

func (LoginRejectedPacket) Bytes

func (p LoginRejectedPacket) Bytes() []byte

type LoginRequestPacket

type LoginRequestPacket struct {
	Header
	Username         [6]byte
	Password         [10]byte
	Session          [10]byte
	SequenceNumber   [20]byte
	HeartbeatTimeout [5]byte
}

func (LoginRequestPacket) Bytes

func (p LoginRequestPacket) Bytes() []byte

type LogoutRequestPacket

type LogoutRequestPacket struct {
	Header
}

type Packet

type Packet interface {
	Bytes() []byte
}

type SequencedDataPacket

type SequencedDataPacket struct {
	Header
	Message []byte
}

func (SequencedDataPacket) Bytes

func (p SequencedDataPacket) Bytes() []byte

type Server

type Server struct {
	// LoginCallback is called for every login request. The username and password is supplied for you to perform additional auth logic
	LoginCallback func(username, password string) bool
	// PacketCallback is called for every unsequenced packet received from a client. The byte slice parameter contains just the message and should
	// be parsed by a higher level protocol
	PacketCallback func([]byte)
	// DebugCallback is called for every debug packet received from a client. This is not normally used.
	DebugCallback func([]byte)
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opts ...ServerOption) *Server

func (*Server) CreateSession

func (s *Server) CreateSession(id string) error

CreateSession creates a new session. There can only be one active session at a time

func (*Server) DeleteSession

func (s *Server) DeleteSession(id string) error

DeleteSession deletes an active session

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ip, port string)

func (*Server) SendToSession

func (s *Server) SendToSession(data []byte) error

SendToSession adds data to the session that will eventually be broadcast to all clients connected to the session. A session must first have been created with CreateSession

type ServerOption

type ServerOption func(s *Server)

func WithLoginCallback

func WithLoginCallback(callback func(username, password string) bool) ServerOption

func WithPacketCallback

func WithPacketCallback(callback func([]byte)) ServerOption

func WithServerDebugCallback

func WithServerDebugCallback(callback func([]byte)) ServerOption

type UnsequencedDataPacket

type UnsequencedDataPacket struct {
	Header
	Message []byte
}

func (UnsequencedDataPacket) Bytes

func (p UnsequencedDataPacket) Bytes() []byte

Jump to

Keyboard shortcuts

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