Ejemplo n.º 1
0
    def book_transfer(self, asset_manager_id, asset_id, source_book_id, target_book_id, wash_book_id, quantity, price,
                      currency):
        """
        A method for moving between books.  The convention is always *from* the source, *to* the target.

        Two transactions are booked -  one against each

        :param asset_manager_id: The owning asset manager id.
        :param asset_id: The asset being transferred.
        :param source_book_id: The book id of the source.
        :param target_book_id:  The book id of the target.
        :param wash_book_id:  The book id of the wash book which will be the counterparty for the two sides.
        :param quantity: The quantity to transfer.
        :param price:  The price at which to make the transfer.  Typically T-1 EOD price or current market price.
        :param currency: The currency for the transfer price.
        :return:
        """
        url = '%s/book_transfer/%s' % (self.endpoint, asset_manager_id)
        body = {'asset_id': asset_id, 'source_book_id': source_book_id, 'target_book_id': target_book_id,
                'wash_book_id': wash_book_id, 'quantity': quantity, 'price': price, 'currency': currency}
        response = self.session.post(url, data=json.dumps(body, default=json_handler), headers=self.json_header)
        if response.ok:
            deliver_json, receive_json = response.json()
            return json_to_transaction(deliver_json), json_to_transaction(receive_json),
        else:
            self.logger.error(response.text)
            response.raise_for_status()
Ejemplo n.º 2
0
 def retrieve_netting_set(self, asset_manager_id, transaction_id):
     """
     Returns all the transaction_ids associated with a single netting set.  Pass in the ID for any transaction in
     the set.
     :param asset_manager_id:  The asset_manager_id for the netting set owner.
     :param transaction_id: A transaction_id of an entry within the netting set.
     :return:
     """
     self.logger.info(
         'Retrieve Netting Set - Asset Manager: %s - Transaction ID: %s',
         asset_manager_id, transaction_id)
     url = '%s/netting/%s/%s' % (self.endpoint, asset_manager_id,
                                 transaction_id)
     response = self.session.get(url)
     if response.ok:
         net_transaction_id, netting_set_json = next(
             iter(response.json().items()))
         netting_set = [
             json_to_transaction(net_transaction)
             for net_transaction in netting_set_json
         ]
         self.logger.info('Returned %s Transactions in Netting Set.',
                          len(netting_set))
         return net_transaction_id, netting_set
     else:
         self.logger.error(response.text)
         response.raise_for_status()
Ejemplo n.º 3
0
    def net_transactions(self,
                         asset_manager_id,
                         transaction_ids,
                         netting_type='Net'):
        """

        :param asset_manager_id: The asset_manager_id of the netting set owner
        :param transaction_ids:  A list of transaction_ids to net
        :param netting_type:
        :return:
        """
        self.logger.info(
            'Net Transactions - Asset Manager: %s - Transaction IDs: %s',
            asset_manager_id, transaction_ids)
        url = '%s/netting/%s' % (self.endpoint, asset_manager_id)
        params = {'netting_type': netting_type}
        response = self.session.post(url, params=params, json=transaction_ids)
        if response.ok:
            net_transaction = json_to_transaction(response.json())
            self.logger.info('Net Created - Transaction: %s',
                             net_transaction.transaction_id)
            return net_transaction
        else:
            self.logger.error(response.text)
            response.raise_for_status()
Ejemplo n.º 4
0
    def allocate_transaction(self, asset_manager_id, transaction_id,
                             allocation_type, allocation_dicts):
        """

        :param asset_manager_id:
        :param transaction_id:
        :param allocation_type:
        :param allocation_dicts:
        :return:
        """
        self.logger.info(
            'Allocate Transaction - Asset Manager: %s - Transaction ID: %s',
            asset_manager_id, transaction_id)
        url = '%s/allocations/%s/%s' % (self.endpoint, asset_manager_id,
                                        transaction_id)
        params = {'allocation_type': allocation_type}
        response = self.session.post(url,
                                     params=params,
                                     data=json.dumps(allocation_dicts,
                                                     default=json_handler),
                                     headers=self.json_header)
        if response.ok:
            allocations = [
                json_to_transaction(json_allocation)
                for json_allocation in response.json()
            ]
            allocation_ids = [
                allocation.transaction_id for allocation in allocations
            ]
            self.logger.info('%s Allocations Created - Transactions: %s',
                             len(allocations), allocation_ids)
            return allocations
        else:
            self.logger.error(response.text)
            response.raise_for_status()
