This TypeScript library provides functionality to calculate Alpaca Markets
trading gains or losses based on FIFO using Alpaca <YYYYMMDD>.json
reports as inputs. We do this because
Alpaca no longer supports FIFO.
IMPORTANT: The alpaca-fifo
project DOES NOT generate tax forms of any kind. It helps you calculate gains
and losses in FIFO mode for your taxes.
git clone git@github.com:baloian/alpaca-fifo.git
cd alpaca-fifo
npm install
Create two directories, one for input (e.g. INPUTS
) and the other for outputs (e.g. OUTPUTS
).
Download all the Alpaca <YYYYMMDD>.json
files from your account documents and place them in the INPUTS
folder.
Please do not edit the filenames or their contents. Otherwise, the result will be incorrect.
You need to set up environment variables by creating a .env
file in the root directory and providing the following variables:
INPUTS=<absolute path of the inputs directory>
OUTPUTS=<Absolute path of the outputs directory>
In the root directory, execute the following command
npm run start
If running the project went successfully, then in the OUTPUTS
directory, you should see alpaca-fifo-<YYYY>.csv
and alpaca-fees-<YYYY>.csv
files for each year.
You can use the project asa dependency lib of your project.
npm install github:baloian/alpaca-fifo
Create an inputs
and outputs
directories and upload all the <YYYYMMDD>.json
files without any modifications in the inputs
directory.
import { AlpacaFIFO } from 'alpaca-fifo';
(async () => {
const alpacaFIFO = new AlpacaFIFO();
await alpacaFIFO.run({
inputDirPath: '<absolute path of the directory>',
outputDirPath: '<absolute path of the directory>'
});
})();
The run()
method takes an argument object with the following properties:
{
inputDirPath: <string>, // absolute path of the directory>',
outputDirPath: <string>, // <absolute path of the directory>'
writeToFile: <boolean>, // True if you want to write data to a .csv file. Default is true
callbackFn: <function> // Callback function. callback(txsData, feeData, year). Default is null
}
Contributions are welcome and can be made by submitting GitHub pull requests
to this repository. In general, the MarCal
source code follows
Airbnb JavaScript Style Guide and the
rules specified in .eslintrc.json
file.
This source code is available to everyone under the standard MIT LICENSE.