Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents a single trading pair in the order book. Responsible for managing all active orders and for matching orders according to their price and quantity.

Hierarchy

  • EventEmitter
    • TradingPair

Index

Constructors

constructor

Properties

Private logger

logger: Logger

Private nomatching

nomatching: boolean

ownOrders

A pair of maps between active own orders ids and orders for the buy and sell sides of this trading pair.

pairId

pairId: string

peersOrders

peersOrders: Map<string, OrderSidesMaps<PeerOrder>>

A map between peerPubKey and a pair of maps between active peer orders ids and orders for the buy and sell sides of this trading pair.

Optional queues

A pair of priority queues for the buy and sell sides of this trading pair

Static QUANTITY_DUST_LIMIT

QUANTITY_DUST_LIMIT: number = 100

The minimum quantity for both sides of a trade that is considered swappable and not dust.

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: keyof symbol

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

Private addOrder

  • Attempts to add an order for this trading pair.

    Parameters

    Returns boolean

    true if the order was added, false if it could not be added because there already exists an order with the same order id

addOrderHold

  • addOrderHold(orderId: string, holdAmount?: undefined | number): void

addOwnOrder

  • Adds an own order for this trading pair.

    Parameters

    Returns boolean

    true if the order was added, false if it could not be added because there already exists an order with the same order id

addPeerOrder

  • Adds a peer order for this trading pair.

    Parameters

    Returns boolean

    true if the order was added, false if it could not be added because there already exists an order with the same order id

emit

  • emit(event: "peerOrder.dust", order: OrderPortion): boolean
  • emit(event: "ownOrder.dust", order: OrderPortion): boolean
  • Notifies listeners that a remote order was removed due to not meeting dust minimum.

    Parameters

    Returns boolean

  • Notifies listeners that a local order was removed due to not meeting dust minimum.

    Parameters

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number

Private getOrder

  • getOrder<T>(orderId: string, maps: OrderSidesMaps<T>): T | undefined

Private getOrderMap

Private getOrders

getOwnOrder

  • getOwnOrder(orderId: string): OwnOrder

getOwnOrders

getPeerOrder

  • getPeerOrder(orderId: string, peerPubKey: string): PeerOrder

getPeersOrders

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

match

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: "peerOrder.dust", listener: (order: OrderPortion) => void): this
  • on(event: "ownOrder.dust", listener: (order: OrderPortion) => void): this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

Private removeOrder

  • removeOrder<T>(orderId: string, maps: OrderSidesMaps<Order>, quantityToRemove?: undefined | number): { fullyRemoved: boolean; order: T }
  • Removes all or part of an order.

    Type parameters

    Parameters

    • orderId: string
    • maps: OrderSidesMaps<Order>
    • Optional quantityToRemove: undefined | number

      the quantity to remove, if undefined or if greater than or equal to the available quantity then the entire order is removed

    Returns { fullyRemoved: boolean; order: T }

    the portion of the order that was removed, and a flag indicating whether the entire order was removed

    • fullyRemoved: boolean
    • order: T

removeOrderHold

  • removeOrderHold(orderId: string, holdAmount?: undefined | number): void

removeOwnOrder

  • removeOwnOrder(orderId: string, quantityToRemove?: undefined | number): { fullyRemoved: boolean; order: OwnOrder }
  • Removes all or part of an own order.

    Parameters

    • orderId: string
    • Optional quantityToRemove: undefined | number

      the quantity to remove, if undefined or if greater than or equal to the available quantity then the entire order is removed

    Returns { fullyRemoved: boolean; order: OwnOrder }

    the portion of the order that was removed, and a flag indicating whether the entire order was removed

removePeerOrder

  • removePeerOrder(orderId: string, peerPubKey?: undefined | string, quantityToRemove?: undefined | number): { fullyRemoved: boolean; order: PeerOrder }
  • Removes all or part of a peer order.

    Parameters

    • orderId: string
    • Optional peerPubKey: undefined | string
    • Optional quantityToRemove: undefined | number

      the quantity to remove, if undefined or if greater than or equal to the available quantity then the entire order is removed

    Returns { fullyRemoved: boolean; order: PeerOrder }

    the portion of the order that was removed, and a flag indicating whether the entire order was removed

removePeerOrders

  • removePeerOrders(peerPubKey?: undefined | string): PeerOrder[]

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Static Private createPriorityQueue

Static Private getMatchingQuantity

  • getMatchingQuantity(buyOrder: Order, sellOrder: Order): number
  • Gets the quantity that can be matched between two orders.

    Parameters

    Returns number

    the smaller of the quantity between the two orders if their price matches, 0 otherwise

Static getOrdersPriorityQueueComparator

  • getOrdersPriorityQueueComparator(orderingDirection: OrderingDirection): (Anonymous function)

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Static Private splitOrderByQuantity

  • splitOrderByQuantity<T>(order: T, matchingQuantity: number): T
  • Splits an order by quantity into a matched portion and subtracts the matched quantity from the original order.

    Type parameters

    Parameters

    • order: T

      the order that is being split

    • matchingQuantity: number

      the quantity for the split order and to subtract from the original order

    Returns T

    the split portion of the order with the matching quantity

Generated using TypeDoc