For a deeper look into our Elektron API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
21 7 6 11

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

websockets
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Upvote
Accepted
79.2k 251 52 74

@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
        ]
    }
]
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thank you Jirapongse it solved solved my issue.

Kind regards,

Johan

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.