<commit_before>from datetime import datetime
from zaifbot.common.action import Action, Buy
from zaifbot.currency_pairs import CurrencyPair
from zaifbot.dao.trades import TradesDao


class Trade:
    def __init__(self):
        self.currency_pair = None
        self.entry_datetime = None
        self.entry_price = None
        self.amount = None
        self.action = None
        self.exit_price = None
        self.exit_datetime = None
        self._dao = TradesDao
        self.id = None
        self.closed = False

    def entry(self, currency_pair, amount, entry_price, action):
        self.currency_pair = CurrencyPair(currency_pair)
        self.amount = amount
        self.entry_price = entry_price
        self.action = Action(action)
        self.entry_datetime = datetime.now()

        trade_obj = self._dao.create(currency_pair=str(self.currency_pair),
                                     amount=self.amount,
                                     entry_price=self.entry_price,
                                     action=str(self.action),
                                     entry_datetime=self.entry_datetime)
        self.id = trade_obj.id

    def exit(self, exit_price):
        self.exit_price = exit_price
        self.exit_datetime = datetime.now()

        self._dao.update(exit_price=self.exit_price,
                         exit_datetime=self.exit_datetime,
                         profit=self.profit())

        self.closed = True

    def profit(self):
        if self.action == Buy:
            return self.exit_price - self.entry_price
        else:
            return self.entry_price - self.exit_price
<commit_msg>add short long<commit_after>from datetime import datetime
from zaifbot.common.action import Action, Buy, Sell
from zaifbot.currency_pairs import CurrencyPair
from zaifbot.dao.trades import TradesDao


class Trade:
    def __init__(self):
        self.currency_pair = None
        self.entry_datetime = None
        self.entry_price = None
        self.amount = None
        self.action = None
        self.exit_price = None
        self.exit_datetime = None
        self._dao = TradesDao
        self.id = None
        self.closed = False

    def entry(self, currency_pair, amount, entry_price, action):
        self.currency_pair = CurrencyPair(currency_pair)
        self.amount = amount
        self.entry_price = entry_price
        self.action = Action(action)
        self.entry_datetime = datetime.now()

        trade_obj = self._dao.create(currency_pair=str(self.currency_pair),
                                     amount=self.amount,
                                     entry_price=self.entry_price,
                                     action=str(self.action),
                                     entry_datetime=self.entry_datetime)
        self.id = trade_obj.id

    def exit(self, exit_price):
        self.exit_price = exit_price
        self.exit_datetime = datetime.now()

        self._dao.update(exit_price=self.exit_price,
                         exit_datetime=self.exit_datetime,
                         profit=self.profit())

        self.closed = True

    def profit(self):
        if self.action == Buy:
            return self.exit_price - self.entry_price
        else:
            return self.entry_price - self.exit_price

    @property
    def is_short(self):
        return self.action == Sell

    @property
    def is_long(self):
        return self.action == Buy

{'fraction_non_alphanumeric': 0.07616565305531423, 'fraction_numerical': 0.0, 'mean_word_length': 1.808130081300813, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4373693', 'n_tokens_mistral': 941, 'n_tokens_neox': 924, 'n_words': 193}