Exemple #1
0
 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()
Exemple #2
0
    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')
Exemple #3
0
 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
Exemple #4
0
    def __gs_asset_to_asset(cls, gs_asset: GsAsset) -> Asset:
        asset_type = gs_asset.type.value
        asset_entity: Dict = json.loads(
            json.dumps(gs_asset.as_dict(), cls=JSONEncoder))

        if asset_type in (GsAssetType.Single_Stock.value, ):
            return Stock(gs_asset.id,
                         gs_asset.name,
                         gs_asset.exchange,
                         gs_asset.currency,
                         entity=asset_entity)

        if asset_type in (GsAssetType.ETF.value, ):
            return ETF(gs_asset.id,
                       gs_asset.assetClass,
                       gs_asset.name,
                       gs_asset.exchange,
                       gs_asset.currency,
                       entity=asset_entity)

        if asset_type in (GsAssetType.Index.value,
                          GsAssetType.Risk_Premia.value,
                          GsAssetType.Access.value,
                          GsAssetType.Multi_Asset_Allocation.value):
            return Index(gs_asset.id,
                         gs_asset.assetClass,
                         gs_asset.name,
                         gs_asset.exchange,
                         gs_asset.currency,
                         entity=asset_entity)

        if asset_type in (GsAssetType.Custom_Basket.value,
                          GsAssetType.Research_Basket.value):
            return Basket(gs_asset.id,
                          gs_asset.assetClass,
                          gs_asset.name,
                          gs_asset.currency,
                          entity=asset_entity)

        if asset_type in (GsAssetType.Future.value, ):
            return Future(gs_asset.id,
                          gs_asset.assetClass,
                          gs_asset.name,
                          gs_asset.currency,
                          entity=asset_entity)

        if asset_type in (GsAssetType.Cross.value, ):
            return Cross(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.Currency.value, ):
            return Currency(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.Rate.value, ):
            return Rate(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.Cash.value, ):
            return Cash(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.WeatherIndex.value, ):
            return WeatherIndex(gs_asset.id,
                                gs_asset.name,
                                entity=asset_entity)

        if asset_type in (GsAssetType.Swap.value, ):
            return Swap(gs_asset.id,
                        gs_asset.assetClass,
                        gs_asset.name,
                        entity=asset_entity)

        if asset_type in (GsAssetType.Option.value, ):
            return Option(gs_asset.id,
                          gs_asset.assetClass,
                          gs_asset.name,
                          entity=asset_entity)

        if asset_type in (GsAssetType.CommodityReferencePrice.value, ):
            return CommodityReferencePrice(gs_asset.id,
                                           gs_asset.name,
                                           entity=asset_entity)

        if asset_type in (GsAssetType.CommodityNaturalGasHub.value, ):
            return CommodityNaturalGasHub(gs_asset.id,
                                          gs_asset.name,
                                          entity=asset_entity)

        if asset_type in (GsAssetType.CommodityEUNaturalGasHub.value, ):
            return CommodityEUNaturalGasHub(gs_asset.id,
                                            gs_asset.name,
                                            entity=asset_entity)

        if asset_type in (GsAssetType.CommodityPowerNode.value, ):
            return CommodityPowerNode(gs_asset.id,
                                      gs_asset.name,
                                      entity=asset_entity)

        if asset_type in (GsAssetType.CommodityPowerAggregatedNodes.value, ):
            return CommodityPowerAggregatedNodes(gs_asset.id,
                                                 gs_asset.name,
                                                 entity=asset_entity)

        if asset_type in (GsAssetType.Bond.value, ):
            return Bond(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.Commodity.value, ):
            return Commodity(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.FutureMarket.value, ):
            return FutureMarket(gs_asset.id,
                                gs_asset.assetClass,
                                gs_asset.name,
                                entity=asset_entity)

        if asset_type in (GsAssetType.FutureContract.value, ):
            return FutureContract(gs_asset.id,
                                  gs_asset.assetClass,
                                  gs_asset.name,
                                  entity=asset_entity)

        # workaround as casing is being migrated
        if asset_type == GsAssetType.Cryptocurrency.value:
            return Cryptocurrency(gs_asset.id,
                                  gs_asset.assetClass,
                                  gs_asset.name,
                                  entity=asset_entity)

        raise TypeError(f'unsupported asset type {asset_type}')
