Stock Bot

by Bkper

Manage Stock Book in sync with Financial Books upon buying and seling inventory instruments.

Stock Bot

It works by monitoring Financial Books and tracking quantities of instruments bought or sold in a separate Stock Book.

The process of tracking realized gains and losses upon sales follows the FIFO (First-In, First-Out) method.


Financial and Instruments Books must be in the same Collection.

Only a single Instruments Book should be defined per Collection.

The Instruments Book is identified by a single book in the Collection with the decimal places set to 0 (zero) or by the stock_book property set to true.

The Stock Bot interacts with the following properties:

Book Properties

Financial Books

Instruments Book

Group Properties

Account Properties

Transaction Properties

Realized Results Service

When calculating realized results, the market value of remaining instruments can be automatically adjusted on Financial Books to match the last realized price of that instrument. This valuation procedure is known as Mark-To-Market.

The Stock Bot adds the following properties to the generated transactions in the Instruments Book:

Observation: The properties starting with fwd above have the same meaning as their peers, however, their values may differ if a Forward Date was set to that instrument. In that case, there are also other fwd properties, which are references that connect forwarded transactions to their logs.

Forward Date Service

In order to close a period and set a closing date to the Stock Book, instruments must be carried to the next period. The proper way to do so is by setting a Forward Date to the accounts in the Instruments Book.

Each unchecked transaction will have its date, price and exchange rate updated to the current valuation, leaving a log of its previous state behind. When the last instrument is successfully forwarded a closing date will be set on the Stock Book one day before the Forward Date.

Once an instrument is forwarded, future FIFO calculations will consider the new Forward valuation. In order to keep calculating gains/losses over the historical basis, the property stock_historical must be set to true on the Instruments Book.

When forwarding instruments, the Stock Bot also adds the following properties to the forwarded transactions: