common

package
v0.0.0-...-78cbaba Latest Latest
Warning

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

Go to latest
Published: May 30, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Call optionType = "call"
	Put  optionType = "put"
)

Variables

View Source
var AlreadyConnected = errors.New("already connected")
View Source
var ConnectionFailed = errors.New("connection failed")
View Source
var DownloadFailed = errors.New("download failed")
View Source
var IMap instrumentMap

global instrument map which is fully synchronized

View Source
var InvalidConnector = errors.New("invalid connector")
View Source
var NotConnected = errors.New("not connected")
View Source
var OrderNotFound = errors.New("order not found")
View Source
var UnknownInstrument = errors.New("unknown instrument")
View Source
var UnsupportedOrderType = errors.New("unsupported order type")

Functions

func CmpTime

func CmpTime(t1 time.Time, t2 time.Time) int

func DecodeDecimal

func DecodeDecimal(r ByteReader) Fixed

func DecodeString

func DecodeString(r ByteReader) string

func DecodeTime

func DecodeTime(r ByteReader) time.Time

func EncodeDecimal

func EncodeDecimal(w ByteWriter, d Fixed)

func EncodeString

func EncodeString(w ByteWriter, s string)

func EncodeTime

func EncodeTime(w ByteWriter, time time.Time)

func MapToFixOrdStatus

func MapToFixOrdStatus(state OrderState) enum.OrdStatus

func MapToFixSide

func MapToFixSide(side Side) enum.Side

func MinDecimal

func MinDecimal(d0 Fixed, d1 Fixed) Fixed

func NewDecimal

func NewDecimal(s string) Fixed

func NewDecimalF

func NewDecimalF(f float64) Fixed

func ParseInt

func ParseInt(s string) int

func PutUvarint

func PutUvarint(w ByteWriter, x uint64) int

PutUvarint encodes a uint64 into buf and returns the number of bytes written.

func PutVarint

func PutVarint(w ByteWriter, x int64) int

PutVarint encodes an int64 into buf and returns the number of bytes written.

func ReadUvarint

func ReadUvarint(r ByteReader) (uint64, error)

ReadUvarint reads an encoded unsigned integer from r and returns it as a uint64.

func ReadVarint

func ReadVarint(r ByteReader) (int64, error)

ReadVarint reads an encoded signed integer from r and returns it as an int64.

func ToDecimal

func ToDecimal(f Fixed) decimal.Decimal

func ToFixed

func ToFixed(d decimal.Decimal) Fixed

func ToFloat

func ToFloat(d Fixed) float64

Types

type Book

type Book struct {
	Instrument Instrument
	Bids       []BookLevel
	Asks       []BookLevel
	Sequence   uint64
}

func (*Book) Equals

func (book *Book) Equals(other Book) bool

func (*Book) HasAsks

func (book *Book) HasAsks() bool

func (*Book) HasBids

func (book *Book) HasBids() bool

func (*Book) IsEmpty

func (book *Book) IsEmpty() bool

func (*Book) String

func (book *Book) String() string

type BookLevel

type BookLevel struct {
	Price    Fixed
	Quantity Fixed
}

type ByteReader

type ByteReader interface {
	io.Reader
	io.ByteReader
}

type ByteWriter

type ByteWriter interface {
	io.Writer
	io.ByteWriter
}

type ConnectorCallback

type ConnectorCallback interface {
	OnBook(*Book)
	// the following is for intra-day instrument addition, or initial startup
	OnInstrument(Instrument)
	// the callback will have the order locked, and will unlock when the callback returns
	OnOrderStatus(*Order)
	OnFill(*Fill)
	OnTrade(*Trade)
}

type Equity

type Equity struct {
	Instrument
}

type ExchangeConnector

type ExchangeConnector interface {
	IsConnected() bool
	Connect() error
	Disconnect() error

	CreateOrder(order *Order) (OrderID, error)
	ModifyOrder(order OrderID, price Fixed, quantity Fixed) error
	CancelOrder(order OrderID) error

	Quote(instrument Instrument, bidPrice Fixed, bidQuantity Fixed, askPrice Fixed, askQuantity Fixed) error

	GetExchangeCode() string

	// ask exchange to create the instrument if it does not already exist, and assign a numeric instrument id
	// the instruments are not persisted across exchange restarts
	CreateInstrument(symbol string)
	// ask exchange for configured instruments, will be emitted via onInstrument() on the callback. this call
	// blocks until all instruments are received
	DownloadInstruments() error
}

type Expiration

type Expiration time.Time

type Fill

type Fill struct {
	Instrument Instrument
	IsQuote    bool
	// Order will be nil on quote trade, the order is unlocked
	Order      *Order
	ExchangeID string
	Quantity   Fixed
	Price      Fixed
	Side       Side
	IsLegTrade bool
}

a fill on an order or quote

type Generic

type Generic struct {
	Instrument
}

type Index

type Index struct {
	Instrument
}

type Instrument

type Instrument interface {
	ID() int64
	Symbol() string
	Group() string
}

func NewInstrument

func NewInstrument(id int64, symbol string) Instrument

type Maturity

type Maturity string

type Option

type Option struct {
	Instrument
	Underlying   Instrument
	Expires      Expiration
	Strike       decimal.Decimal
	OptionType   optionType
	MaturityDate Maturity
}

type OptionLeg

type OptionLeg struct {
	Option *Option
	Ratio  int
}

type OptionStrategy

type OptionStrategy struct {
	Instrument
	Expires  Expiration
	Maturity Maturity
	Legs     []OptionLeg
}

type Order

type Order struct {
	sync.RWMutex
	Instrument
	Id         OrderID
	ExchangeId string
	Price      Fixed
	Side
	Quantity  Fixed
	Remaining Fixed
	OrderType
	OrderState
	RejectReason string
}

func LimitOrder

func LimitOrder(instrument Instrument, side Side, price Fixed, quantity Fixed) *Order

func MarketOrder

func MarketOrder(instrument Instrument, side Side, quantity Fixed) *Order

func (*Order) IsActive

func (order *Order) IsActive() bool

func (*Order) String

func (order *Order) String() string

type OrderID

type OrderID int32

func NewOrderID

func NewOrderID(id string) OrderID

func (OrderID) String

func (id OrderID) String() string

type OrderState

type OrderState string
const (
	New         OrderState = "new"
	Booked      OrderState = "booked"
	PartialFill OrderState = "partial"
	Filled      OrderState = "filled"
	Cancelled   OrderState = "cancelled"
	Rejected    OrderState = "rejected"
)

func MapFromFixOrdStatus

func MapFromFixOrdStatus(ordStatus enum.OrdStatus) OrderState

type OrderType

type OrderType string
const (
	Market OrderType = "market"
	Limit  OrderType = "limit"
)

type Properties

type Properties interface {
	GetString(key string, def string) string
	SetString(key string, value string)
}

func NewProperties

func NewProperties(file string) (Properties, error)

func NewPropertiesFromReader

func NewPropertiesFromReader(r io.Reader) (Properties, error)

type Side

type Side string
const (
	Buy  Side = "buy"
	Sell Side = "sell"
)

func MapFromFixSide

func MapFromFixSide(side enum.Side) Side

type StatusBool

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

func (*StatusBool) IsTrue

func (sb *StatusBool) IsTrue() bool

func (*StatusBool) SetFalse

func (sb *StatusBool) SetFalse()

func (*StatusBool) SetTrue

func (sb *StatusBool) SetTrue()

func (*StatusBool) WaitForFalse

func (sb *StatusBool) WaitForFalse(timeoutMS int64) bool

func (*StatusBool) WaitForTrue

func (sb *StatusBool) WaitForTrue(timeoutMS int64) bool

type Trade

type Trade struct {
	Instrument Instrument
	Quantity   Fixed
	Price      Fixed
	ExchangeID string
	TradeTime  time.Time
}

an exchange trade, not necessarily initiated by the current client

Jump to

Keyboard shortcuts

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