I am not getting the reply from the server that I want using Python.
Created at 26 Mar 2018, 21:10
BE
I am not getting the reply from the server that I want using Python.
26 Mar 2018, 21:10
I am starting to use FIX API, but I do not know C#, so I am tring to use Python. I have created a MessageConstructor that constructed the following message:
8=FIX.4.4|9=126|35=A|49=icmarkets.3327814|56=cServer|57=TRADE|50=BVN|34=1|52=20180326-18:06:43.105|98=0|108=30|141=Y|553=3327814|554=password|10=206|
When I try to send this message to the server, I get a NoneType message as reply. I do not know where the problem is. It can be the message, the way that I am using to connect to the server or anything else. This is the code that a I am using to communicate with the server:
import socket class API_Socket: def __init__(self): self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) def connect(self, host, port): self.sock.connect((host, port)) def send(self, msg): self.msg=msg self.sock.send(msg) def receive(self,buffer=1024): data=b'' while True: part=self.sock.recv(buffer) data+=part if len(part)<buffer: break self.sock.close() data_semi_parsed=data.decode().replace('\u0001','|') return data_semi_parsed def get_reply(self,host,port,msg,buffer=1024): self.connect(host,port) self.send(msg) return self.receive(buffer) if __name__=='__main__': message='8=FIX.4.4|9=126|35=A|49=icmarkets.3327814|56=cServer|57=TRADE|50=BVN|34=1|52=20180326-18:06:43.105|98=0|108=30|141=Y|553=3327814|554=password|10=206|' byte_message=bytearray(message.replace('|','\u0001'),'utf-8')) s=API_Socket() response=s.get_reply('h43.p.ctrader.com',5201,byte_message) print(response)
Any help or advise will be welcome.