lab

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

Documentation

Overview

Package lab runs the whole thing inside one process: the exchange on a loopback port, a few liquidity bots that are ordinary FIX sessions, and one initiator session per visitor, each behind its own tap.

pigfox.com's /demos/fix-lab imports this package. The host exposes no extra TCP port, so every FIX connection here is loopback; the browser never speaks FIX and reaches its session only through the host's own WebSocket.

Index

Constants

View Source
const BotLevels = 2

BotLevels is how many price levels each bot quotes a side.

View Source
const BotQty = 100

BotQty is each bot order's size.

Variables

View Source
var ErrLogon = errors.New("the session did not log on")

ErrLogon is a visitor session that did not log on in time.

Functions

func Step

func Step(ref int64) int64

Step is the ladder's spacing for an instrument: half a percent of its reference price, at least one tick.

Types

type Book

type Book struct {
	Symbol string       `json:"symbol"`
	Name   string       `json:"name"`
	Bids   []book.Level `json:"bids"`
	Asks   []book.Level `json:"asks"`
}

Book is one instrument's depth.

type Config

type Config struct {
	// HeartBtInt is every session's heartbeat interval, in seconds. Short
	// enough that "go silent" ends a session while the reader watches.
	HeartBtInt int
	// Bots is how many liquidity bots to run; 0 runs none.
	Bots int
	// Addr is the exchange's listen address; "" is 127.0.0.1 on a free port.
	Addr string
	// Open lets any SenderCompID log on. Off, only sessions the lab started
	// itself can, which is how a host that runs visitors uses it.
	Open bool
}

Config is how a lab starts.

type Lab

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

Lab is a running exchange with its bots.

func Start

func Start(ctx context.Context, cfg Config) (*Lab, error)

Start starts the exchange and the bots, and waits for the bots to log on.

func (*Lab) Books

func (l *Lab) Books(n int) []Book

Books returns every instrument's depth, n levels a side.

func (*Lab) Close

func (l *Lab) Close()

Close stops the bots and the exchange.

func (*Lab) Exchange

func (l *Lab) Exchange() *exchange.Exchange

Exchange is the running exchange.

func (*Lab) NewVisitor

func (l *Lab) NewVisitor(ctx context.Context, compID string, onFrame func(wire.Frame), onEvent func(client.Event)) (*Visitor, error)

NewVisitor starts a session for compID through a fresh tap and waits for its logon. onFrame hears every message on the wire, onEvent every engine event; both run on engine or tap goroutines and must not block.

type Seq

type Seq struct {
	ClientNextOut   int `json:"client_next_out"`
	ClientNextIn    int `json:"client_next_in"`
	ExchangeNextOut int `json:"exchange_next_out"`
	ExchangeNextIn  int `json:"exchange_next_in"`
}

Seq is both ends' sequence numbers for the visitor's session.

type Visitor

type Visitor struct {
	CompID  string
	Session *client.Session
	Tap     *wire.Tap
	// contains filtered or unexported fields
}

Visitor is one visitor's initiator session and the tap in front of it.

func (*Visitor) Close

func (v *Visitor) Close()

Close logs the session out (if it is still on), stops it and closes the tap.

func (*Visitor) Seq

func (v *Visitor) Seq() Seq

Seq reads both engines' stores.

Jump to

Keyboard shortcuts

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