Invalid Logon message: Tag specified out of required order, field=57\x0110=118\x01'

Created at 25 Dec 2022, 08:53
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AS

ashish.sah.np

Joined 19.12.2022

Invalid Logon message: Tag specified out of required order, field=57\x0110=118\x01'
25 Dec 2022, 08:53


Getting this response from the server

b'8=FIX.4.4\x019=153\x0135=5\x0134=1\x0149=CSERVER\x0150=TRADE\x0152=20221225-06:28:44.551\x0156=demo.icmarkets.8579286\x0158=Invalid Logon message: Tag specified out of required order, field=57\x0110=118\x01'

Python code that I use:

import socket
import base64
import time, datetime
import hmac
import hashlib

PASSPHRASE = "xxxx"
USERNAME = "xxxxx"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("h50.p.ctrader.com", 5201))

seq_num = "1" # Correction: using the same MsgSeqNum for signed text and for the field 34


# Correction: t is the same in both signed RawData and in SendingTime (52)
timestamp = str(time.time())
t = str(datetime.datetime.utcnow()).replace("-","").replace(" ", "-")[:-3]

# Correction: '|' is not a valid separator for FIX, it must be '\u0001'
message   = "\u0001".join([t, "A", seq_num, "CSERVER", PASSPHRASE]).encode("utf-8")

msgType = "A"

body = "34={}|52={}|49=demo.icmarkets.xxx|56=CSERVER|98=0|57=TRADE|50=TRADE|141=Y|108=30|553={}|554={}|".format(seq_num, t,USERNAME, PASSPHRASE) # using the same time (t) and seq_num as in signed text

# Correction: bodyLength is the number of characters, not bytes, also it must include everything after "8=FIX.4.2|9={}|" i.e. the "35=A|" part of the header
bodyLength = len("35={}|".format(msgType)) + len(body)
header     = "8=FIX.4.4|9={}|35={}|".format(bodyLength, msgType)
msg        = header + body

msg = msg.replace('|', '\u0001') # Correction: '|' is not a valid separator for FIX, it must be '\u0001'

# generate the checksum:
def check_sum(s):
    sum = 0
    for char in msg:
        sum += ord(char)
    sum = str(sum % 256)
    while len(sum) < 3:
        sum = '0' + sum
    return sum

c_sum = check_sum(msg)

logon = msg + "10={}\u0001".format(c_sum)
logon = logon.encode('ascii')
print(logon)

s.sendall(logon)
print(s.recv(4096))

Output :

b'8=FIX.4.4\x019=136\x0135=A\x0134=1\x0152=20221225-06:28:44.504\x0149=demo.icmarkets.xxxx\x0156=CSERVER\x0198=0\x0157=TRADE\x0150=TRADE\x01141=Y\x01108=30\x01553=xxxx\x01554=xxxxx\x0110=073\x01' b'8=FIX.4.4\x019=153\x0135=5\x0134=1\x0149=CSERVER\x0150=TRADE\x0152=20221225-06:28:44.551\x0156=demo.icmarkets.xxxxxx\x0158=Invalid Logon message: Tag specified out of required order, field=57\x0110=118\x01'



@ashish.sah.np
Replies

PanagiotisChar
27 Dec 2022, 11:57

Hi there,

Here is a correct logon message

8=FIX.4.4|9=126|35=A|49=live.theBroker.12345|56=CSERVER|34=1|52=20170117-08:03:04|57=TRADE|50=any_string|98=0|108=30|141=Y|553=12345|554=passw0rd!|10=131|

Use the same order for your tags

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar