
- 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>
43 lines
2.2 KiB
Python
43 lines
2.2 KiB
Python
from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey, Enum, Text
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from app.db.base import Base
|
|
import enum
|
|
|
|
class OrderStatus(str, enum.Enum):
|
|
PENDING = "pending" # Order placed, waiting for payment
|
|
PAYMENT_PENDING = "payment_pending" # Payment details provided, waiting for payment confirmation
|
|
PAYMENT_CONFIRMED = "payment_confirmed" # Payment confirmed, crypto will be released
|
|
COMPLETED = "completed" # Crypto released to buyer
|
|
CANCELLED = "cancelled" # Order cancelled
|
|
DISPUTED = "disputed" # Order in dispute
|
|
|
|
class Order(Base):
|
|
__tablename__ = "orders"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
advertisement_id = Column(Integer, ForeignKey("advertisements.id"), nullable=False)
|
|
buyer_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
seller_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
cryptocurrency_id = Column(Integer, ForeignKey("cryptocurrencies.id"), nullable=False)
|
|
|
|
crypto_amount = Column(Float, nullable=False) # Amount of crypto being traded
|
|
fiat_amount = Column(Float, nullable=False) # Amount in fiat currency
|
|
price = Column(Float, nullable=False) # Price per unit at time of order
|
|
|
|
status = Column(Enum(OrderStatus), default=OrderStatus.PENDING)
|
|
payment_account_number = Column(String) # Account number provided by payment provider
|
|
payment_reference = Column(String) # Payment reference for tracking
|
|
|
|
created_at = Column(DateTime, server_default=func.now())
|
|
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
|
|
expires_at = Column(DateTime) # Order expiration time
|
|
|
|
notes = Column(Text) # Additional notes from buyer/seller
|
|
|
|
# Relationships
|
|
advertisement = relationship("Advertisement", back_populates="orders")
|
|
buyer = relationship("User", foreign_keys=[buyer_id], back_populates="buy_orders")
|
|
seller = relationship("User", foreign_keys=[seller_id], back_populates="sell_orders")
|
|
cryptocurrency = relationship("Cryptocurrency", back_populates="orders")
|
|
payments = relationship("Payment", back_populates="order") |