Ejemplo n.º 5
0
 def create_many(self, transactions):
     if type(transactions) is not list:
         raise ValueError(
             'Error - create_many takes in a list of transactions instead of single transaction'
         )
     transactions_json = []
     # check to ensure all transactions have the same asset_manager_id
     asset_manager_id = transactions[0].asset_manager_id
     for transaction in transactions:
         transactions_json.append(transaction.to_interface())
         if transaction.asset_manager_id != asset_manager_id:
             raise AttributeError(
                 'Check failed - Not all transactions have the same asset manager ID.'
             )
     self.logger.info('Multple new Transactions - Asset Manager: %s',
                      asset_manager_id)
     url = '%s/transactions/%s' % (self.endpoint, asset_manager_id)
     response = self.session.post(url, json=transactions_json)
     if response.ok:
         transactions = []
         for transaction_json in response.json():
             transactions.append(json_to_transaction(transaction_json))
         return transactions
     else:
         self.logger.error(response.text)
         response.raise_for_status()
Ejemplo n.º 6
0
 def transactions_by_asset_manager(self, asset_manager_id):
     self.logger.info('Retrieve Transactions by Asset Manager: %s', asset_manager_id)
     url = '%s/transactions/%s' % (self.endpoint, asset_manager_id)
     response = self.session.get(url)
     if response.ok:
         transactions = [json_to_transaction(json_transaction) for json_transaction in response.json()]
         self.logger.info('Returned %s Transactions.', len(transactions))
         return transactions
     else:
         self.logger.error(response.text)
         response.raise_for_status()
Ejemplo n.º 7
0
 def partial(self, asset_manager_id, transaction_id, updates):
     self.logger.info('Partial Amend Transaction - Asset Manager: %s - Transaction ID: %s', asset_manager_id,
                      transaction_id)
     url = '%s/transactions/%s/%s' % (self.endpoint, asset_manager_id, transaction_id)
     response = self.session.patch(url, data=json.dumps(updates, default=json_handler), headers=self.json_header)
     if response.ok:
         transaction = json_to_transaction(response.json())
         return transaction
     else:
         self.logger.error(response.text)
         response.raise_for_status()
Ejemplo n.º 8
0
 def amend(self, transaction):
     self.logger.info('Amend Transaction - Asset Manager: %s - Transaction ID: %s', transaction.asset_manager_id,
                      transaction.transaction_id)
     url = '%s/transactions/%s/%s' % (self.endpoint, transaction.asset_manager_id, transaction.transaction_id)
     response = self.session.put(url, json=transaction.to_interface())
     if response.ok:
         transaction = json_to_transaction(response.json())
         return transaction
     else:
         self.logger.error(response.text)
         response.raise_for_status()
Ejemplo n.º 9
0
 def retrieve(self, asset_manager_id, transaction_id, version=None):
     self.logger.info('Retrieve Transaction - Asset Manager: %s - Transaction ID: %s', asset_manager_id,
                      transaction_id)
     url = '%s/transactions/%s/%s' % (self.endpoint, asset_manager_id, transaction_id)
     if version:
         url += '?version=%d' % int(version)
     response = self.session.get(url)
     if response.ok:
         return json_to_transaction(response.json())
     else:
         self.logger.error(response.text)
         response.raise_for_status()
