client

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 client is the initiator side: one QuickFIX/Go initiator session that logs on to the exchange, sends NewOrderSingle and OrderCancelRequest, and keeps its own view of its orders from the ExecutionReports it receives.

Every session-level behavior — logon, heartbeats, TestRequest, sequence numbers, ResendRequest and the resend or gap fill that answers it, logout — is the engine's. This package only starts it, sends application messages through it, and listens.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotLoggedOn = errors.New("the session is not logged on")

ErrNotLoggedOn is a send attempted outside a logged-on session.

Functions

This section is empty.

Types

type CancelReject

type CancelReject struct {
	ClOrdID     string `json:"cl_ord_id"`
	OrigClOrdID string `json:"orig_cl_ord_id"`
	Reason      string `json:"reason"`
	Text        string `json:"text"`
}

CancelReject is an OrderCancelReject as the client read it.

type Config

type Config struct {
	SenderCompID string
	// Addr is the exchange's (or a tap's) host:port.
	Addr string
	// HeartBtInt is the heartbeat interval in seconds sent in the Logon.
	HeartBtInt int
	// ReconnectInterval is how long the engine waits before dialing again
	// after a disconnect. The lab stops a session that disconnects, so this
	// only matters to a long-running client.
	ReconnectInterval time.Duration
	// Log is the engine's log; nil is no log.
	Log quickfix.LogFactory
}

Config is one session's settings.

type Event

type Event struct {
	Logon        bool
	Logout       bool
	Exec         *Exec
	CancelReject *CancelReject
	// At is when the engine handed the client the event.
	At time.Time
}

Event is what a session's handler hears. Exactly one field is set, except Logon/Logout which are flags.

type Exec

type Exec struct {
	OrderID     string `json:"order_id"`
	ClOrdID     string `json:"cl_ord_id"`
	OrigClOrdID string `json:"orig_cl_ord_id,omitempty"`
	ExecID      string `json:"exec_id"`
	ExecType    string `json:"exec_type"`
	OrdStatus   string `json:"ord_status"`
	Symbol      string `json:"symbol"`
	Side        string `json:"side"`
	OrderQty    string `json:"order_qty"`
	Price       string `json:"price"`
	LeavesQty   string `json:"leaves_qty"`
	CumQty      string `json:"cum_qty"`
	AvgPx       string `json:"avg_px"`
	LastQty     string `json:"last_qty,omitempty"`
	LastPx      string `json:"last_px,omitempty"`
	MatchID     string `json:"match_id,omitempty"`
	Text        string `json:"text,omitempty"`
}

Exec is an ExecutionReport as the client read it.

type Order

type Order struct {
	ClOrdID string `json:"cl_ord_id"`
	OrderID string `json:"order_id"`
	Symbol  string `json:"symbol"`
	Side    string `json:"side"`
	Price   string `json:"price"`
	Qty     string `json:"qty"`
	Leaves  string `json:"leaves"`
	Cum     string `json:"cum"`
	AvgPx   string `json:"avg_px"`
	Status  string `json:"status"`
	Text    string `json:"text,omitempty"`
	// contains filtered or unexported fields
}

Order is the client's view of one of its orders, built only from what the exchange reported.

type Session

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

Session is one initiator session.

func New

func New(cfg Config, handler func(Event)) (*Session, error)

New prepares a session; Start connects and logs on. handler is called from the engine's session goroutine for every event, so it must not block long and must not call Stop.

func (*Session) Cancel

func (s *Session) Cancel(origClOrdID string) (string, error)

Cancel sends an OrderCancelRequest for the order with origClOrdID and returns the request's own ClOrdID.

func (*Session) FromApp

func (*Session) ID

func (s *Session) ID() quickfix.SessionID

ID is the session's identity.

func (*Session) LoggedOn

func (s *Session) LoggedOn() bool

LoggedOn reports the session's state.

func (*Session) NewOrder

func (s *Session) NewOrder(symbol, side, price string, qty int64) (string, error)

NewOrder sends a limit NewOrderSingle and returns its ClOrdID.

func (*Session) OnCreate

func (s *Session) OnCreate(quickfix.SessionID)

func (*Session) OnLogon

func (s *Session) OnLogon(quickfix.SessionID)

func (*Session) OnLogout

func (s *Session) OnLogout(quickfix.SessionID)

func (*Session) Orders

func (s *Session) Orders() []Order

Orders returns the client's orders, oldest first.

func (*Session) Seq

func (s *Session) Seq() (nextOut, nextIn int, ok bool)

Seq returns the engine's next outbound and next expected inbound sequence numbers for this session.

func (*Session) Start

func (s *Session) Start() error

Start connects and begins the logon.

func (*Session) Stop

func (s *Session) Stop()

Stop logs out (when logged on) and stops the engine. It blocks until the engine's goroutines are done, so it must not be called from the handler.

func (*Session) ToAdmin

func (s *Session) ToAdmin(*quickfix.Message, quickfix.SessionID)

func (*Session) ToApp

func (*Session) WaitLogon

func (s *Session) WaitLogon(ctx context.Context) error

WaitLogon waits for the first logon.

Jump to

Keyboard shortcuts

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