def __populate_current_attributes_for_existing_basket( self, gs_asset: GsAsset): self.__description = get(gs_asset, 'description', None) self.__gs_asset_type = get(gs_asset, 'type', None) self.__live_date = get(gs_asset, 'live_date', None) self.__ticker = get(gs_asset, 'xref.ticker', None) self.__clone_parent_id = get(gs_asset, 'parameters.clone_parent_id', None) self.__default_backcast = get(gs_asset, 'parameters.default_backcast', None) self.__flagship = get(gs_asset, 'parameters.flagship', None) self.__hedge_id = get(gs_asset, 'parameters.hedge_id', None) self.__return_type = get(gs_asset, 'parameters.index_calculation_type', None) last_positions = GsAssetApi.get_latest_positions(self.__id) self.__divisor = get(last_positions, 'divisor', None) last_initial_price = GsIndexApi.initial_price(gs_asset.id, DateLimit.TODAY.value) self.__initial_price = get(last_initial_price, 'price', None) report = self.__get_last_create_report() self.__include_price_history = get(report, 'parameters.include_price_history', None) self.__publish_to_bloomberg = get(report, 'parameters.publish_to_bloomberg', None) self.__publish_to_factset = get(report, 'parameters.publish_to_factset', None) self.__publish_to_reuters = get(report, 'parameters.publish_to_reuters', None)
def test_basket_initial_price(mocker): # construct mock response mock_response = {'price': 100} # setup mock session and api response mock_session() mocker.return_value = mock_response # run test response = GsIndexApi.initial_price(basket_id, date) assert response == mock_response
def __finish_populating_attributes_for_existing_basket(self): """ Populates all values not originally fetched during initialization due to required API calls """ if self.__populate_api_attrs: position_set = GsAssetApi.get_latest_positions(self.id, PositionType.ANY) report = get(self, '__latest_create_report', self.__get_latest_create_report()) self.__divisor = get(position_set, 'divisor') self.__initial_price = get(GsIndexApi.initial_price(self.id, dt.date.today()), 'price') self.__parent_basket = None if self.__clone_parent_id is None else \ get(GsAssetApi.get_asset(self.__clone_parent_id), 'id') self.__position_set = PositionSet.from_target(position_set) self.__publish_to_bloomberg = get(report, 'parameters.publish_to_bloomberg') self.__publish_to_factset = get(report, 'parameters.publish_to_factset') self.__publish_to_reuters = get(report, 'parameters.publish_to_reuters') set_(self.__initial_state, 'divisor', self.__divisor) set_(self.__initial_state, 'initial_price', self.__initial_price) set_(self.__initial_state, 'position_set', self.__position_set) set_(self.__initial_state, 'publish_to_bloomberg', self.__publish_to_bloomberg) set_(self.__initial_state, 'publish_to_factset', self.__publish_to_factset) set_(self.__initial_state, 'publish_to_reuters', self.__publish_to_reuters) self.__initial_positions = set(deepcopy(self.__position_set.positions)) self.__populate_api_attrs = False
def __finish_initialization(self): """ Fetches remaining data not retrieved during basket initialization """ if has(self, 'id'): if not has(self, '__initial_positions'): position_set = GsAssetApi.get_latest_positions( self.id, PositionType.ANY) position_set = PositionSet.from_target(position_set) self.__position_set = position_set self.__divisor = get(position_set, 'divisor') self.__initial_positions = set( deepcopy(self.__position_set.positions)) set_(self.__initial_state, 'divisor', self.__divisor) set_(self.__initial_state, 'position_set', self.__position_set) if not has(self.__initial_state, 'initial_price'): initial_price = GsIndexApi.initial_price( self.id, dt.date.today()) self.__initial_price = get(initial_price, 'price') set_(self.__initial_state, 'initial_price', self.__initial_price) if not has(self.__initial_state, 'publish_to_bloomberg'): report = get(self, '__latest_create_report', self.__get_latest_create_report()) self.__publish_to_bloomberg = get( report, 'parameters.publish_to_bloomberg') self.__publish_to_factset = get( report, 'parameters.publish_to_factset') self.__publish_to_reuters = get( report, 'parameters.publish_to_reuters') set_(self.__initial_state, 'publish_to_bloomberg', self.__publish_to_bloomberg) set_(self.__initial_state, 'publish_to_factset', self.__publish_to_factset) set_(self.__initial_state, 'publish_to_reuters', self.__publish_to_reuters) if not has(self, '__entitlements'): self.__entitlements = BasketEntitlements.from_target( self.__initial_entitlements) self.__set_error_messages()