def test_fix_duplicate_key_value(self):
        records = []
        records.append({'KeyValue': 'x', 'v': 10})
        records.append({'KeyValue': 'x', 'v': 20})
        records.append({'KeyValue': 'x', 'v': 30})

        try:
            fix_duplicate_key_value(records)
            self.assertEqual(records[0], {'KeyValue': 'x', 'v': 10})
            self.assertEqual(records[1], {'KeyValue': 'x_1', 'v': 20})
            self.assertEqual(records[2], {'KeyValue': 'x_2', 'v': 30})

        except:
            self.fail()
Example #2
0
def convert12734(files):
	"""
	Convert the trade files from settlement to Geneva format for quick trade
	import.

	files: a list of trade files.
	"""
	output_list = []
	error_list = []
	for f in files:
		logger.debug('convert12734(): read file {0}'.format(f))
		read_transaction_file(f, output_list, error_list)

	records = convert_to_geneva_records(output_list)
	fix_duplicate_key_value(records)

	if len(error_list) > 0:
		print('There are {0} rows in error, check log file'.format(len(error_list)))

	return records
Example #3
0
def generate_match_records(match_file, transaction_file):
    """
	From the match status file and the transaction file, create the list of
	records that fix the unmatched positions.
	"""
    match_status = read_match_status(match_file)
    # print('{0} match status read'.format(len(match_status)))
    # print('\n++++++++++++++++\n')
    # for entry in match_status:
    # 	print(entry)

    isin_list = [entry[2] for entry in match_status]
    transaction_list = []
    read_transaction_file(transaction_file, isin_list, transaction_list)
    matched_transaction_list, bad_isin_list = filter_matched_transaction(
        transaction_list, match_status)
    records = convert_to_geneva_records(matched_transaction_list)
    fix_duplicate_key_value(records)
    print('{0} records generated'.format(len(records)))
    verify_records(match_status, records, bad_isin_list)
    return records
    def test_ftcsa2(self):
        match_file = get_current_path(
        ) + '\\samples\\12366 match results 0118 morning.xlsx'
        transaction_file = get_current_path(
        ) + '\\samples\\transactions 12366 no initial pos.xls'
        match_status = read_match_status(match_file)
        isin_list = [entry[2] for entry in match_status]
        transaction_list = []
        read_transaction_file(transaction_file, isin_list, transaction_list)
        # print(len(transaction_list))
        matched_transaction_list, bad_isin_list = filter_matched_transaction(
            transaction_list, match_status)
        records = convert_to_geneva_records(matched_transaction_list)
        fix_duplicate_key_value(records)
        try:
            verify_records(match_status, records, bad_isin_list)
        except:
            self.fail('verify records function failed')

        # from a IATSA transaction
        self.verify_record6(
            self.find_record(records, 'FR0013101599 HTM', 'Buy', 28000000))
    def test_ftcsa(self):
        match_file = get_current_path(
        ) + '\\samples\\12229 match results 0118 morning.xlsx'
        transaction_file = get_current_path(
        ) + '\\samples\\transactions 12229 no initial pos.xls'
        match_status = read_match_status(match_file)
        isin_list = [entry[2] for entry in match_status]
        transaction_list = []
        read_transaction_file(transaction_file, isin_list, transaction_list)
        matched_transaction_list, bad_isin_list = filter_matched_transaction(
            transaction_list, match_status)
        records = convert_to_geneva_records(matched_transaction_list)
        fix_duplicate_key_value(records)
        try:
            verify_records(match_status, records, bad_isin_list)
        except:
            self.fail('verify records function failed')

        # from a CSA transaction
        self.verify_record1(
            self.find_record(records, 'USG46715AB73 HTM', 'Buy', 3750000))

        # from a CSW transaction
        self.verify_record2(
            self.find_record(records, 'USG46715AC56 HTM', 'Sell', 4500000))

        # from a CALLED transaction
        self.verify_record3(
            self.find_record(records, 'US06406JET88 HTM', 'Sell', 100000))

        # from a TNDRL transaction
        self.verify_record4(
            self.find_record(records, 'USY97279AB28 HTM', 'Sell', 10900000))

        # from a IATSW transaction
        self.verify_record5(
            self.find_record(records, 'FR0013101599 HTM', 'Sell', 17200000))