0.1.3 • Published 5 years ago

fifocount v0.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

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 }
// ]
0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago