<commit_before>#! /usr/local/bin/python
"""
    See LICENSE file for copyright and license details.
"""

from datetime import datetime

from database.databaseaccess import DatabaseAccess
from modules.core_module import CoreModule
from modules.statement import Statement
from modules.constant import *
from modules.function import *
from generic.modules.function import *
from database.mappings import T_TRADE
from generic.modules.calculator_finance import CalculatorFinance

class Trade(CoreModule):
    """
        Trade class.
    """

    def __init__(self, config):
        """
            Initialisation
        """
        self.config = config
        self.statement_trade = Statement(Table.TRADE)
        self.flag_insupdel = StatementType.INSERT
        self.trade_id = DEFAULT_INT
        self.market_id = DEFAULT_INT
        self.commodity_name = ''
        self.date_buy = DEFAULT_DATE
        self.year_buy = DEFAULT_INT
        self.month_buy = DEFAULT_INT
        self.day_buy = DEFAULT_INT
        self.date_sell = DEFAULT_DATE
        self.year_sell = DEFAULT_INT
        self.month_sell = DEFAULT_INT
        self.day_sell = DEFAULT_INT
        self.long_flag = DEFAULT_INT
        self.price_buy = DEFAULT_DECIMAL
        self.price_sell = DEFAULT_DECIMAL
        self.shares_buy = DEFAULT_DECIMAL
        self.shares_sell = DEFAULT_DECIMAL
        self.commission_buy = DEFAULT_DECIMAL
        self.commission_sell = DEFAULT_DECIMAL
        self.tax_buy = DEFAULT_DECIMAL
        self.tax_sell = DEFAULT_DECIMAL
        self.risk_input = DEFAULT_DECIMAL
        self.risk_input_percent = DEFAULT_DECIMAL
        self.risk_initial = DEFAULT_DECIMAL
        self.risk_initial_percent = DEFAULT_DECIMAL
        self.risk_actual = DEFAULT_DECIMAL
        self.risk_actual_percent = DEFAULT_DECIMAL
        self.cost_total = DEFAULT_DECIMAL
        self.cost_other = DEFAULT_DECIMAL
        self.amount_buy_simple = DEFAULT_DECIMAL
        self.amount_sell_simple = DEFAULT_DECIMAL
        self.stoploss = DEFAULT_DECIMAL
        self.profit_loss = DEFAULT_DECIMAL
        self.profit_loss_percent = DEFAULT_DECIMAL
        self.r_multiple = DEFAULT_DECIMAL
        self.win_flag = DEFAULT_DECIMAL
        self.id_buy = DEFAULT_INT
        self.id_sell = DEFAULT_INT
        self.currency_exchange_id = DEFAULT_INT
        self.drawdown_id = DEFAULT_INT
        self.pool_at_start = DEFAULT_DECIMAL
        self.date_expiration = DEFAULT_DATE
        self.expired_flag = DEFAULT_INT
        self.active = DEFAULT_INT
        self.date_created = DEFAULT_DATE
        self.date_modified = DEFAULT_DATE
        self.trade_record = []

    def create_statements(self, input_fields, statements_finance):
        """
            Creates the records needed for Table.TRADE and returns them as a
            Statement object.
        """
        #NOTE: price_buy will be fields['i_amount']
        #When we buy more, it will be overwritten!
        #Trading without adding to positions is assumed by this code!
        try:
            dba = DatabaseAccess(self.config)
            calc = CalculatorFinance()
            self.date_created = current_date()
            self.date_modified = current_date()
            records = 0
            self.finance_id = dba.first_finance_id_from_latest()
            if self.finance_id != -1:
                for fields in input_fields:<commit_msg>comment changed.<commit_after>#! /usr/local/bin/python
"""
    See LICENSE file for copyright and license details.
"""

from datetime import datetime

from database.databaseaccess import DatabaseAccess
from modules.core_module import CoreModule
from modules.statement import Statement
from modules.constant import *
from modules.function import *
from generic.modules.function import *
from database.mappings import T_TRADE
from generic.modules.calculator_finance import CalculatorFinance

class Trade(CoreModule):
    """
        Trade class.
    """

    def __init__(self, config):
        """
            Initialisation
        """
        self.config = config
        self.statement_trade = Statement(Table.TRADE)
        self.flag_insupdel = StatementType.INSERT
        self.trade_id = DEFAULT_INT
        self.market_id = DEFAULT_INT
        self.commodity_name = ''
        self.date_buy = DEFAULT_DATE
        self.year_buy = DEFAULT_INT
        self.month_buy = DEFAULT_INT
        self.day_buy = DEFAULT_INT
        self.date_sell = DEFAULT_DATE
        self.year_sell = DEFAULT_INT
        self.month_sell = DEFAULT_INT
        self.day_sell = DEFAULT_INT
        self.long_flag = DEFAULT_INT
        self.price_buy = DEFAULT_DECIMAL
        self.price_sell = DEFAULT_DECIMAL
        self.shares_buy = DEFAULT_DECIMAL
        self.shares_sell = DEFAULT_DECIMAL
        self.commission_buy = DEFAULT_DECIMAL
        self.commission_sell = DEFAULT_DECIMAL
        self.tax_buy = DEFAULT_DECIMAL
        self.tax_sell = DEFAULT_DECIMAL
        self.risk_input = DEFAULT_DECIMAL
        self.risk_input_percent = DEFAULT_DECIMAL
        self.risk_initial = DEFAULT_DECIMAL
        self.risk_initial_percent = DEFAULT_DECIMAL
        self.risk_actual = DEFAULT_DECIMAL
        self.risk_actual_percent = DEFAULT_DECIMAL
        self.cost_total = DEFAULT_DECIMAL
        self.cost_other = DEFAULT_DECIMAL
        self.amount_buy_simple = DEFAULT_DECIMAL
        self.amount_sell_simple = DEFAULT_DECIMAL
        self.stoploss = DEFAULT_DECIMAL
        self.profit_loss = DEFAULT_DECIMAL
        self.profit_loss_percent = DEFAULT_DECIMAL
        self.r_multiple = DEFAULT_DECIMAL
        self.win_flag = DEFAULT_DECIMAL
        self.id_buy = DEFAULT_INT
        self.id_sell = DEFAULT_INT
        self.currency_exchange_id = DEFAULT_INT
        self.drawdown_id = DEFAULT_INT
        self.pool_at_start = DEFAULT_DECIMAL
        self.date_expiration = DEFAULT_DATE
        self.expired_flag = DEFAULT_INT
        self.active = DEFAULT_INT
        self.date_created = DEFAULT_DATE
        self.date_modified = DEFAULT_DATE
        self.trade_record = []

    def create_statements(self, input_fields, statements_finance):
        """
            Creates the records needed for Table.TRADE and returns them as a
            Statement object.
        """
        #NOTE: price_buy will be fields['i_price']
        #When we buy more, it will be overwritten!
        #Trading without adding to positions is assumed by this code!
        try:
            dba = DatabaseAccess(self.config)
            calc = CalculatorFinance()
            self.date_created = current_date()
            self.date_modified = current_date()
            records = 0
            self.finance_id = dba.first_finance_id_from_latest()
            if self.finance_id != -1:
                for fields in input_fields:
{'fraction_non_alphanumeric': 0.06115531977600943, 'fraction_numerical': 0.0005894488653109342, 'mean_word_length': 2.4716112531969308, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1044990', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1911, 'n_words': 414}