Automated Action b9798f0eaf Implement comprehensive crypto P2P trading platform
- Complete FastAPI application with JWT authentication
- SQLite database with SQLAlchemy ORM and Alembic migrations
- User registration/login with secure password hashing
- Multi-cryptocurrency wallet system with balance tracking
- Advertisement system for buy/sell listings with fund locking
- Order management with automatic payment integration
- Payment provider API integration with mock fallback
- Automatic crypto release after payment confirmation
- Health monitoring endpoint and CORS configuration
- Comprehensive API documentation with OpenAPI/Swagger
- Database models for users, wallets, ads, orders, and payments
- Complete CRUD operations for all entities
- Security features including fund locking and order expiration
- Detailed README with setup and usage instructions

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-26 14:48:18 +00:00

26 lines
1.1 KiB
Python

from sqlalchemy import Column, Integer, Float, DateTime, ForeignKey, Index
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.db.base import Base
class Wallet(Base):
__tablename__ = "wallets"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
cryptocurrency_id = Column(Integer, ForeignKey("cryptocurrencies.id"), nullable=False)
available_balance = Column(Float, default=0.0)
locked_balance = Column(Float, default=0.0) # Funds locked in active orders
created_at = Column(DateTime, server_default=func.now())
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
# Relationships
user = relationship("User", back_populates="wallets")
cryptocurrency = relationship("Cryptocurrency", back_populates="wallets")
@property
def total_balance(self):
return self.available_balance + self.locked_balance
# Ensure one wallet per user per cryptocurrency
__table_args__ = (Index('ix_user_crypto', 'user_id', 'cryptocurrency_id', unique=True),)