The three golden rules of accounting are (1) debit all expenses and losses, credit all incomes and gains, (2) debit the receiver, credit the giver, and (3) debit what comes in, credit what goes out. These rules are the basis of double-entry accounting, first attributed to Luca Pacioli.
One way to put these golden rules into practice for programmatic money movement is a double-entry ledger, as shown below for fictional company Bagel.co.
Imagine Bagel.co allows users to buy, sell, and trade bagels, moving funds between accounts the company operates on behalf of customers. Supposing three customers (1) buy and sell bagels to each other, and (2) cash out the balances of their accounts on Bagel.co’s platform to external banks, below is an example double-entry ledger of their transactions.