def test_rdate_datagrid(mocker): mocker.patch.object(GsSession.__class__, 'default_value', return_value=GsSession.get(Environment.QA, 'client_id', 'secret')) name = 'Testing' SPX = get_test_entity('MA4B66MW5E27U8P32SB') close = DataCoordinate( measure=DataMeasure.CLOSE_PRICE, frequency=DataFrequency.DAILY, ) last_trade_price = DataCoordinate( measure=DataMeasure.TRADE_PRICE, frequency=DataFrequency.REAL_TIME, ) rows = [ DataRow(SPX), ] columns = [ DataColumn(name="1d Chg (RT)", processor=ChangeProcessor(AppendProcessor(close, last_trade_price, start=RelativeDate("-1d", base_date=date(2021, 1, 22))))) ] datagrid = DataGrid(name=name, rows=rows, columns=columns) start_date = datagrid.columns[0].processor.children['a'].start assert start_date.base_date == RelativeDate('-1d', base_date=date(2021, 1, 22)).base_date assert start_date.rule == RelativeDate('-1d').rule datagrid.initialize() datagrid.poll() assert str(datagrid._data_queries[0].query.start) == '2021-01-21' as_dict = datagrid.as_dict() start = as_dict['parameters']['columns'][0]['parameters']['a']['parameters']['start'] assert start['type'] == 'relativeDate' assert start['value'] == {'rule': '-1d', 'baseDate': '2021-01-22'} # Check that base_date is not persisted when not passed in. columns = [ DataColumn(name="1d Chg (RT)", processor=ChangeProcessor(AppendProcessor(close, last_trade_price, start=RelativeDate("-1d")))) ] datagrid = DataGrid(name=name, rows=rows, columns=columns) as_dict = datagrid.as_dict() start = as_dict['parameters']['columns'][0]['parameters']['a']['parameters']['start'] assert start['type'] == 'relativeDate' assert start['type'] == 'relativeDate' assert start['value'] == {'rule': '-1d'}
def update_datagrid(cls, datagrid: DataGrid): datagrid_json = json.dumps(datagrid.as_dict()) datagrid = GsSession.current._put(f'{API}/{datagrid.id_}', datagrid_json, request_headers=DATAGRID_HEADERS) return DataGrid.from_dict(datagrid)
def create_datagrid(cls, datagrid: DataGrid) -> DataGrid: datagrid_json = json.dumps(datagrid.as_dict()) response = GsSession.current._post(f'{API}', datagrid_json, request_headers=DATAGRID_HEADERS) return DataGrid.from_dict(response)