Minimal Working Example of FIX Protocol Api

Currently, I am trying to connect to the FIX Protocol API (testnet). I have problem and I am not sure at which part is the problem.
I have some basic tcp/tls connection, I have tested it with api.binance.com, and it’s returns some result, but the fix api returns nothing and also doesnot return any exception. At this example I am trying send the example message from the doc.

import socket
import ssl

hostname = 'fix-oe.testnet.binance.vision'

context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_verify_locations('cacert.pem')


with socket.create_connection((hostname, 9000)) as sock:
    with context.wrap_socket(sock, server_hostname=hostname) as ssock:
        print(ssock.version())
        r = ssock.write(
            b"8=FIX.4.4|9=248|35=A|34=1|49=5JQmUOsm|52=20240612-08:52:21.613|56=SPOT|95=88|96=KhJLbZqADWknfTAcp0ZjyNz36Kxa4ffvpNf9nTIc+K5l35h+vA1vzDRvLAEQckyl6VDOwJ53NOBnmmRYxQvQBQ==|98=0|108=30|141=Y|553=W5rcOD30c0gT4jHK8oX5d5NbzWoa0k4SFVoTHIFNJVZ3NuRpYb6ZyJznj8THyx5d|25035=1|10=000|"
        )
        print(
            ssock.recv(2048)
        )

result:

TLSv1.3
b''

Should not the api return the Reject message?

Yep, I have resolved my issue. Just in case working code:

import base64
from datetime import datetime

import socket
import ssl
import simplefix
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
from cryptography.hazmat.primitives.serialization import load_pem_private_key

def logon_raw_data(private_key: Ed25519PrivateKey,
                   sender_comp_id: str,
                   target_comp_id: str,
                   msg_seq_num: str,
                   sending_time: str):
    """
    Computes the value of RawData (96) field in Logon<A> message.
    """
    payload = chr(1).join([
        'A',
        sender_comp_id,
        target_comp_id,
        msg_seq_num,
        sending_time,
    ])

    signature = private_key.sign(payload.encode('ASCII'))
    return base64.b64encode(signature).decode('ASCII')


with open('your.pem', 'rb') as f:
    private_key = load_pem_private_key(data=f.read(),
                                       password=None)

sending_time = datetime.utcnow().strftime("%Y%m%d-%H:%M:%S.%f")[:-3]
sender_comp_id = "EXAMPLE2"
target_comp_id = "SPOT"
msg_seq_num = 1

api = '<API key>'

raw_data = logon_raw_data(private_key,
                          sender_comp_id=sender_comp_id,
                          target_comp_id=target_comp_id,
                          msg_seq_num=str(msg_seq_num),
                          sending_time=sending_time)




message = simplefix.FixMessage()

BEGIN_STRING = "8=FIX.4.4"

message.append_string(BEGIN_STRING, header=True)
message.append_pair(35, 'A', header=True)
message.append_pair(34, msg_seq_num, header=True)
message.append_pair(49, sender_comp_id, header=True)
message.append_pair(52, sending_time, header=True)
message.append_pair(56, 'SPOT', header=True)
message.append_pair(95, len(raw_data))
message.append_pair(96, raw_data)
message.append_pair(98, 0)
message.append_pair(108, 5)
message.append_pair(141, 'Y')
message.append_pair(553, api)
message.append_pair(25035, 1)

r = message.encode()
print(r)

hostname = 'fix-oe.testnet.binance.vision'

context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_verify_locations('cacert.pem'). # could find at `openssl version -d`


with socket.create_connection((hostname, 9000)) as sock:
    with context.wrap_socket(sock, server_hostname=hostname) as ssock:
        print(ssock.version())
        r = ssock.write(
            r
        )
        print(
            ssock.recv(2048)
        )