Skip to main content
All CollectionsAutomationsBots
Bkper Stock Bot (Stock Exchange)
Bkper Stock Bot (Stock Exchange)

Record quantities and calculate profits and losses on trading operations

Updated over a week ago

The Stock Bot keeps track of quantities, profits and losses and revaluations related to financial operations.

Record the purchase of $ 1000.00 in stock and the Stock Bot records 5 shares related to this purchase.

Record the sale of 2 shares at a selling price of $ 250.00. The Stock Bot records the quantity of 2 shares less related to this sale and the Stock Bot records a profit of $ 100.00 for this sale and valuates the 3 remaining shares at a value of $ 750.00.

Profit or Loss is calculated on a FIFO basis.

This help article explains how to use the Stock Bot in Stock exchange operations with market to market valuation and short sales.

The Bkper Stock bot is a robust and reliable work force, working at our clients where it keeps track of thousands of stock operations each month.

Overview

On Bkper you track different entities in different books, so to keep track of finances you need a financial book and to track stock you need another book to track quantities, in this case called an Instruments book.

For the Stock Bot to understand its boundaries of operation, it requires that (all) these

books are in one Bkper Collection.

Note: you can have as many currencies in one collection for the Stock Bot as you need.

The Stock Bot is triggered in the financial books on each Post and check transaction event. Once a stock operation is identified by some properties that we’ll explain a bit later, it will send the transaction data to the Stock Bot operating on the instruments book which records the same transaction resembling it in quantities.

Installation

Create the Financial Books

Create an Instruments Book

Add all the books to one Bkper Collection

Install the Stock Bot on all the financial Books

Install the Stock Bot on the Instruments Book

Stock Bot Status

Blue: working properly

Red: error

No icon: not installed

Note: This status is given per bot on each book and not for all the bots operating on the books in the collection

Bot Flow

1. Post a transaction that represents a stock order purchase on a financial book.

e.g. 100 Bank account >> Exchange 10 Stock

2. This Post event Triggers the Stock Bot on this financial book.

3. The Stock Bot finds the required stock properties on the transaction and gets into Action.

4. The Stock Bot on the financial book gathers all the data from this transaction including the property information :

- Creates a Fee transaction and a Stock transaction on the financial book

5. Check the Stock purchase transaction.

90 Exchange >> Stock

6. This check event Triggers the Stock Bot on the financial book.

7. The Stock Bot finds the required stock properties on the transaction and gets into Action.

8. It gathers all the data from this transaction including the new property information and sends it to the Stock Bot on the Instruments book.

9. The Stock Bot on the instruments book records a transaction on this book resembling the same purchase but in quantities rather than value.

10. The Stock Bot on the Instruments book records a transaction on Instruments book resembling the same purchase but in quantities rather than value.

Accounts

The accounts needed for the Stock Bot to work properly.

On the Financial Book

Asset accounts

A Bank Account: JP Morgan

An Exchange Account: JP Morgan Exchange

A Stock Account: BKPER

Outgoing accounts

A Fees account: Fees

On the Instruments Book

Asset Accounts

Stock Account: BKPER

Note: it is the same stock account as on the financial book:

Groups

On the Financial Book

Add the "stock" accounts to a "stock" group

e.g. NASDAQ

On the Instruments Book

Add the "stock" accounts to a "stock" group with the same name as in the financial book.

e.g. NASDAQ

Properties

To operate correctly the Stock Bot requires Book, Group, Account and Transaction properties.

Book Properties

On the Financial Books

Book one

exc_code : USD

Book two

exc_code : EUR

These properties are required by the other bots in the collection to identify where the financials were recorded for this particular exc_code.

On the Instruments Book

stock_book : true

This property identifies for the financial stock bot the book where the quantities are recorded within the collection.

Group Properties

On all the "stock" groups in the financial and Instruments Books add the stock_exc_code property.

On the Financial Books

Book one Group NASDAQ

stock_exc_code : USD

Book two Group DAX

stock_exc_code : EUR

On the Instruments Book

Group NASDAQ

stock_exc_code : USD

Group DAX

stock_exc_code : EUR

The Stock bot uses this exchange code to keep groups in sync between the books in this collection. So if you add a new stock account to one group in your financial book, it will automatically be added to the group on the instruments book and vice versa.

It also helps the Stock Bot operating on the Instrument Book to find the way back to the origin of the transaction. (book > group > account)

Note: you can give this group property any value that makes sense to your operation but in one financial book the book property exc_code should have the same value as this group property stock_exc_code. For example exc_code: USD and

stock_exc_code:USD

Account Properties

The Exchange Account (JP Morgan Exchange) has a fees account property that indicates the outgoing account where stock operation Fees are booked.

Exchange Account

stock_fees_account : Fees Account

Transaction Properties

Transactions that represent the purchase order at the Exchange Account should have the following properties :

instrument : BKPER
quantity : #
trade_date : mm/dd/yyyy
fees : $ [optional]
interest : $ [optional]
order: # [optional]

Trigger the Stock Bot

The Stock Bot is triggered on the financial books by Posting the transaction that has the instrument, quantity and trade_date properties. It continues its actions when the posted transaction has an instrument account that is part of the stock group identified by the stock_exc_code property.

The Stock Bot is triggered on the financial book by checking the transaction that has the quantity property. It continues its actions when the checked transaction has a stock account that is part of the stock group identified by the stock_exc_code property.

Action from the Stock Bot

The Stock Bot on the financial book collects the data from the posted stock order transaction.

From the collected data on the posted transaction it creates two transactions on the Financial Book.

On the Financial Book

A transaction that actually represents the purchase of the Stock

n Exchange Account >> Stock

The Stock Bot also adds properties to the newly recorded transaction that refers to the stock order.

fees:$
interest:$
price:$$
quantity: #

A transaction that represents the payment of the fees on this operation

n Exchange Account >> Fees

The Stock Bot on the financial book collects the data from the checked stock transaction.

On the Instruments Book

The collected data is passed to the Stock Bot on the instruments book which records a transaction that represents the same operation but the balance value of the stock account in this book represents the quantity rather than its value.

The Stock Bot also adds properties to the newly recorded transaction that refers to the financial operation.

original_amount: $$
original_quantity: n
purchase_price: $

Example

Did this answer your question?