Beispiel #1
0
    def create_statements(self, input_fields):
        """
            Creates the records needed for Table.FINANCE
            and returns them as a Statement object.
        """
        try:
            dba = DatabaseAccess(self.config)
            date_created = current_date()
            date_modified = current_date()
            statement_finance = Statement(T_FINANCE)
            records = 0
            currency_exchange_id = dba.first_currency_exchange_id_from_latest()
            rate_id = dba.first_rate_id_from_latest()
            for fields in input_fields:
                account_from_id = dba.account_id_from_account_name(
                    fields[Input.ACCOUNT_FROM], True)
                account_to_id = dba.account_id_from_account_name(
                    fields[Input.ACCOUNT_TO], False)

                #NOTE: in the database, the first values in the tables of the
                #below id's, are empty/dummy values, used for when we are not
                #dealing with stocks.
                rate_id = 1
                if deals_with_commodities(
                    fields[Input.ACCOUNT_FROM],
                    fields[Input.ACCOUNT_TO]
                ):
                    rate_id = dba.get_latest_rate_id()

                amount_value = fields[Input.AMOUNT]
                if is_negative_amount(fields[Input.ACCOUNT_FROM]):
                    amount_value = Decimal(-1.0) * amount_value

                records = records + 1
                statement_finance.add(
                    records,
                    {
                        'finance_id': None,
                        'date': fields[Input.DATE],
                        'year': fields[Input.DATE].year,
                        'month': fields[Input.DATE].month,
                        'day': fields[Input.DATE].day,
                        'account_from_id': account_from_id,
                        'account_to_id': account_to_id,
                        'amount': amount_value,
                        'comment': fields[Input.COMMENT],
                        'currency_exchange_id': currency_exchange_id,
                        'rate_id': rate_id,
                        'active': 1,
                        'date_created': date_created,
                        'date_modified': date_modified
                    }
                )
                currency_exchange_id = currency_exchange_id + 1
            print 'test: ', statement_finance.statements_insert
            return statement_finance
        except Exception as ex:
            print Error.CREATE_STATEMENTS_TABLE_FINANCE, ex
        finally:
            dba = None
Beispiel #2
0
 def __init__(self, config):
     """
         Initialisation
     """
     self.config = config
     self.statement_rate = Statement(T_RATE)
     self.commission = DEFAULT_DECIMAL
     self.tax = DEFAULT_DECIMAL
     self.date_created = DEFAULT_DATE
     self.date_modified = DEFAULT_DATE
Beispiel #3
0
 def create_statements(self, input_fields):
     """
         Creates the records needed for Table.CURRENCY_EXCHANGE.
     """
     try:
         dba = DatabaseAccess(self.config)
         statement_currency_exchange = Statement(T_CURRENCY_EXCHANGE)
         date_created = current_date()
         date_modified = current_date()
         records = 0
         for fields in input_fields:
             records = records + 1
             #NOTE: we don't need to query, because we always add a new
             #currency_exchange line. The same value can be used multiple
             #times, so it's not possible to query if one already exists.
             statement_currency_exchange.add(
                 records, {
                     'currency_exchange_id':
                     None,
                     'currency_from_id':
                     dba.currency_id_from_currency(
                         fields[Input.CURRENCY_FROM]),
                     'currency_to_id':
                     dba.currency_id_from_currency(
                         fields[Input.CURRENCY_TO]),
                     'exchange_rate':
                     Decimal(fields[Input.EXCHANGE_RATE]),
                     'date_created':
                     date_created,
                     'date_modified':
                     date_modified
                 })
         return statement_currency_exchange
     except Exception as ex:
         print Error.CREATE_STATEMENTS_TABLE_CURRENCY_EXCHANGE, ex
     finally:
         dba = None
Beispiel #4
0
 def __init__(self, config):
     """
         Initialisation
     """
     self.config = config
     self.statement_trade = Statement(T_TRADE)
     self.flag_insupdel = StatementType.INSERT
     self.trade_id = DEFAULT_INT
     self.market_id = DEFAULT_INT
     self.commodity_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_buy_orig = DEFAULT_DECIMAL
     self.price_sell = DEFAULT_DECIMAL
     self.price_sell_orig = 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 = DEFAULT_DECIMAL
     self.amount_sell = DEFAULT_DECIMAL
     self.amount_buy_simple = DEFAULT_DECIMAL
     self.amount_sell_simple = DEFAULT_DECIMAL
     self.stoploss = DEFAULT_DECIMAL
     self.stoploss_orig = DEFAULT_DECIMAL
     self.profit_loss = DEFAULT_DECIMAL
     self.profit_loss_orig = DEFAULT_DECIMAL
     self.profit_loss_total = DEFAULT_DECIMAL
     self.profit_loss_total_percent = DEFAULT_DECIMAL
     self.r_multiple = DEFAULT_DECIMAL
     self.win_flag = DEFAULT_DECIMAL
     self.id_buy = DEFAULT_INT
     self.id_sell = DEFAULT_INT
     self.drawdown_id = DEFAULT_INT
     self.pool_at_start = DEFAULT_DECIMAL
     self.date_expiration = DEFAULT_DATE
     self.expired_flag = DEFAULT_INT
     self.spread = DEFAULT_INT
     self.active = DEFAULT_INT
     self.date_created = DEFAULT_DATE
     self.date_modified = DEFAULT_DATE
     self.trade_record = []
     self.open_trade_position = -1