Add trading journal and portfolio tracking
This commit is contained in:
+25
-2
@@ -83,8 +83,9 @@ def initialize(path=None):
|
||||
('Bayer','stock'), ('STOXX Global Select Dividend 100','etf'), ('airBaltic','bond')]:
|
||||
ensure_asset(db, name, kind)
|
||||
_update_interest_positions(db)
|
||||
if db.execute('PRAGMA user_version').fetchone()[0] < 2:
|
||||
db.execute('PRAGMA user_version = 2')
|
||||
_create_trading_schema(db)
|
||||
if db.execute('PRAGMA user_version').fetchone()[0] < 3:
|
||||
db.execute('PRAGMA user_version = 3')
|
||||
|
||||
|
||||
def _update_interest_positions(db):
|
||||
@@ -98,3 +99,25 @@ def _update_interest_positions(db):
|
||||
db.execute('UPDATE assets SET active=0 WHERE normalized_name IN (?,?)',
|
||||
(name_key('Zinsen'), name_key('Steuerrückzahlung')))
|
||||
db.execute('INSERT INTO data_migrations (name) VALUES (?)', (migration,))
|
||||
|
||||
|
||||
def _create_trading_schema(db):
|
||||
# Transactional DDL: retain every existing table and income entry.
|
||||
db.execute("""CREATE TABLE IF NOT EXISTS transactions (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
date TEXT NOT NULL,
|
||||
asset_id INTEGER NOT NULL REFERENCES assets(id) ON DELETE RESTRICT,
|
||||
transaction_type TEXT NOT NULL CHECK(transaction_type IN ('buy','sell')),
|
||||
quantity TEXT NOT NULL CHECK(typeof(quantity)='text'),
|
||||
price_per_unit TEXT NOT NULL CHECK(typeof(price_per_unit)='text'),
|
||||
currency TEXT NOT NULL CHECK(length(currency)=3),
|
||||
fees TEXT NOT NULL DEFAULT '0.00' CHECK(typeof(fees)='text'),
|
||||
source TEXT NOT NULL DEFAULT 'manual' CHECK(source IN ('manual','savings_plan','roundup','cashback','rebalancing','other')),
|
||||
strategy_tag TEXT CHECK(strategy_tag IN ('core','income','conviction','dip_buy','speculation','rebalancing','other')),
|
||||
note TEXT,
|
||||
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
||||
)""")
|
||||
db.execute('CREATE INDEX IF NOT EXISTS transactions_asset_date ON transactions(asset_id,date,id)')
|
||||
db.execute('CREATE INDEX IF NOT EXISTS transactions_date ON transactions(date DESC,id DESC)')
|
||||
db.execute('INSERT OR IGNORE INTO data_migrations(name) VALUES (?)', ('2026-09-09-trading-schema',))
|
||||
|
||||
Reference in New Issue
Block a user