# docker-finance | modern accounting for the power-user
#
# Copyright (C) 2021-2024 Aaron Fiore (Founder, Evergreen Crypto LLC)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

fields date,type,security_,currency_,amount_,fiat_amount,price,fees,description,direction,subaccount

date-format %m/%d/%y

# TODO: how to handle 'ProShares Ultra Semiconductors', ticker 'USD' ...

account1 assets:etrade:%subaccount:%currency_
amount %amount_ %currency_

comment type:%type, security:%security_
if %direction [A-Z]
  comment type:%type, security:%security_, direction:%direction

# TODO: currently needs to be added manually
if %type ^Reorganization$
  skip

################################################################################
#                                                                              #
#                                 TRANSFER                                     #
#                                                                              #
################################################################################

if %direction ^IN$
  account2 equity:etrade:%subaccount:withdrawal:%currency_

if %direction ^IN$
& %security_ UNKNOWN
  amount %fiat_amount %currency_

if %direction ^OUT$
  amount -%amount_ %currency_
  account2 equity:etrade:%subaccount:deposit:%currency_

if %direction ^OUT$
& %security_ UNKNOWN
  amount -%fiat_amount %currency_

################################################################################
#                                                                              #
#                                   INCOME                                     #
#                                                                              #
################################################################################

if %type ^Interest$
  account1 assets:etrade:%subaccount:USD
  amount %fiat_amount USD
  account2 income:etrade:%subaccount:USD

################################################################################
#                                                                              #
#                                   TRADE                                      #
#                                                                              #
################################################################################

if %type (^Bought$|^Sold$)
  amount %amount_ %currency_ @ %price USD
  account2 assets:etrade:%subaccount:USD
  comment type:%type, security:%security_

if %type (^Bought$|^Sold$)
& %fees [1-9]
  account3 assets:etrade:%subaccount:USD
  amount3 -%fees USD
  account4 expenses:etrade:%subaccount:fees:trades:USD
  amount4 %fees USD

# vim: sw=2 sts=2 si ai et
