Skip to content

Portfolio DB#158

Merged
8ball030 merged 20 commits intomainfrom
feat/portfolio_db
Jan 19, 2026
Merged

Portfolio DB#158
8ball030 merged 20 commits intomainfrom
feat/portfolio_db

Conversation

@Karrenbelt
Copy link
Collaborator

Adds database persistence for portfolio value tracking.

Key additions:

  • db_models.py: SQLAlchemy-based database module with PortfolioValue table
  • Portfolio snapshots saved to SQLite on each data collection round
  • Case-insensitive asset matching (i.e. handles weETH/WEETH variations)
  • Defensive data validation - only saves when complete venue data available

Configuration:

  • New parameter: db_config (defaults to sqlite:///../data/agent_data.db)

Comment on lines +20 to +24
def try_symbol_to_base_and_quote(symbol: str) -> tuple[str, str] | None:
if len(assets := symbol.upper().split("/")) == 2:
base_asset, quote_asset = assets
return base_asset, quote_asset
return None
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot do Python anymore. Rust has ruined it for me.

After working with Rust's type system, I've become acutely aware of how brittle string parsing is in Python. A single malformed ticker symbol could crash the entire agent.

Every time I see symbol.split("/") followed by tuple unpacking, I die a little inside. What if there's no /? What if there are two? The program just... crashes. No compiler to save you. No Option to make the failure path explicit.

This utility function is me trying to bring sanity to a codebase that assumes perfect input. It won't save us, but at least it's honest about failure. This whole framework is just giving me a headache 🤕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there wont be 2, thats not how these things work mate.
And its not really honest it just siilently fails now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you expecting?
A market caLLED ETH/BTC/LBTC?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image Goddamn it man

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I am expecting that the input data won't always be perfect. You CAN use defensive programming in python too. But you will need to be very meticulous and diligent in carrying out this dutiful responsibility. In Rust, however, there is always the compiler lurking over your code, enforcing you to be precise and explicit.

@8ball030 8ball030 marked this pull request as ready for review January 19, 2026 16:50
@8ball030 8ball030 merged commit 91e320e into main Jan 19, 2026
1 check passed
@8ball030 8ball030 deleted the feat/portfolio_db branch January 19, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants