Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents an order book containing all orders for all active trading pairs. This encompasses all orders tracked locally and is the primary interface with which other modules interact with the order book.

Hierarchy

  • EventEmitter
    • OrderBook

Index

Constructors

constructor

Properties

Private currencyInstances

currencyInstances: Map<string, CurrencyInstance> = new Map<string, CurrencyInstance>()

A map of supported currency tickers to currency instances.

Private localIdMap

localIdMap: Map<string, {} & { id: string }> = new Map<string, OrderIdentifier>()

A map between own orders local id and their global id.

Private logger

logger: Logger

Private nobalancechecks

nobalancechecks: boolean

nomatching

nomatching: boolean

Private nosanityswaps

nosanityswaps: boolean

Private pairInstances

pairInstances: Map<string, PairInstance> = new Map<string, PairInstance>()

A map of supported trading pair tickers and pair database instances.

Private pool

pool: Pool

Private repository

repository: OrderBookRepository

Private strict

strict: boolean

Private swaps

swaps: Swaps

Private thresholds

tradingPairs

tradingPairs: Map<string, TradingPair> = new Map<string, TradingPair>()

A map between active trading pair ids and trading pair instances.

Static Private Readonly MAX_PLACEORDER_ITERATIONS_TIME

MAX_PLACEORDER_ITERATIONS_TIME: 60000 = 60000

Max time for placeOrder iterations (due to swaps failures retries).

Static Private Readonly MAX_SANITY_SWAP_TIME

MAX_SANITY_SWAP_TIME: 15000 = 15000

Max time for sanity swaps to succeed.

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.

Accessors

currencies

pairIds

  • get pairIds(): string[]

Methods

addCurrency

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 addOrderHold

  • addOrderHold(orderId: string, pairId: string, holdAmount: number): void

Private addOwnOrder

  • Adds an own order to the order book and broadcasts it to peers.

    Parameters

    Returns boolean

    false if it's a duplicated order or with an invalid pair id, otherwise true

addPair

Private addPeerOrder

  • Adds an incoming peer order to the local order book. It timestamps the order based on when it enters the order book and also records its initial quantity upon being received.

    Parameters

    Returns boolean

    false if it's a duplicated order or with an invalid pair id, otherwise true

Private bindPool

  • bindPool(): void

Private bindSwaps

  • bindSwaps(): void

Private checkPeerCurrencies

  • checkPeerCurrencies(peer: Peer): void

Private checkThresholdCompliance

emit

  • emit(event: "peerOrder.incoming", order: PeerOrder): boolean
  • emit(event: "peerOrder.invalidation", order: OrderPortion): boolean
  • emit(event: "peerOrder.filled", order: OrderPortion): boolean
  • emit(event: "ownOrder.swapped", order: OrderPortion): boolean
  • emit(event: "ownOrder.filled", order: OrderPortion): boolean
  • emit(event: "ownOrder.added", order: OwnOrder): boolean
  • emit(event: "ownOrder.removed", order: OrderPortion): boolean
  • Notifies listeners that a remote order was added

    Parameters

    • event: "peerOrder.incoming"
    • order: PeerOrder

    Returns boolean

  • Notifies listeners that all or part of a remote order was invalidated and removed

    Parameters

    Returns boolean

  • Notifies listeners that all or part of a remote order was filled by an own order and removed

    Parameters

    Returns boolean

  • Notifies listeners that all or part of a local order was swapped and removed, after it was filled and executed remotely

    Parameters

    Returns boolean

  • Notifies listeners that all or part of a local order was filled by an own order and removed

    Parameters

    Returns boolean

  • Notifies listeners that a local order was added

    Parameters

    • event: "ownOrder.added"
    • order: OwnOrder

    Returns boolean

  • Notifies listeners that a local order was removed

    Parameters

    Returns boolean

eventNames

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

executeSwap

getMaxListeners

  • getMaxListeners(): number

getOwnOrder

  • getOwnOrder(orderId: string, pairId: string): OwnOrder
  • Gets an own order by order id and pair id.

    Parameters

    • orderId: string
    • pairId: string

    Returns OwnOrder

    The order matching parameters, or undefined if no order could be found.

