1.1.0 • Published 5 years ago

order-match v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage

order-match

The account book to record the match of order asks and bids.

Install

$ npm i order-match

Usage

const OrderMatch = require('order-match')

const om = new OrderMatch()

new OrderMatch()

Creates an acount book of asks and bids

om.ask(price, amount)

  • price number
  • amount number

Ask a price

om.bid(price, amount)

Bid with a price

om.resistance(price): undefined | Object

Returns the plan against the resistance if we want to reach the price level.

  • undefined which indicates there is no resistance.
  • Object
    • action Enum<ASK|BID>
    • orders Array<{price, amount}>
const om = new OrderMatch()

om.ask(100, 50)
om.ask(120, 10)

// Then the asks are:
// price: 120, amount: 10
// price: 100, amount: 50

const plan = om.resistance(130)
console.log(plan.action)
// BID, we need bid orders to buy the asks
console.log(plan.orders)
// [
//   {price: 100, amount: 50},
//   {price: 120, amount: 50}
// ]

Getter: om.price number

Get the current price. The initial price is 0.

Getter: om.asks Array<{price, amount}>

Get current asks which is an ascending array of {price, amount} ordered by price

Getter: om.bids Array<{price, amount}>

Get current bids which is an decendng array of {price, amount} ordered by price

Event: 'trade'

  • e.price number the actual price of the trade
  • e.amount number the amount of the trade
  • e.type Enum<ASK|BID>
om.on('trade', e => {
  console.log()
})

License

MIT