fifocount

0.1.3 • Public • Published

FIFO count

FIFO count is a module to get a first in first out calculation of a list of trades.

Usage

import { FifoCount } from 'fifocount'
 
const fifo = new FifoCount()
 
 
// add trades
fifo.add({ "type": "in",  "amount": 12, "price": 120 })
fifo.add({ "type": "out", "amount": 3,  "price": 150 })
fifo.add({ "type": "out", "amount": 5,  "price": 180 })
fifo.add({ "type": "in",  "amount": 2,  "price": 190 })
fifo.add({ "type": "out", "amount": 6,  "price": 210 })
 
// calculate trades
const res = fifo.count()
 
// res === [
//   { inPrice: 120, outPrice: 150, amount: 3, profit: 90 },
//   { inPrice: 120, outPrice: 180, amount: 5, profit: 300 },
//   { inPrice: 190, outPrice: 210, amount: 6, profit: 400 }
// ]

Readme

Keywords

Package Sidebar

Install

npm i fifocount

Weekly Downloads

2

Version

0.1.3

License

MIT

Unpacked Size

6.91 kB

Total Files

8

Last publish

Collaborators

  • andifeind