mirror of
https://github.com/Zproger/Aurum.git
synced 2026-10-13 02:56:39 +07:00
feat: full CoinMarketCap-style crypto portfolio (buy/sell log, 1h/24h/7d%, P&L)
Replaces the plain quantity field with a CryptoTransaction log (same
"record events, derive the total" shape as Goal/GoalContribution): quantity
and average buy price are now computed via weighted-average cost — a buy
blends into the running average, a sell reduces quantity but leaves the
average cost of what's still held unchanged.
Switches price fetching from /simple/price to CoinGecko's /coins/markets
(still one batched call for every coin), which also returns 1h/24h/7d %
change in the same request. Old PATCH /crypto/holdings/{id} is replaced by
POST .../transactions (buy/sell, rejects selling more than held), GET
.../transactions (history), and DELETE /crypto/transactions/{id}.
Frontend: CryptoHoldingsTable replaces the simple list with a real table
(Name/Price/1h%/24h%/7d%/Holdings/Avg Buy Price/Profit-Loss/Actions),
horizontally scrollable on mobile rather than dropping columns. New
CryptoTransactionModal (buy/sell) and CryptoTransactionHistoryModal.
Backend: 79/79 tests passing (13 in test_crypto.py, up from 9). Also
verified live end-to-end against the real CoinGecko API with the user's own
key — create, buy, sell, oversell rejection, history, manual refresh, all
against real BTC/ETH prices in EUR — test data cleaned up after.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01855PiW5Wd8n4aRW4n9kByY
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""add crypto holdings and sync state
|
||||
"""add crypto holdings, transactions, and sync state
|
||||
|
||||
Revision ID: 3e3503b61b20
|
||||
Revises: f6a4d8b2e017
|
||||
@@ -26,12 +26,36 @@ def upgrade() -> None:
|
||||
sa.Column('symbol', sa.String(length=20), nullable=False),
|
||||
sa.Column('name', sa.String(length=150), nullable=False),
|
||||
sa.Column('thumb_url', sa.String(length=500), nullable=True),
|
||||
sa.Column('quantity', sa.Numeric(precision=38, scale=18), nullable=False),
|
||||
# Cached from the last successful CoinGecko sync — quantity and
|
||||
# average buy price are computed from crypto_transactions instead
|
||||
# of stored here (see models/crypto.py).
|
||||
sa.Column('last_price', sa.Numeric(precision=38, scale=18), nullable=True),
|
||||
sa.Column('price_change_1h', sa.Numeric(precision=10, scale=4), nullable=True),
|
||||
sa.Column('price_change_24h', sa.Numeric(precision=10, scale=4), nullable=True),
|
||||
sa.Column('price_change_7d', sa.Numeric(precision=10, scale=4), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['asset_id'], ['assets.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('asset_id'),
|
||||
)
|
||||
op.create_table(
|
||||
'crypto_transactions',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('asset_id', sa.Integer(), nullable=False),
|
||||
sa.Column(
|
||||
'type',
|
||||
sa.Enum('BUY', 'SELL', name='crypto_transaction_type', native_enum=False, length=10),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column('quantity', sa.Numeric(precision=38, scale=18), nullable=False),
|
||||
sa.Column('price_per_unit', sa.Numeric(precision=38, scale=18), nullable=False),
|
||||
sa.Column('date', sa.Date(), nullable=False),
|
||||
sa.Column('note', sa.Text(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['asset_id'], ['crypto_holdings.asset_id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
)
|
||||
op.create_table(
|
||||
'crypto_sync_state',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
@@ -42,4 +66,5 @@ def upgrade() -> None:
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table('crypto_sync_state')
|
||||
op.drop_table('crypto_transactions')
|
||||
op.drop_table('crypto_holdings')
|
||||
|
||||
Reference in New Issue
Block a user