示例#1
0
文件: trade.py 项目: anagels/python
 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:
                 if deals_with_commodities(
                     fields[Input.ACCOUNT_FROM],
                     fields[Input.ACCOUNT_TO]
                 ):
                     records = records + 1
                     # GENERAL INFO AT START
                     self.general_info_at_start(dba, calc, fields)
                     # UPDATE/INSERT
                     print "test: invade_started = ",
                     (self.open_trade_position > -1)
                     if self.open_trade_position > -1:
                         self.update_info(dba, calc, fields)
                     else:
                         self.insert_info(dba, calc, fields)
                     # GENERAL VARIABLES THAT CAN BE CALCULATED
                     # ON THE DATA WE HAVE
                     self.general_info_at_end(dba, fields, self.trade_record)
                     # TEST INFO
                     #self.print_test_info()
                     # ADDING THE STATEMENTS
                     self.add_to_statement(records)
                 self.finance_id = self.finance_id + 1
         return self.statement_trade
     except Exception as ex:
         print Error.CREATE_STATEMENTS_TABLE_TRADE, ex
     finally:
         calc = None
         dba = None
示例#2
0
文件: trade.py 项目: rockwolf/python
 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:
                 if deals_with_commodities(fields[Input.ACCOUNT_FROM],
                                           fields[Input.ACCOUNT_TO]):
                     records = records + 1
                     # GENERAL INFO AT START
                     self.general_info_at_start(dba, calc, fields)
                     # UPDATE/INSERT
                     print "test: invade_started = ",
                     (self.open_trade_position > -1)
                     if self.open_trade_position > -1:
                         self.update_info(dba, calc, fields)
                     else:
                         self.insert_info(dba, calc, fields)
                     # GENERAL VARIABLES THAT CAN BE CALCULATED
                     # ON THE DATA WE HAVE
                     self.general_info_at_end(dba, fields,
                                              self.trade_record)
                     # TEST INFO
                     #self.print_test_info()
                     # ADDING THE STATEMENTS
                     self.add_to_statement(records)
                 self.finance_id = self.finance_id + 1
         return self.statement_trade
     except Exception as ex:
         print Error.CREATE_STATEMENTS_TABLE_TRADE, ex
     finally:
         calc = None
         dba = None