getOwnOrderByLocalId

  • getOwnOrderByLocalId(localId: string): { isBuy: boolean; pairId: string; quantity: number } & { price: number } & { localId: string } & {} & { id: string } & { createdAt: number; initialQuantity: number } & { hold: number }
  • Parameters

    • localId: string

    Returns { isBuy: boolean; pairId: string; quantity: number } & { price: number } & { localId: string } & {} & { id: string } & { createdAt: number; initialQuantity: number } & { hold: number }

getOwnOrders

  • getOwnOrders(pairId: string): { buyArray: T[]; sellArray: T[] }
  • Get lists of this node's own buy and sell orders.

    Parameters

    • pairId: string

    Returns { buyArray: T[]; sellArray: T[] }

    • buyArray: T[]
    • sellArray: T[]

getPeerOrder

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

getPeersOrders

  • getPeersOrders(pairId: string): { buyArray: T[]; sellArray: T[] }
  • Get lists of buy and sell orders of peers.

    Parameters

    • pairId: string

    Returns { buyArray: T[]; sellArray: T[] }

    • buyArray: T[]
    • sellArray: T[]

getTrades

  • getTrades(limit?: undefined | number): Promise<TradeInstance[]>

Private getTradingPair

Private handleOrderInvalidation

  • handleOrderInvalidation(oi: OrderPortion, peerPubKey: string): void

Private handleSwapRequest

  • Handles a request from a peer to create a swap deal. Checks if the order for the requested swap is available and if a route exists to determine if the request should be accepted or rejected. Responds to the peer with a swap response packet containing either an accepted quantity or rejection reason.

    Parameters

    Returns Promise<void>

init

  • init(): Promise<void>

Private isPeerCurrencySupported

  • isPeerCurrencySupported(peer: Peer, currency: string): boolean
  • Checks that a currency advertised by a peer is known to us, has a swap client identifier, and that their token identifier matches ours.

    Parameters

    • peer: Peer
    • currency: string

    Returns boolean

listenerCount

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

    • type: string | symbol

    Returns number

