Skip to content

Commit 0d93ab0

Browse files
martinrobersonTan, Rachel Wei Swin [GBM Public]
authored andcommitted
Chore: Make release 1.4.66
1 parent 7672ecc commit 0d93ab0

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

gs_quant/api/gs/assets.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,16 @@ def get_many_assets_data(
297297
fields: IdList = None,
298298
as_of: dt.datetime = None,
299299
limit: int = None,
300+
source: Optional[str] = None,
300301
**kwargs
301302
) -> dict:
302303
span = Tracer.active_span()
303304
tracer = Tracer('GsAsset.get_many_assets_data') if span and span.is_recording() else nullcontext()
304305
with tracer as scope:
305306
cls._set_tags(scope, kwargs)
306307
query = cls.__create_query(fields, as_of, limit, **kwargs)
307-
response = GsSession.current._post('/assets/data/query', payload=query)
308+
request_headers = {'X-Application': 'Studio'} if source == "Basket" else None
309+
response = GsSession.current._post('/assets/data/query', payload=query, request_headers=request_headers)
308310
return response['results']
309311

310312
@classmethod
@@ -332,18 +334,20 @@ def get_many_assets_data_scroll(
332334
fields: IdList = None,
333335
as_of: dt.datetime = None,
334336
limit: int = None,
337+
source: Optional[str] = None,
335338
**kwargs
336339
) -> dict:
337340
span = Tracer.active_span()
338341
tracer = Tracer('GsAsset.get_many_assets_data_scroll') if span and span.is_recording() else nullcontext()
339342
with tracer as scope:
340343
cls._set_tags(scope, kwargs)
341344
query = cls.__create_query(fields, as_of, limit, scroll, **kwargs)
342-
response = GsSession.current._post('/assets/data/query', payload=query)
345+
request_headers = {'X-Application': 'Studio'} if source == "Basket" else None
346+
response = GsSession.current._post('/assets/data/query', payload=query, request_headers=request_headers)
343347
results = get(response, 'results')
344348
while (has(response, 'scrollId') and len(get(response, 'results'))):
345349
query = cls.__create_query(fields, as_of, limit, scroll, get(response, 'scrollId'), **kwargs)
346-
response = GsSession.current._post('/assets/data/query', payload=query)
350+
response = GsSession.current._post('/assets/data/query', payload=query, request_headers=request_headers)
347351
results += get(response, 'results')
348352
return results
349353

gs_quant/markets/baskets.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,43 @@ def get_type(self) -> Optional[SecAssetType]:
531531
if self.__gs_asset_type:
532532
return SecAssetType[self.__gs_asset_type.name.upper()]
533533

534+
@_validate(ErrorMessage.UNINITIALIZED)
535+
def get_latest_position_set(self,
536+
position_type: PositionType = PositionType.CLOSE,
537+
source: str = "Basket") -> PositionSet:
538+
if self.positioned_entity_type == EntityType.ASSET:
539+
response = GsAssetApi.get_latest_positions(self.id, position_type)
540+
return PositionSet.from_target(response, source=source)
541+
raise NotImplementedError
542+
543+
@_validate(ErrorMessage.UNINITIALIZED)
544+
def get_position_set_for_date(self,
545+
date: dt.date,
546+
position_type: PositionType = PositionType.CLOSE,
547+
source: str = "Basket") -> PositionSet:
548+
if self.positioned_entity_type == EntityType.ASSET:
549+
response = GsAssetApi.get_asset_positions_for_date(self.id, date, position_type)
550+
if len(response) == 0:
551+
_logger.info("No positions available for {}".format(date))
552+
return PositionSet([], date=date)
553+
return PositionSet.from_target(response[0], source=source)
554+
raise NotImplementedError
555+
556+
@_validate(ErrorMessage.UNINITIALIZED)
557+
def get_position_sets(self,
558+
start: dt.date = DateLimit.LOW_LIMIT.value,
559+
end: dt.date = dt.date.today(),
560+
position_type: PositionType = PositionType.CLOSE,
561+
source: str = "Basket") -> List[PositionSet]:
562+
if self.positioned_entity_type == EntityType.ASSET:
563+
response = GsAssetApi.get_asset_positions_for_dates(self.id, start, end, position_type)
564+
if len(response) == 0:
565+
_logger.info("No positions available in the date range {} - {}".format(start, end))
566+
return []
567+
return [PositionSet.from_target(position_set, source=source)
568+
for position_set in response]
569+
raise NotImplementedError
570+
534571
@_validate(ErrorMessage.UNINITIALIZED)
535572
def get_url(self) -> str:
536573
"""

gs_quant/markets/indices_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,8 @@ def get_flagships_constituents(fields: List[str] = [],
499499
batch_size = 100
500500
for i in range(0, len(asset_ids), batch_size):
501501
batch = asset_ids[i:i + batch_size]
502-
asset_data += GsAssetApi.get_many_assets_data_scroll(id=batch, fields=fields, limit=QUERY_LIMIT, scroll='1m')
502+
asset_data += GsAssetApi.get_many_assets_data_scroll(id=batch, fields=fields, limit=QUERY_LIMIT,
503+
scroll='1m', source="Basket")
503504
asset_data_map = {get(asset, 'id'): asset for asset in asset_data}
504505

505506
for row in constituents_data:

gs_quant/markets/position_set.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -871,11 +871,11 @@ def to_target(self, common: bool = True) -> Union[CommonPositionSet, List[Positi
871871
return CommonPositionSet(positions, self.date) if common else list(positions)
872872

873873
@classmethod
874-
def from_target(cls, position_set: CommonPositionSet):
874+
def from_target(cls, position_set: CommonPositionSet, source: Optional[str] = None):
875875
""" Create PostionSet instance from PostionSet type defined in target file """
876876
positions = position_set.positions
877877
mqids = [position.asset_id for position in positions]
878-
position_data = cls.__get_positions_data(mqids)
878+
position_data = cls.__get_positions_data(mqids, source=source)
879879
converted_positions = []
880880
for p in positions:
881881
asset = get(position_data, p.asset_id)
@@ -1040,8 +1040,9 @@ def __resolve_identifiers(identifiers: List[str], date: dt.date, **kwargs) -> Li
10401040
return [id_map, unmapped_assets]
10411041

10421042
@staticmethod
1043-
def __get_positions_data(mqids: List[str]) -> Dict:
1044-
response = GsAssetApi.get_many_assets_data(id=mqids, fields=['id', 'name', 'bbid'])
1043+
def __get_positions_data(mqids: List[str], source: Optional[str] = None) -> Dict:
1044+
response = GsAssetApi.get_many_assets_data(id=mqids, fields=['id', 'name', 'bbid'],
1045+
source=source)
10451046
data = {}
10461047
for asset in response:
10471048
data[get(asset, 'id')] = dict(name=get(asset, 'name'), bbid=get(asset, 'bbid'))

0 commit comments

Comments
 (0)