Skip to content

FIFO count to calculate trades by using first in first out method

Notifications You must be signed in to change notification settings

kippisone/fifocount

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

FIFO count to calculate trades by using first in first out method

Resources

Stars

Watchers

Forks

Packages

No packages published