示例#1
0
def test_coordinate_last(mocker):
    as_of = dt.datetime(2019, 1, 2, 1, 10)
    data = {
        'responses': [{
            'data': [{
                'mktType': 'Prime',
                'mktAsset': '335320934',
                'mktQuotingStyle': 'price',
                'price': 1.0141,
                'time': '2019-01-20T01:08:00Z'
            }]
        }, {
            'data': [{
                'mktType': 'IR',
                'mktAsset': 'USD',
                'mktClass': 'Swap',
                'mktPoint': ('2Y', ),
                'mktQuotingStyle': 'ATMRate',
                'ATMRate': 0.02592,
                'time': '2019-01-20T01:09:45Z'
            }]
        }]
    }

    expected_result = pd.DataFrame(
        data={
            'time': ['2019-01-20T01:08:00Z', '2019-01-20T01:09:45Z'],
            'mktType': ['Prime', 'IR'],
            'mktAsset': ['335320934', 'USD'],
            'mktClass': [None, 'Swap'],
            'mktPoint': [None, ('2Y', )],
            'mktQuotingStyle': ['price', None],
            'value': [1.0141, 0.02592]
        })

    # mock GsSession and data response
    mocker.patch.object(GsSession.__class__,
                        'default_value',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    GsSession.current._post = mocker.Mock(return_value=data)

    result = GsDataApi.coordinates_last(coordinates=test_coordinates,
                                        as_of=as_of,
                                        as_dataframe=True)
    assert result.equals(expected_result)

    GsSession.current._post.reset_mock()
    result_from_str = GsDataApi.coordinates_last(
        coordinates=test_str_coordinates, as_of=as_of, as_dataframe=True)
    assert result_from_str.equals(expected_result)
    GsSession.current._post.assert_called_once_with(
        '/data/coordinates/query/last',
        payload=MDAPIDataQuery(market_data_coordinates=test_coordinates,
                               end_time=as_of,
                               vendor=MarketDataVendor.Goldman_Sachs,
                               format="MessagePack"))
示例#2
0
def test_coordinate_last(mocker):
    data = {
        'responses': [{
            'data': [{
                'mktType': 'Prime',
                'mktAsset': '335320934',
                'mktQuotingStyle': 'price',
                'price': 1.0141,
                'time': '2019-01-20T01:08:00Z'
            }]
        }, {
            'data': [{
                'mktType': 'IR',
                'mktAsset': 'USD',
                'mktClass': 'Swap',
                'mktPoint': ('2Y', ),
                'mktQuotingStyle': 'ATMRate',
                'ATMRate': 0.02592,
                'time': '2019-01-20T01:09:45Z'
            }]
        }]
    }

    expected_result = pd.DataFrame(
        data={
            'mktType': ['Prime', 'IR'],
            'mktAsset': ['335320934', 'USD'],
            'mktClass': [None, 'Swap'],
            'mktPoint': [None, ('2Y', )],
            'mktQuotingStyle': ['price', None],
            'value': [1.0141, 0.02592]
        })

    # mock GsSession and data response
    mocker.patch.object(GsSession.__class__,
                        'current',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    GsSession.current._post = mocker.Mock(return_value=data)

    result = GsDataApi.coordinates_last(coordinates=test_coordinates,
                                        as_of=dt.datetime(2019, 1, 2, 1, 10),
                                        as_dataframe=True)
    assert result.equals(expected_result)

    result_from_str = GsDataApi.coordinates_last(
        coordinates=test_str_coordinates,
        as_of=dt.datetime(2019, 1, 2, 1, 10),
        as_dataframe=True)
    assert result_from_str.equals(expected_result)

    GsSession.current._post.assert_called_with('/data/coordinates/query/last',
                                               payload=mocker.ANY)
    assert GsSession.current._post.call_count == 2
示例#3
0
def test_coordinate_last(mocker):
    data = {
        'responses': [{
            'data': [{
                'marketDataType': 'Prime',
                'marketDataAsset': '335320934',
                'field': 'price',
                'price': 1.0141,
                'time': '2019-01-20T01:08:00Z'
            }]
        }, {
            'data': [{
                'marketDataType': 'IR',
                'marketDataAsset': 'USD',
                'pointClass': 'Swap',
                'marketDataPoint': ('2Y', ),
                'quotingStyle': 'ATMRate',
                'ATMRate': 0.02592,
                'time': '2019-01-20T01:09:45Z'
            }]
        }]
    }

    expected_result = sort_risk(
        pd.DataFrame([{
            'field': 'price',
            'marketDataAsset': '335320934',
            'marketDataType': 'Prime',
            'value': 1.0141
        }, {
            'quotingStyle': 'ATMRate',
            'marketDataAsset': 'USD',
            'marketDataType': 'IR',
            'marketDataPoint': ('2Y', ),
            'pointClass': 'Swap',
            'value': 0.02592
        }]))

    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'current',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    mocker.patch.object(GsSession.current, '_post', return_value=data)

    result = GsDataApi.coordinates_last(coordinates=test_coordinates,
                                        as_of=dt.datetime(2019, 1, 2, 1, 10),
                                        as_dataframe=True)

    result.sort_index(axis=1, inplace=True)
    expected_result.sort_index(axis=1, inplace=True)
    assert result.equals(expected_result)