Exemple #5
0
    def __gs_asset_to_asset(cls, gs_asset: GsAsset) -> Asset:
        asset_type = gs_asset.type.value
        asset_entity: Dict = json.loads(
            json.dumps(gs_asset.as_dict(), cls=JSONEncoder))

        if asset_type in (GsAssetType.Single_Stock.value, ):
            return Stock(gs_asset.id,
                         gs_asset.name,
                         gs_asset.exchange,
                         gs_asset.currency,
                         entity=asset_entity)

        if asset_type in (GsAssetType.ETF.value, ):
            return ETF(gs_asset.id,
                       gs_asset.assetClass,
                       gs_asset.name,
                       gs_asset.exchange,
                       gs_asset.currency,
                       entity=asset_entity)

        if asset_type in (GsAssetType.Index.value,
                          GsAssetType.Risk_Premia.value,
                          GsAssetType.Access.value,
                          GsAssetType.Multi_Asset_Allocation.value):
            return Index(gs_asset.id,
                         gs_asset.assetClass,
                         gs_asset.name,
                         gs_asset.exchange,
                         gs_asset.currency,
                         entity=asset_entity)

        if asset_type in (GsAssetType.Custom_Basket.value,
                          GsAssetType.Research_Basket.value):
            return Basket(gs_asset.id,
                          gs_asset.assetClass,
                          gs_asset.name,
                          gs_asset.currency,
                          entity=asset_entity)

        if asset_type in (GsAssetType.Future.value, ):
            return Future(gs_asset.id,
                          gs_asset.assetClass,
                          gs_asset.name,
                          gs_asset.currency,
                          entity=asset_entity)

        if asset_type in (GsAssetType.Cross.value, ):
            return Cross(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.Currency.value, ):
            return Currency(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.Rate.value, ):
            return Rate(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.Cash.value, ):
            return Cash(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.WeatherIndex.value, ):
            return WeatherIndex(gs_asset.id,
                                gs_asset.name,
                                entity=asset_entity)

        if asset_type in (GsAssetType.Swap.value, ):
            return Swap(gs_asset.id,
                        gs_asset.assetClass,
                        gs_asset.name,
                        entity=asset_entity)

        if asset_type in (GsAssetType.Option.value, ):
            return Option(gs_asset.id,
                          gs_asset.assetClass,
                          gs_asset.name,
                          entity=asset_entity)

        if asset_type in (GsAssetType.CommodityReferencePrice.value, ):
            return CommodityReferencePrice(gs_asset.id,
                                           gs_asset.name,
                                           entity=asset_entity)

        # disabled: this asset type would have to be added to target\common.py and the (Prod) Asset Service first!
        # if asset_type in (GsAssetType.CommodityNaturalGasHub.value,):
        #     return CommodityNaturalGasHub(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.CommodityPowerNode.value, ):
            return CommodityPowerNode(gs_asset.id,
                                      gs_asset.name,
                                      entity=asset_entity)

        if asset_type in (GsAssetType.CommodityPowerAggregatedNodes.value, ):
            return CommodityPowerAggregatedNodes(gs_asset.id,
                                                 gs_asset.name,
                                                 entity=asset_entity)

        if asset_type in (GsAssetType.Bond.value, ):
            return Bond(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.Commodity.value, ):
            return Commodity(gs_asset.id, gs_asset.name, entity=asset_entity)

        if asset_type in (GsAssetType.FutureMarket.value, ):
            return FutureMarket(gs_asset.id,
                                gs_asset.assetClass,
                                gs_asset.name,
                                entity=asset_entity)

        if asset_type in (GsAssetType.FutureContract.value, ):
            return FutureContract(gs_asset.id,
                                  gs_asset.assetClass,
                                  gs_asset.name,
                                  entity=asset_entity)

        raise TypeError(f'unsupported asset type {asset_type}')