1.1.0 • Published 7 years ago
order-match v1.1.0
order-match
The account book to record the match of order asks and bids.
Install
$ npm i order-matchUsage
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.
undefinedwhich indicates there is no resistance.Object- action
Enum<ASK|BID> - orders
Array<{price, amount}>
- action
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
numberthe actual price of the trade - e.amount
numberthe amount of the trade - e.type
Enum<ASK|BID>
om.on('trade', e => {
console.log()
})License
MIT