exchange

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: 13 Imported by: 0

Documentation

Overview

Package exchange is the acceptor side: a QuickFIX/Go acceptor whose application is a matching engine with one order book per instrument.

It takes NewOrderSingle (D) and OrderCancelRequest (F) and answers with ExecutionReport (8) and OrderCancelReject (9). Every fill is reported to BOTH sides, each on its own session, and the two reports carry the same match ID in SecondaryExecID (527) so a reader can pair them. Any other application message is refused by the engine with a BusinessMessageReject.

THE INSTRUMENTS ARE FICTIONAL. Their symbols end in ".LAB", their names say so, and their reference prices are made up; nothing here reads or resembles a market.

When a session ends for any reason, its resting orders are canceled: there is no session to report a later fill to.

Index

Constants

View Source
const (
	BandPercent = 20
	MaxOrderQty = 1000
)

Limits the exchange enforces on every order.

View Source
const CompID = "PFXLAB"

CompID is the exchange's SenderCompID.

Variables

View Source
var Instruments = []Instrument{
	{Symbol: "ACORN.LAB", Name: "Acorn (fictional)", Ref: 10000},
	{Symbol: "BIRCH.LAB", Name: "Birch (fictional)", Ref: 2500},
}

Instruments are the two books.

Functions

func SessionID

func SessionID(clientCompID string) quickfix.SessionID

SessionID is the exchange's side of a client's session.

func Symbols

func Symbols() []string

Symbols returns the listed symbols in a stable order.

Types

type Config

type Config struct {
	// Addr is the listen address; "" means 127.0.0.1 on a free port.
	Addr string
	// HeartBtInt is the heartbeat interval in seconds the exchange asks for;
	// the initiator's Logon sets the session's actual value.
	HeartBtInt int
	// Allow, if set, decides which SenderCompIDs may log on.
	Allow func(compID string) bool
	// Log is the engine's log; nil is no log.
	Log quickfix.LogFactory
}

Config is how an exchange starts.

type Event

type Event struct {
	Symbol string
	Trade  *book.Fill
}

Event is what observers hear: a book changed, or a trade happened.

type Exchange

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

Exchange is a running acceptor.

func Start

func Start(cfg Config) (*Exchange, error)

Start opens the listener and starts the acceptor.

func (*Exchange) Addr

func (x *Exchange) Addr() *net.TCPAddr

Addr is where initiators connect.

func (*Exchange) Depth

func (x *Exchange) Depth(symbol string, n int) (bids, asks []book.Level, ok bool)

Depth returns up to n levels a side for symbol.

func (*Exchange) FromApp

func (*Exchange) Observe

func (x *Exchange) Observe(fn func(Event))

Observe registers fn for every book change and trade. It is called outside the exchange's lock, possibly from several goroutines.

func (*Exchange) OnCreate

func (x *Exchange) OnCreate(quickfix.SessionID)

func (*Exchange) OnLogon

func (x *Exchange) OnLogon(quickfix.SessionID)

func (*Exchange) OnLogout

func (x *Exchange) OnLogout(id quickfix.SessionID)

OnLogout cancels everything the session had resting.

func (*Exchange) Seq

func (x *Exchange) Seq(clientCompID string) (nextOut, nextIn int, ok bool)

Seq is the exchange's next outbound and next expected inbound sequence numbers for a client's session, read from the engine's store.

func (*Exchange) Stats

func (x *Exchange) Stats() Stats

Stats returns the counters.

func (*Exchange) Stop

func (x *Exchange) Stop()

Stop stops the acceptor and every session.

func (*Exchange) ToAdmin

func (x *Exchange) ToAdmin(*quickfix.Message, quickfix.SessionID)

func (*Exchange) ToApp

type Instrument

type Instrument struct {
	Symbol string `json:"symbol"`
	Name   string `json:"name"`
	// Ref is the made-up reference price in ticks; orders must be within
	// BandPercent of it.
	Ref int64 `json:"ref"`
}

Instrument is one fictional instrument.

type Stats

type Stats struct {
	Trades  uint64 `json:"trades"`
	Logons  uint64 `json:"logons"`
	Resting int    `json:"resting"`
}

Stats are the exchange's counters.

Jump to

Keyboard shortcuts

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