示例#1
0
    def update(self) -> Dict:
        """
        Update your custom basket

        :return: dictionary containing asset id and report id

        **Usage**

        Make updates to your basket's metadata, pricing options, publishing options, or composition

        **See also**

        :func:`get_details` :func:`poll_status` :func:`create`

        """
        self.__finish_populating_attributes_for_existing_basket()
        edit_inputs, rebal_inputs = self.__get_updates()
        if edit_inputs is None and rebal_inputs is None:
            raise MqValueError('Update failed: Nothing on the basket was changed')
        elif edit_inputs is not None and rebal_inputs is None:
            response = GsIndexApi.edit(self.id, edit_inputs)
        elif rebal_inputs is not None and edit_inputs is None:
            response = GsIndexApi.rebalance(self.id, rebal_inputs)
        else:
            response = self.__edit_and_rebalance(edit_inputs, rebal_inputs)
        gs_asset = GsAssetApi.get_asset(self.id)
        self.__latest_create_report = GsReportApi.get_report(response.report_id)
        self.__error_messages.remove(ErrorMessage.UNMODIFIABLE)
        self.__init__(gs_asset=gs_asset)
        return response.as_dict()
示例#2
0
def test_basket_edit(mocker):
    # construct inputs and mock response
    inputs = CustomBasketsEditInputs(name=name, flagship=True)
    mock_response = CustomBasketsResponse(report_id, basket_id, 'done')

    # setup mock session and api response
    mock_session()
    mocker.return_value = mock_response

    # run test
    response = GsIndexApi.edit(basket_id, inputs)
    assert response == mock_response
示例#3
0
 def __edit_and_rebalance(self, edit_inputs: CustomBasketsEditInputs,
                          rebal_inputs: CustomBasketsRebalanceInputs) -> CustomBasketsResponse:
     """ If updates require edit and rebalance, rebal will not be scheduled until/if edit report succeeds """
     _logger.info('Current update request requires multiple reports. Your rebalance request will be submitted \
                   once the edit report has completed. Submitting basket edits now...')
     response = GsIndexApi.edit(self.id, edit_inputs)
     report_id = response.report_id
     self.__latest_create_report = GsReportApi.get_report(response.report_id)
     report_status = self.poll_report(report_id, timeout=600, step=15)
     if report_status != ReportStatus.done:
         raise MqError(f'The basket edit report\'s status is {status}. The current rebalance request will \
                         not be submitted in the meantime.')
     _logger.info('Your basket edits have completed successfuly. Submitting rebalance request now...')
     response = GsIndexApi.rebalance(self.id, rebal_inputs)
     return response
示例#4
0
    def update(self) -> Dict:
        """
        Update your custom basket

        :return: dictionary containing asset id and report id

        **Usage**

        Make updates to your basket's metadata, pricing options, publishing options, or composition

        **See also**

        :func:`get_details` :func:`poll_status` :func:`create`

        """
        edit_inputs, rebal_inputs = self.__get_updates()
        entitlements = self.__entitlements.to_target()
        response = None
        if not entitlements == self.__initial_entitlements:
            response = GsAssetApi.update_asset_entitlements(
                self.id, entitlements)
        if edit_inputs is None and rebal_inputs is None:
            if response:
                return response.as_dict()
            raise MqValueError(
                'Update failed: Nothing on the basket was changed')
        elif edit_inputs is not None and rebal_inputs is None:
            response = GsIndexApi.edit(self.id, edit_inputs)
        elif rebal_inputs is not None and edit_inputs is None:
            response = GsIndexApi.rebalance(self.id, rebal_inputs)
        else:
            response = self.__edit_and_rebalance(edit_inputs, rebal_inputs)
        gs_asset = GsAssetApi.get_asset(self.id)
        self.__latest_create_report = GsReportApi.get_report(
            response.report_id)
        self.__init__(gs_asset=gs_asset, _finish_init=True)
        return response.as_dict()