Ejemplo n.º 10
0
 def search(self, asset_manager_id, transaction_ids=[], transaction_statuses=[],
            asset_book_ids=[], counterparty_book_ids=[], asset_ids=[], transaction_date_start=None,
            transaction_date_end=None, code_types=[], code_values=[], link_types=[], linked_transaction_ids=[],
            party_types=[], party_ids=[], reference_types=[], reference_values=[], client_ids=[],
            page_no=None, page_size=None):
     self.logger.info('Search Transactions - Asset Manager: %s', asset_manager_id)
     search_params = {}
     # Potentially roll this into a loop through args rather than explicitly named - depends on additional validation
     if transaction_ids:
         search_params['transaction_ids'] = ','.join(transaction_ids)
     if transaction_statuses:
         search_params['transaction_statuses'] = ','.join(transaction_statuses)
     if asset_book_ids:
         search_params['asset_book_ids'] = ','.join(asset_book_ids)
     if counterparty_book_ids:
         search_params['counterparty_book_ids'] = ','.join(counterparty_book_ids)
     if asset_ids:
         search_params['asset_ids'] = ','.join(asset_ids)
     if transaction_date_start:
         search_params['transaction_date_start'] = transaction_date_start
     if transaction_date_end:
         search_params['transaction_date_end'] = transaction_date_end
     if code_types:
         search_params['code_types'] = ','.join(code_types)
     if code_values:
         search_params['code_values'] = ','.join(code_values)
     if link_types:
         search_params['link_types'] = ','.join(link_types)
     if linked_transaction_ids:
         search_params['linked_transaction_ids'] = ','.join(linked_transaction_ids)
     if party_types:
         search_params['party_types'] = ','.join(party_types)
     if party_ids:
         search_params['party_ids'] = ','.join(party_ids)
     if reference_types:
         search_params['reference_types'] = ','.join(reference_types)
     if reference_values:
         search_params['reference_values'] = ','.join(reference_values)
     if client_ids:
         search_params['client_ids'] = ','.join(client_ids)
     if page_no is not None:
         search_params['page_no'] = page_no
     if page_size:
         search_params['page_size'] = page_size
     url = '%s/transactions/%s' % (self.endpoint, asset_manager_id)
     response = self.session.get(url, params=search_params)
     if response.ok:
         transactions = [json_to_transaction(json_transaction) for json_transaction in response.json()]
         self.logger.info('Returned %s Transactions.', len(transactions))
         return transactions
     else:
         self.logger.error(response.text)
         response.raise_for_status()
Ejemplo n.º 11
0
 def get_pnl_transactions(self, book_id, asset_manager_id, start_date, end_date):
     self.logger.info('Retrieving transactions for PnL - Asset Manager: %s - Book ID: %s'%(asset_manager_id, book_id))
     url = '%s/pnl_transactions/%s' % (self.endpoint, asset_manager_id)
     search_params = {'asset_manager_id': asset_manager_id,
                      'start_date': start_date,
                      'book_id': book_id,
                      'end_date': end_date}
     response = self.session.get(url, params=search_params)
     if response.ok:
         transactions = [json_to_transaction(json_transaction) for json_transaction in response.json()]
         self.logger.info('Returned %s Transactions.', len(transactions))
         return transactions
     else:
         self.logger.error(response.text)
         response.raise_for_status()        
Ejemplo n.º 12
0
    def retrieve_transaction_allocations(self, asset_manager_id, transaction_id):
        """

        :param asset_manager_id:
        :param transaction_id:
        :return:
        """
        self.logger.info('Retrieve Allocations - Asset Manager: %s - Transaction ID: %s', asset_manager_id,
                         transaction_id)
        url = '%s/allocations/%s/%s' % (self.endpoint, asset_manager_id, transaction_id)
        response = self.session.get(url)
        if response.ok:
            allocations = [json_to_transaction(json_allocation) for json_allocation in response.json()]
            self.logger.info('Returned %s Allocations.', len(allocations))
            return allocations
        else:
            self.logger.error(response.text)
            response.raise_for_status()
Ejemplo n.º 13
0
 def test_JsonToTransaction(self):
     transaction = generate_transaction()
     json_transaction = transaction.to_json()
     gen_transaction = json_to_transaction(json_transaction)
     self.assertEqual(gen_transaction, transaction)