Request same field with different parameters in data_grid

If I do a request like the following:

ek.get_data('BHP.AX', ['TR.TradePriceClose', ('TR.TradePriceClose', {'Curn': 'USD'})])

The second TradePriceClose field (in USD) doesn't come through as an additional column as expected whereas this works fine in say excel, or through the COM apis (Dex2).

Instead what appears to be happenning is it is collapsing the data by bare field name (not including parameters) causing it to get folded together with the first field as a single column in the response, leaving only one instance of TradePriceClose in the returned json headers. Using either by itself works fine. Is there some way of modifying the request in data_grid to avoid this (eg passing some different parameters)?

Best Answer

  • I got the same result as yours.

    The following is the Request and Response after using the above code.

    Request

    {
    "Entity": {
    "W": {
    "fields": [
    {
    "name": "TR.TradePriceClose"
    },
    {
    "parameters": {
    "Curn": "USD"
    },
    "name": "TR.TradePriceClose"
    }
    ],
    "instruments": [
    "BHP.AX"
    ]
    },
    "E": "DataGrid"
    }
    }

    Response

    {
    "columnHeadersCount": 1,
    "data": [
    [
    "BHP.AX",
    23.8
    ],
    [
    "BHP.AX",
    23.8
    ]
    ],
    "headerOrientation": "horizontal",
    "headers": [
    [
    {
    "displayName": "Instrument"
    },
    {
    "displayName": "Trade Price Close",
    "field": "TR.TRADEPRICECLOSE"
    }
    ]
    ],
    "rowHeadersCount": 1,
    "totalColumnsCount": 2,
    "totalRowsCount": 3
    }

    However, if I use your workaround, I can get the correct data.

    Request

    {
    "Entity": {
    "W": {
    "fields": [
    {
    "name": "TR.TradePriceClose.value",
    "parameters": {
    "Curn": "USD"
    }
    },
    {
    "name": "TR.TradePriceClose.value"
    }
    ],
    "instruments": [
    "BHP.AX"
    ]
    },
    "E": "DataGrid"
    }
    }

    Response

    {
    "columnHeadersCount": 1,
    "data": [
    [
    "BHP.AX",
    17.933300179333,
    23.8
    ]
    ],
    "headerOrientation": "horizontal",
    "headers": [
    [
    {
    "displayName": "Instrument"
    },
    {
    "displayName": "Trade Price Close",
    "field": "TR.TRADEPRICECLOSE(Curn=USD).value"
    },
    {
    "displayName": "Trade Price Close",
    "field": "TR.TRADEPRICECLOSE.value"
    }
    ]
    ],
    "rowHeadersCount": 1,
    "totalColumnsCount": 3,
    "totalRowsCount": 2
    }

    This could be the problem in Data Grid. I will contact Data Grid team to verify the issue.

Answers

  • It seems to work if I add a .value suffix to both fields, and put the USD one first, otherwise I get two identical columns. Can't quite figure make sense of this one.

  • Thanks for taking a look. Note that it is also reproducible in excel, ie this formula doesn't work correctly unless you flip the order:

    =TR("BHP.AX","TR.TradePriceClose;TR.TradePriceClose(Curn=USD)","CH=Fd",B2)

    So this has the potential to trip up many more people than just those using DataGrid via the scripting API or JET. Another thing to note is that it works fine with TR.PriceClose, so it is something peculiar to these items (which I believe get pulled from a different source than data cloud?).