<commit_before>import inspect

from django.db import models

from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User

from enum import Enum


class ChoiceEnum(Enum):
    @classmethod
    def choices(cls):
        # get all members of the class
        members = inspect.getmembers(cls, lambda m: not (inspect.isroutine(m)))
        # filter down to just properties
        props = [m for m in members if not (m[0][:2] == '__')]
        # format into django choice tuple
        choices = tuple([(str(p[1].value), p[0]) for p in props])
        return choices


class TradeTypes(ChoiceEnum):
    Market = 0
    Limit = 1


class SideTypes(ChoiceEnum):
    Buy = 0
    Sell = 1


class CurrencyTypes(ChoiceEnum):
    USD = 0
    BTC = 1


class BaseModel(models.Model):
    """Abstract base model that all other models should inherit from."""
    created_at = models.DateTimeField('Created at', auto_now_add=True)
    modified_at = models.DateTimeField('Modified at', auto_now=True)

    class Meta:
        abstract = True
        app_label = "exchange"
        verbose_name = _('BaseModel')
        verbose_name_plural = _('BaseModels')


class User(User):
    pass


class Order(BaseModel):
    order_type = models.CharField(max_length=1, choices=TradeTypes.choices())
    side = models.CharField(max_length=1, choices=SideTypes.choices())
    amount = models.DecimalField(max_digits=15,
                                 decimal_places=8)  # max digits are one million bitcoins times 10^8 to translate to satoshis
    limit = models.DecimalField(max_digits=13,
                                decimal_places=8)  # max digits is one ten thousand bitcoins times 10^8 to translate to satoshis
    from_currency = models.CharField(max_length=3, choices=CurrencyTypes.choices())
    to_currency = models.CharField(max_length=3,
                                   choices=CurrencyTypes.choices())  # it should not be possible for the from currency to equal the to currency


# these are generated by exchanges
class Trade(BaseModel):
    # the amount each unit from the buy_order will cost, expressed in terms of the sell currency
    rate = models.DecimalField(max_digits=15,
                               decimal_places=8)  # max_digits is 10^8 to convert to satoshis times 100 to account for decimal places
    buy_order = models.ForeignKey('Order', related_name="buy_order")
    sell_order = models.ForeignKey('Order', related_name="sell_order")
    filled = models.BooleanField(default=False)


# url where the exchange can be contacted, and base currency that the exchange uses
class Exchange(BaseModel):
    api_url = models.CharField(max_length=255)
    base_currency = models.CharField(max_length=3, choices=CurrencyTypes.choices())


#security supported by exchange
class ExchangeSecurity(BaseModel):
    exchange = models.ForeignKey('Exchange')
    currency_type = models.CharField(max_length=3, choices=CurrencyTypes.choices())


class Account(BaseModel):
    user = models.ForeignKey('User')
    currency_type = models.CharField(max_length=3, choices=CurrencyTypes.choices())
    balance = models.DecimalField(max_digits=15, decimal_places=8)<commit_msg>added Meta to model classes, and tweaked comments<commit_after>import inspect

from django.db import models

from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User

from enum import Enum


class ChoiceEnum(Enum):
    @classmethod
    def choices(cls):
        # get all members of the class
        members = inspect.getmembers(cls, lambda m: not (inspect.isroutine(m)))
        # filter down to just properties
        props = [m for m in members if not (m[0][:2] == '__')]
        # format into django choice tuple
        choices = tuple([(str(p[1].value), p[0]) for p in props])
        return choices


class TradeTypes(ChoiceEnum):
    Market = 0
    Limit = 1


class SideTypes(ChoiceEnum):
    Buy = 0
    Sell = 1


class CurrencyTypes(ChoiceEnum):
    USD = 0
    BTC = 1


class BaseModel(models.Model):
    """Abstract base model that all other models should inherit from."""
    created_at = models.DateTimeField('Created at', auto_now_add=True)
    modified_at = models.DateTimeField('Modified at', auto_now=True)

    class Meta:
        abstract = True
        app_label = "exchange"
        verbose_name = _('BaseModel')
        verbose_name_plural = _('BaseModels')


class User(User):
    pass


class Order(BaseModel):
    order_type = models.CharField(max_length=1, choices=TradeTypes.choices())
    side = models.CharField(max_length=1, choices=SideTypes.choices())
    amount = models.DecimalField(max_digits=15,
                                 decimal_places=8)  # up to 1,000,000
    limit = models.DecimalField(max_digits=13,
                                decimal_places=8)  # up to 10,000
    from_currency = models.CharField(max_length=3, choices=CurrencyTypes.choices())
    to_currency = models.CharField(max_length=3,
                                   choices=CurrencyTypes.choices())  # it should not be possible for the from currency to equal the to currency

    class Meta:
        app_label = "exchange"
        verbose_name = _('Order')
        verbose_name_plural = _('Orders')


# these are generated by exchanges
class Trade(BaseModel):
    # the amount each unit from the buy_order will cost, expressed in terms of the sell currency
    rate = models.DecimalField(max_digits=15,
                               decimal_places=8)  # up to 1,000,000
    buy_order = models.ForeignKey('Order', related_name="buy_order")
    sell_order = models.ForeignKey('Order', related_name="sell_order")
    filled = models.BooleanField(default=False)

    class Meta:
        app_label = "exchange"
        verbose_name = _('Trade')
        verbose_name_plural = _('Trades')


# url where the exchange can be contacted, and base currency that the exchange uses
class Exchange(BaseModel):
    api_url = models.CharField(max_length=255)
    base_currency = models.CharField(max_length=3, choices=CurrencyTypes.choices())

    class Meta:
        app_label = "exchange"
        verbose_name = _('Exchange')
        verbose_name_plural = _('Exchanges')


#security supported by exchange
class ExchangeSecurity(BaseModel):
    exchange = models.ForeignKey('Exchange')
    currency_type = models.CharField(max_length=3, choices=CurrencyTypes.choices())

    class Meta:
        app_label = "exchange"
        verbose_name = _('ExchangeSecurity')
        verbose_name_plural = _('ExchangeSecurities')


class Account(BaseModel):
    user = models.ForeignKey('User')
    currency_type = models.CharField(max_length=3, choices=CurrencyTypes.choices())
    balance = models.DecimalField(max_digits=15, decimal_places=8)

    class Meta:
        app_label = "exchange"
        verbose_name = _('Account')
        verbose_name_plural = _('Accounts')
{'fraction_non_alphanumeric': 0.09352413992483377, 'fraction_numerical': 0.013732292570106967, 'mean_word_length': 3.2868649318463445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '762947', 'n_tokens_mistral': 2081, 'n_tokens_neox': 1972, 'n_words': 544}