Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kaelzhang/order-match
The account book to record the match of order asks and bids
https://github.com/kaelzhang/order-match
fintech
Last synced: about 2 months ago
JSON representation
The account book to record the match of order asks and bids
- Host: GitHub
- URL: https://github.com/kaelzhang/order-match
- Owner: kaelzhang
- License: other
- Created: 2019-03-07T11:34:24.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-10T13:06:56.000Z (almost 6 years ago)
- Last Synced: 2024-12-13T13:16:21.420Z (about 2 months ago)
- Topics: fintech
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/kaelzhang/order-match.svg?branch=master)](https://travis-ci.org/kaelzhang/order-match)
[![Coverage](https://codecov.io/gh/kaelzhang/order-match/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/order-match)# order-match
The account book to record the match of order asks and bids.
## Install
```sh
$ npm i order-match
```## Usage
```js
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`
- **orders** `Array<{price, amount}>````js
const om = new OrderMatch()om.ask(100, 50)
om.ask(120, 10)// Then the asks are:
// price: 120, amount: 10
// price: 100, amount: 50const 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````js
om.on('trade', e => {
console.log()
})
```## License
MIT