listeners

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

    • event: string | symbol

    Returns Function[]

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.incoming", listener: (order: PeerOrder) => void): this
  • on(event: "peerOrder.invalidation", listener: (order: OrderPortion) => void): this
  • on(event: "peerOrder.filled", listener: (order: OrderPortion) => void): this
  • on(event: "ownOrder.swapped", listener: (order: OrderPortion) => void): this
  • on(event: "ownOrder.filled", listener: (order: OrderPortion) => void): this
  • on(event: "ownOrder.added", listener: (order: OwnOrder) => void): this
  • on(event: "ownOrder.removed", 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

Private persistTrade

  • persistTrade(__namedParameters: { makerOrder: undefined | ({} & { localId?: undefined | string; nodeId?: undefined | number; price?: undefined | number }); makerOrderId: undefined | string; quantity: number; rHash: undefined | string; takerOrder: undefined | ({} & { localId?: undefined | string; nodeId?: undefined | number; price?: undefined | number }) }): Promise<void>
  • Parameters

    • __namedParameters: { makerOrder: undefined | ({} & { localId?: undefined | string; nodeId?: undefined | number; price?: undefined | number }); makerOrderId: undefined | string; quantity: number; rHash: undefined | string; takerOrder: undefined | ({} & { localId?: undefined | string; nodeId?: undefined | number; price?: undefined | number }) }
      • makerOrder: undefined | ({} & { localId?: undefined | string; nodeId?: undefined | number; price?: undefined | number })
      • makerOrderId: undefined | string
      • quantity: number
      • rHash: undefined | string
      • takerOrder: undefined | ({} & { localId?: undefined | string; nodeId?: undefined | number; price?: undefined | number })

    Returns Promise<void>

placeLimitOrder

placeMarketOrder

Private placeOrder

  • placeOrder(__namedParameters: { discardRemaining: boolean; maxTime: undefined | number; onUpdate: undefined | ((e: PlaceOrderEvent) => void); order: { isBuy: boolean; pairId: string; quantity: number } & { price: number } & { localId: string } & {} & { id: string } & { createdAt: number; initialQuantity: number } & { hold: number }; retry: boolean }): Promise<PlaceOrderResult>
  • Places an order in the order book. This method first attempts to match the order with existing orders by price and initiate swaps for any matches with peer orders. It can be called recursively for any portions of the order that fail swaps.

    Parameters

    • __namedParameters: { discardRemaining: boolean; maxTime: undefined | number; onUpdate: undefined | ((e: PlaceOrderEvent) => void); order: { isBuy: boolean; pairId: string; quantity: number } & { price: number } & { localId: string } & {} & { id: string } & { createdAt: number; initialQuantity: number } & { hold: number }; retry: boolean }
      • discardRemaining: boolean
      • maxTime: undefined | number
      • onUpdate: undefined | ((e: PlaceOrderEvent) => void)
      • order: { isBuy: boolean; pairId: string; quantity: number } & { price: number } & { localId: string } & {} & { id: string } & { createdAt: number; initialQuantity: number } & { hold: number }
      • retry: boolean

    Returns Promise<PlaceOrderResult>

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

removeCurrency

  • removeCurrency(currencyId: string): Promise<void>

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 removeOrderHold

  • removeOrderHold(orderId: string, pairId: string, holdAmount: number): void

Private removeOwnOrder

  • removeOwnOrder(orderId: string, pairId: string, quantityToRemove?: undefined | number, takerPubKey?: undefined | string): { isBuy: boolean; pairId: string; quantity: number } & { price: number } & { localId: string } & {} & { id: string } & { createdAt: number; initialQuantity: number } & { hold: number }
  • Removes all or part of an own order from the order book and broadcasts an order invalidation packet.

    Parameters

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

      the quantity to remove from the order, if undefined then the full order is removed

    • Optional takerPubKey: undefined | string

      the node pub key of the taker who filled this order, if applicable

    Returns { isBuy: boolean; pairId: string; quantity: number } & { price: number } & { localId: string } & {} & { id: string } & { createdAt: number; initialQuantity: number } & { hold: number }

    the removed portion of the order

removeOwnOrderByLocalId

  • removeOwnOrderByLocalId(localId: string, allowAsyncRemoval?: undefined | false | true, quantityToRemove?: undefined | number): number
  • Removes all or part of an order from the order book by its local id. Throws an error if the specified pairId is not supported or if the order to cancel could not be found.

    Parameters

    • localId: string
    • Optional allowAsyncRemoval: undefined | false | true

      whether to allow an eventual async removal of the order in case some quantity of the order is on hold and cannot be immediately removed. If false, while some quantity of the order is on hold, an error will be thrown.

    • Optional quantityToRemove: undefined | number

      the quantity to remove from the order, if undefined then the entire order is removed.

    Returns number

    any quantity of the order that was on hold and could not be immediately removed (if allowed).

removePair

  • removePair(pairId: string): Promise<void>

removePeerOrder

  • removePeerOrder(orderId: string, pairId: string, peerPubKey?: undefined | string, quantityToRemove?: undefined | number): { fullyRemoved: boolean; order: PeerOrder }
  • Removes all or part of a peer order from the order book and emits the peerOrder.invalidation event.

    Parameters

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

      the quantity to remove from the order, if undefined then the full order is removed

    Returns { fullyRemoved: boolean; order: PeerOrder }

Private removePeerOrders

  • removePeerOrders(peerPubKey?: undefined | string): void

Private removePeerPair

  • removePeerPair(peerPubKey: string, pairId: string): void

Private sendOrders

  • sendOrders(peer: Peer, reqId: string, pairIds: string[]): Promise<void>
  • Send local orders to a given peer in an [[OrdersPacket].

    Parameters

    • peer: Peer
    • reqId: string

      the request id of a GetOrdersPacket packet that this method is responding to

    • pairIds: string[]

      a list of trading pair ids, only orders belonging to one of these pairs will be sent

    Returns Promise<void>

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

stampOwnOrder

Private tryGetOwnOrder

  • tryGetOwnOrder(orderId: string, pairId: string): OwnOrder | undefined

Private verifyPeerPairs

  • verifyPeerPairs(peer: Peer): Promise<void>
  • Verifies the advertised trading pairs of a peer. Checks that the peer has advertised lnd pub keys for both the base and quote currencies for each pair, and optionally attempts a "sanity swap" for each currency which is a 1 satoshi for 1 satoshi swap of a given currency that demonstrates that we can both accept and receive payments for this peer.

    Parameters

    Returns Promise<void>

Static Private createOutgoingOrder

Static listenerCount

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

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc