Home Reference Source Repository
public class | source

Market

Extends:

market-engine~MarketEngine → Market

Market with contingent order features, such as stop orders, one-cancels-other orders and one-sends-other orders

Constructor Summary

Public Constructor
public

constructor(options: Object)

Market constructor

Member Summary

Public Members
public

container for books and book settings

public

list of all books

public

inbox for pre-orders from internal processes such as stops and triggers.

public

Method Summary

Public Methods
public

clear()

clears or resets market to initial "new" condition, clearing active list, books, and trash

public

market current Ask Price

public

market current Bid Price

public

last trade price, if any.

public

process order from the top of the inbox, returning inbox length

public

submit(neworder: number[]): string | undefined

submit order to the Market's inbox for eventual processing

Public Constructors

public constructor(options: Object) source

Market constructor

Params:

NameTypeAttributeDescription
options Object

Options affecting market behavior. Also passed to marekt-engine constructor. Accessible later in this.o

options.buyImprove number
  • optional

If positive, indicates entry in buy book new buy order must beat to be acceptable. 0=off. 1= new buy must beat book highest buy. 2=must beat 2nd best book,etc.

options.sellImprove number
  • optional

If positive, indicates entry in sell book new sell order must beat to be acceptable. 0=off. 1= new sell must be lower than lowest previous sell order on book.

options.resetAfterEachTrade boolean
  • optional

If true, calls .clear() after each trade, clearing the market books and active trade list.

options.buySellBookLimit number
  • optional

If positive, after each trade keeps at most buySellBookLimit orders in the buy book, and buySellBookLimit orders in the sell book, deleting other orders.

options.bookfixed boolean
  • optional
  • default: 1

If true, books are fixed size and scan active list after each trade. If false, books are accordian-style that can shrink 50% before re-scanning old orders.

options.booklimit number
  • optional
  • default: 100

Indicates maximum and initial size, in orders, of order book for each category (buy,sell,buystop,sellstop).

Listen:

bump

triggering book update with .cleanup() when orders are bumped off due to cancellation/expiration

before-order

triggering check of .improvementRule() to check new orders against .buyImprove/.sellImprove

order

to detect trades between orders, and when trades are found, calling market-engine inherited .trade() method

trade

triggering one-sends-other orders via .tradeTrigger() to be pushed to .inbox

trade-cleanup

triggering stop orders to .inbox, rescanning order books and applying post-trade book size limits

stops

to push buy/sell orders resulting from stops to .inbox

Public Members

public book: Object source

container for books and book settings

public books: Array<Object> source

list of all books

public inbox: Array<number[]> source

inbox for pre-orders from internal processes such as stops and triggers. new orders should also be pushed here.

public lastTrade: * source

Public Methods

public clear() source

clears or resets market to initial "new" condition, clearing active list, books, and trash

public currentAskPrice(): number | undefined source

market current Ask Price

Return:

number | undefined

price of lowest sell limit order from market sell limit order book, if any.

public currentBidPrice(): number | undefined source

market current Bid Price

Return:

number | undefined

price of highest buy limit order from market buy limit order book, if any.

public lastTradePrice(): number | undefined source

last trade price, if any.

Return:

number | undefined

public process(): number source

process order from the top of the inbox, returning inbox length

Return:

number

number of orders remaining in inbox

public submit(neworder: number[]): string | undefined source

submit order to the Market's inbox for eventual processing

Params:

NameTypeAttributeDescription
neworder number[]

a 17 element number array represeting an unentered order.

Return:

string | undefined

Error message on invalid order format, undefined on ok submission