Documentation ¶
Index ¶
- Variables
- type OnUpdateCB
- type OrderBook
- func (ob *OrderBook) ApplyDelta(obd common.OrderBookDelta) error
- func (ob *OrderBook) ApplyDeltaOpt(obd common.OrderBookDelta, ignoreSeqNum bool) error
- func (ob *OrderBook) ApplySnapshot(snapshot common.OrderBookSnapshot)
- func (ob *OrderBook) GetSeqNum() common.SeqNum
- func (ob *OrderBook) GetSnapshot() common.OrderBookSnapshot
- type OrderBookSnapshotGetter
- type OrderBookSnapshotGetterREST
- type OrderBookUpdater
- type OrderBookUpdaterParams
- type StateUpdate
- type Update
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSeqNumMismatch is returned ErrSeqNumMismatch = errors.New("seq num mismatch") )
Functions ¶
This section is empty.
Types ¶
type OnUpdateCB ¶
type OnUpdateCB func(snapshot Update)
type OrderBook ¶
type OrderBook struct {
// contains filtered or unexported fields
}
OrderBook represents a "live" order book, which is able to receive snapshots and deltas.
It is not thread-safe; so if you need to use it from more than one goroutine, apply your own synchronization.
func NewOrderBook ¶
func NewOrderBook(snapshot common.OrderBookSnapshot) *OrderBook
func (*OrderBook) ApplyDelta ¶
func (ob *OrderBook) ApplyDelta(obd common.OrderBookDelta) error
ApplyDelta applies the given delta (received from the wire) to the current orderbook. If the sequence number isn't exactly the old one incremented by 1, returns an error without applying delta.
func (*OrderBook) ApplyDeltaOpt ¶
func (ob *OrderBook) ApplyDeltaOpt(obd common.OrderBookDelta, ignoreSeqNum bool) error
ApplyDeltaOpt applies the given delta (received from the wire) to the current orderbook. If ignoreSeqNum is true, applies the delta even if the sequence number isn't exactly the old one incremented by 1.
func (*OrderBook) ApplySnapshot ¶
func (ob *OrderBook) ApplySnapshot(snapshot common.OrderBookSnapshot)
ApplySnapshot sets the internal orderbook to the provided snapshot.
func (*OrderBook) GetSnapshot ¶
func (ob *OrderBook) GetSnapshot() common.OrderBookSnapshot
GetSnapshot returns the snapshot of the current orderbook.
type OrderBookSnapshotGetter ¶
type OrderBookSnapshotGetter interface {
GetOrderBookSnapshot() (common.OrderBookSnapshot, error)
}
OrderBookSnapshotGetter gets the up-to-date snapshot. Typically clients should use OrderBookSnapshotGetterREST, which gets the snapshot from the REST API.
This is needed in the first place because snapshots are broadcasted via websocket only every minute, so whenever the client just starts, or gets out of sync for a little bit, it needs to get the up-to-date snapshot to avoid waiting for it for too long from the websocket.
type OrderBookSnapshotGetterREST ¶
type OrderBookSnapshotGetterREST struct {
// contains filtered or unexported fields
}
OrderBookSnapshotGetterREST implements OrderBookSnapshotGetter; it gets snapshot for the specified market from the REST API.
func NewOrderBookSnapshotGetterRESTBySymbol ¶
func NewOrderBookSnapshotGetterRESTBySymbol( exchangeSymbol string, pairSymbol string, restParams *rest.CWRESTClientParams, ) *OrderBookSnapshotGetterREST
NewOrderBookSnapshotGetterRESTBySymbol creates a new snapshot getter which uses the REST API to get snapshots for the given market.
func (*OrderBookSnapshotGetterREST) GetOrderBookSnapshot ¶
func (sg *OrderBookSnapshotGetterREST) GetOrderBookSnapshot() (common.OrderBookSnapshot, error)
type OrderBookUpdater ¶
type OrderBookUpdater struct {
// contains filtered or unexported fields
}
OrderBookUpdater maintains the up-to-date orderbook by applying live updates (which are typically fed to it from the StreamClient updates)
func NewOrderBookUpdater ¶
func NewOrderBookUpdater(params *OrderBookUpdaterParams) *OrderBookUpdater
NewOrderBookUpdater creates a new orderbook updater with the provided params.
func (*OrderBookUpdater) Close ¶
func (obu *OrderBookUpdater) Close() error
Close stops event loop; after that instance of OrderBookUpdater can't be used anymore.
func (*OrderBookUpdater) OnUpdate ¶
func (obu *OrderBookUpdater) OnUpdate(cb OnUpdateCB)
OnUpdate registers a new callback which will be called when an update is available: either state update or orderbook update. The callback will be called from the same internal eventloop, so they are never called concurrently with each other, and the callback shouldn't block.
func (*OrderBookUpdater) ReceiveDelta ¶
func (obu *OrderBookUpdater) ReceiveDelta(delta common.OrderBookDelta)
ReceiveDelta should be called when a new orderbook delta is received from the websocket. If the delta applies cleanly to the internal orderbook, the OnUpdate callbacks will be called shortly.
func (*OrderBookUpdater) ReceiveSnapshot ¶
func (obu *OrderBookUpdater) ReceiveSnapshot(snapshot common.OrderBookSnapshot)
ReceiveSnapshot should be called when a new orderbook snapshot is received from the websocket. The OnUpdate callbacks will be called shortly.
type OrderBookUpdaterParams ¶
type OrderBookUpdaterParams struct { // SnapshotGetter is optional; it returns an up-to-date snapshot, typically // from REST API. See NewOrderBookSnapshotGetterRESTBySymbol. // // If SnapshotGetter is not set, then OrderBookUpdater will just wait for // the snapshot from the websocket (snapshot is delivered there every minute) SnapshotGetter OrderBookSnapshotGetter // contains filtered or unexported fields }
OrderBookUpdaterParams contains params for creating a new orderbook updater.
type StateUpdate ¶
type StateUpdate struct { // IsInSync is true when the cached deltas cover the current snapshot. IsInSync bool // SeqNum is the sequence number of the current snapshot. SeqNum *common.SeqNum // MinDeltaNum is the min sequence number of the cached deltas. MinDeltaNum *common.SeqNum // MaxDeltaNum is the max sequence number of the cached deltas. MaxDeltaNum *common.SeqNum }
StateUpdate is delivered to handlers (registered with OnUpdate) when the client becomes in sync or goes out of sync; see IsInSync field.
func (*StateUpdate) String ¶
func (su *StateUpdate) String() string
type Update ¶
type Update struct { OrderBookUpdate *common.OrderBookSnapshot StateUpdate *StateUpdate GetSnapshotError error }