def __init__(self, gs_asset: GsAsset = None, **kwargs): self.__error_messages = None if gs_asset: if gs_asset.type.value not in BasketType.to_list(): raise MqValueError( f'Failed to initialize. Asset {gs_asset.id} is not a basket' ) self.__id = gs_asset.id self.__initial_entitlements = gs_asset.entitlements asset_entity: Dict = json.loads( json.dumps(gs_asset.as_dict(), cls=JSONEncoder)) Asset.__init__(self, gs_asset.id, gs_asset.asset_class, gs_asset.name, exchange=gs_asset.exchange, currency=gs_asset.currency, entity=asset_entity) PositionedEntity.__init__(self, gs_asset.id, EntityType.ASSET) self.__populate_current_attributes_for_existing_basket(gs_asset) else: self.__populate_default_attributes_for_new_basket(**kwargs) self.__error_messages = set([]) if get(kwargs, '_finish_init', False): self.__finish_initialization()
def __init__(self, identifier: str = None, gs_asset: GsAsset = None): if identifier: gs_asset = self.__get_gs_asset(identifier) if gs_asset: if gs_asset.type.value not in BasketTypes.to_list(): raise MqValueError( f'Failed to initialize. Asset {gs_asset.id} of type {gs_asset.type.value} \ is not a basket') self.__id = gs_asset.id asset_entity: Dict = json.loads( json.dumps(gs_asset.as_dict(), cls=JSONEncoder)) asset_parameters = get(asset_entity, 'parameters', {}) Asset.__init__(self, gs_asset.id, gs_asset.asset_class, gs_asset.name, exchange=gs_asset.exchange, currency=gs_asset.currency, parameters=AssetParameters(**asset_parameters), entity=asset_entity, entitlements=gs_asset.entitlements) PositionedEntity.__init__(self, gs_asset.id, EntityType.ASSET) self.__populate_current_attributes_for_existing_basket(gs_asset) else: self.__raise_initialization_error( 'use currently implemented class functionality')
def __init__(self, id_: str, asset_class: AssetClass, name: str, exchange: Optional[str] = None, currency: Optional[Currency] = None, entity: Optional[Dict] = None): Asset.__init__(self, id_, asset_class, name, exchange, currency, entity=entity) PositionedEntity.__init__(self, id_, EntityType.ASSET) if entity: self.asset_type = AssetType(entity['type']) else: self.asset_type = AssetType.INDEX if self.__is_sts_index(): self.tree_helper = TreeHelper( id_, tree_underlier_dataset='STS_UNDERLIER_WEIGHTS') self.tree_df = pd.DataFrame()
def __init__(self, identifier: str = None, gs_asset: GsAsset = None, **kwargs): user_tokens = get(GsUsersApi.get_current_user_info(), 'tokens', []) user_is_internal = 'internal' in user_tokens if identifier: gs_asset = self.__get_gs_asset(identifier) if gs_asset: if gs_asset.type.value not in BasketType.to_list(): raise MqValueError(f'Failed to initialize. Asset {gs_asset.id} is not a basket') self.__id = gs_asset.id asset_entity: Dict = json.loads(json.dumps(gs_asset.as_dict(), cls=JSONEncoder)) Asset.__init__(self, gs_asset.id, gs_asset.asset_class, gs_asset.name, exchange=gs_asset.exchange, currency=gs_asset.currency, entity=asset_entity) PositionedEntity.__init__(self, gs_asset.id, EntityType.ASSET) user_is_admin = any(token in user_tokens for token in get(gs_asset.entitlements, 'admin', [])) self.__populate_current_attributes_for_existing_basket(gs_asset) self.__set_error_messages(user_is_admin, user_is_internal, True) self.__populate_api_attrs = True else: self.__set_error_messages(True, user_is_internal, False) self.__populate_default_attributes_for_new_basket(**kwargs) self.__populate_api_attrs = False