Authentication

Receiving prediction events requires sending authentication information when subscribing to a prediction service. The Authentication requires sending an API key along with a signature that is produced based on a number of data elements as described below.

Authentication Parameters

In order to authenticate your request, the following information is required:

  • API key

  • API private key

  • Message type

  • Current timestamp in millisecond

Authentication Logic

Use the following steps:

  • Build a string message: message_type + api_key + timestamp

  • Sign the message using Hmac512 algorithm.

  • Send the signature produced above along with other subscription parameters

Timestamp in the context of Authentication is represented as Millisecond Epoch as per below sample

Sample code to build a subscription message

now = int(time.time()*1000)
message = {
    "message_type": "subscribe",
    "predictions": [
     {
            "type": "price_movement",
            "exchange_id": "cme",
            "symbol": "ESU3",
            "params": {
                "threshold": "0.00002",
                "horizon": "10"
            }
        }
    ],
    "heartbeat": True,
    "timestamp": now,
    "api_key": api_key
}
message_to_sign = message['message_type'] + message['api_key'] + str(message['timestamp'])
message['signature'] = sign(api_secret, message_to_sign)

Use the following method to create a signature:

def sign(secret, message):
    signature = hmac.new(base64.b64decode(secret), message.encode('utf-8'), digestmod=hashlib.sha512).digest()
    signature_b64 = base64.b64encode(signature).decode()
    return signature_b64

Last updated