Add basic portfolio logic

This changes the connection to fall back to a config file. It also
handles db errors more robustly.