wire

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package wire reads FIX messages off a byte stream, names every tag in them, and sits between two FIX engines as a tap that can lose messages on purpose.

Nothing here speaks FIX the way an engine does: no sequence numbers are kept, nothing is answered, nothing is resent. The tap only forwards whole messages or withholds them, so every recovery a reader sees after a withheld message is the engines' own.

Index

Constants

View Source
const SOH = 0x01

SOH is FIX's field delimiter, byte 0x01.

Variables

View Source
var ErrFrame = errors.New("not a FIX message")

ErrFrame is a stream that is not a sequence of FIX 4.4 messages.

Functions

func Pipe

func Pipe(raw []byte) string

Pipe shows a message with each SOH as "|", as FIX logs conventionally do.

Types

type Dir

type Dir string

Dir is which way a message travelled through the tap.

const (
	Out Dir = "out"
	In  Dir = "in"
)

Out is initiator to acceptor (the client's own messages); In is the reverse.

type Field

type Field struct {
	Tag     int    `json:"tag"`
	Name    string `json:"name"`
	Value   string `json:"value"`
	Meaning string `json:"meaning,omitempty"`
}

Field is one tag=value pair with its dictionary name, and the name of the value when the dictionary enumerates it (ExecType 0 is "NEW").

type Frame

type Frame struct {
	Dir     Dir
	Raw     []byte
	At      time.Time
	Dropped bool
	// Why is set on a dropped frame: "drop-next" or "silent".
	Why string
}

Frame is one whole message the tap saw. Dropped is true when the tap withheld it, so the other engine never received it.

type Message

type Message struct {
	MsgType string  `json:"msg_type"`
	Name    string  `json:"name"`
	Seq     int     `json:"seq"`
	PossDup bool    `json:"poss_dup"`
	Pipe    string  `json:"pipe"`
	Fields  []Field `json:"fields"`
}

Message is a decoded message.

func Decode

func Decode(raw []byte) (Message, error)

Decode names every field of raw from the FIX 4.4 dictionary. A tag the dictionary does not know keeps its number as its name.

func (Message) Get

func (m Message) Get(tag int) (string, bool)

Get returns the first value of tag.

type Reader

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

Reader splits a stream into whole messages.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader wraps r.

func (*Reader) Next

func (fr *Reader) Next() ([]byte, error)

Next returns the next whole message, BeginString through CheckSum.

type Tap

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

Tap is a TCP relay for one FIX connection at a time: the initiator dials Addr, the tap dials the acceptor, and whole messages are copied across.

DropNext withholds the next whole outbound message, once. Silence withholds every outbound message until it is lifted, which to the acceptor looks like a client that stopped talking. The tap never alters a message it forwards and never writes one of its own.

func NewTap

func NewTap(upstream string, onFrame func(Frame)) (*Tap, error)

NewTap listens on 127.0.0.1 and relays each connection to upstream. onFrame is called for every message in either direction, from the relay goroutines, in the order that direction carried them.

func (*Tap) Addr

func (t *Tap) Addr() *net.TCPAddr

Addr is where the initiator should connect.

func (*Tap) Armed

func (t *Tap) Armed() bool

Armed reports whether a DropNext is still waiting for a message.

func (*Tap) Close

func (t *Tap) Close()

Close stops listening and closes every relayed connection.

func (*Tap) DropNext

func (t *Tap) DropNext()

DropNext arms a one-shot drop of the next outbound message.

func (*Tap) SetSilent

func (t *Tap) SetSilent(on bool)

SetSilent withholds (true) or forwards (false) every outbound message.

func (*Tap) Silent

func (t *Tap) Silent() bool

Silent reports whether outbound messages are being withheld.

Jump to

Keyboard shortcuts

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