Websocket API market_price towards multiple Service's

Hi,

I can't find any documentation on how to request market prices towards multiple Service's, would you be able to provide with such or a working example on how to write it?

I am using Websocket API with Python and your market_price.py example like below towards one Service only:

def send_market_price_request(ws):
""" Create and send simple Market Price request """
mp_req_json = {
'ID': 2,
'Key': {
'Name': ["EUR=,"DKK="],

'Service': 'IDN_SELECTFEED'
},
"View": [6,
22,
25,
30,
31,
1010,
1025],
'Streaming': not snapshot,
}

ws.send(json.dumps(mp_req_json))
print("SENT:")
print(json.dumps(mp_req_json, sort_keys=True, indent=2, separators=(',', ':')))

And I am looking for something like below if possible:

def send_market_price_request(ws):
""" Create and send simple Market Price request """
mp_req_json = {
'ID': 2,
'Key': [{
'Name': ["EUR=","DKK="],

'Service': 'IDN_SELECTFEED'
},
{
'Name': ["EUR=MAFX","DKK=MAFX"],

'Service': 'INTERNAL_PRICE'
}
],
"View": [6,
22,
25,
30,
31,
1010,
1025],
'Streaming': not snapshot,
}

ws.send(json.dumps(mp_req_json))
print("SENT:")
print(json.dumps(mp_req_json, sort_keys=True, indent=2, separators=(',', ':')))


Kind regards,

Johan

Tagged:

Best Answer

  • Jirapongse
    Answer ✓

    @johan.lundquist

    Thank you for reaching out to us.

    The "Key" is an object, not an array.

    Therefore, you need to create another request message for another service. For example, this is for IDN_SELECTFEED.

      mp_req_json = {
            'ID': 2,
            'Key': {
                'Name': ["EUR=,"DKK="],
     
                'Service': 'IDN_SELECTFEED'
            },
            "View": [6,
            22,
            25,
            30,
            31,
            1010,
            1025],
            'Streaming': not snapshot,
        }

    This one is for INTERNAL_PRICE.

     mp_req_json1 = {
            'ID': 5,
            'Key': {
                'Name': ["EUR=MAFX","DKK=MAFX"],
    'Service': 'INTERNAL_PRICE'
            },
            "View": [6,
            22,
            25,
            30,
            31,
            1010,
            1025],
            'Streaming': not snapshot,
        }

    Otherwise, you can send an array of the request messages. For example:

    [
        {
            "ID": 2,
            "Key": {
                "Name": [
                    "JPY=",
                    "THB="
                ],
                "Service": "{{REALTIME_SERVICE}}"
            },
            "View": [
                22,
                25
            ]
        },
        {
            "ID": 5,
            "Key": {
                "Name": [
                    "/PTT.BK",
                    "/IBM.N"
                ],
                "Service": "ELEKTRON_DD"
            },
            "View": [
                22,
                25
            ]
        }
    ]

Answers