No answer from server
No answer from server
16 Nov 2020, 20:05
OK, I tried really hard, gone through quite a few existing forum threads with similar issues.
It seems that the server just doesn't want to send me any data back. I get no error but also no response...
I've written my code in Python looking at the example code of C#. Here is what I have:
import socket
import datetime
### 1 Custom variables: ###
heartbeat_interval = 30
user = r'1234567'
password = r'password'
SenderCompID = r'icmarkets.1234567'
TargetCompID = r'CSERVER'
MsgSeqNum = 1
utct = datetime.datetime.utcnow()
SendingTime = utct.strftime("%Y%m%d-%H:%M:%S")
### 2 Constructing Body ###
body = {
'encryption_scheme': r'98=0',
'heartbeat_interval': r'108=%s' %heartbeat_interval,
# 'sequence_reset': r"141=Y",
'username': r"553=%s" %user,
'password': r"554=%s" %password
}
bodyStr = ''
for e in body:
bodyStr += body[e]+'|'
### 3 Constructing Header ###
header = {
'8-BeginString': r"8=FIX.4.4",
'9-BodyLength': r"9={message_length}",
'35-MsgType': r"35=A",
'34-MsgSeqNum': r"34=%s" %MsgSeqNum,
'49-SenderCompID': r"49=%s" %SenderCompID,
'57-TargetSubID': r"57=TRADE",
'50-SenderSubID': r"50=TRADE",
'52-SendingTime': r"52=%s" %SendingTime,
'56-TargetCompID': r"56=%s" % TargetCompID,
}
#
headerStr = ''
for e in header:
headerStr += header[e] +'|'
message = headerStr + bodyStr
message_length = len(message.replace('8=FIX.4.4|', ''))
message = message.replace('{message_length}', str(message_length))
### 4 Calculating checksum ###
arr = bytes(message.replace('|', r'\x01'), 'ascii')
s = 0
for byte in arr:
s += byte
cs = s % 256
if len(str(cs)) == 2:
cs = '0%s' % cs
print("Checksum = %s" % cs)
message = message + '10=%s|' %cs
# '\x01' or '\u0001'?
message = message.replace('|', r'\x01')
print(message)
### 5 Sending message ###
message = message.encode('ascii')
print(message)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 37.48.78.15 or h59.p.ctrader.com
s.connect(("37.48.78.15", 5202))
s.sendall(message)
print(s)
data = s.recv(4096)
print("received message:", data)
I get no errors but I also don't get any response from server. The higher likelyhood of where I stumbled:
1. In Python, what should be the '|' replaced with, '\x01' or '\u0001'?
2. What TAG #50 should be in this case? Should it be the same as '57 TargetSubID'? In documentation it's '50=any_string'. But on the same page slightly further down in the table it's 'QUOTE - Assigned value used to identify specific message originator.'
3. If I'm not using SSL, then I have to connect to 37.48.78.15:5201 for QUOTE and to 37.48.78.15:5202 for TRADE?
4. If SSL then to 37.48.78.15:5211 for QUOTE and to 37.48.78.15:5212 for TRADE respectively?
5. When I do 'message = message.encode('ascii')' my message start looking like this with double '\\', is it OK?:
b'8=FIX.4.4\\x019=135\\x0135=A\\x0134=1\\x0149=icmarkets.1234567\\x0157=TRADE\\x0150=TRADE\\x0152=20201116-18:01:58\\x0156=CSERVER\\x0198=0\\x01108=30\\x01553=1234567\\x01554=password\\x0110=072\\x01'
Any help and suggestions would be very much appreciated!
Thank you!
Replies
mywebsidekicks
18 Nov 2020, 21:49
( Updated at: 21 Dec 2023, 09:22 )
RE:
@PanagiotisCharalampous
Ok, I tried to run
In the Visual Studio 2019 but got an error:
1>------ Build started: Project: FIX API Library, Configuration: Debug|AnyCPU ------
1>C:\Users\irmsc\AppData\Local\Temp\tmp4d2b9d281c5e45808cac2e0a5d03d93c.proj(23,1): error MSB3202: The project file "C:\Users\irmsc\pp\FIX API Library\FIX API Library.csproj" was not found.
Build Failure. Error: Failed to complete scanning on file ‘C:\Users\irmsc\pp\FIX API Library\FIX API Library.csproj’
The screenshot:
@mywebsidekicks
PanagiotisCharalampous
19 Nov 2020, 13:59
Hi mywebsidekicks,
As per the error
The project file "C:\Users\irmsc\pp\FIX API Library\FIX API Library.csproj" was not found.
Can you confirm that file is there and it is not locked by any other process e.g. antivirus or something else?
Best Regards,
Panagiotis
@PanagiotisCharalampous
mywebsidekicks
19 Nov 2020, 19:58
RE:
PanagiotisCharalampous said:
Hi mywebsidekicks,
As per the error
The project file "C:\Users\irmsc\pp\FIX API Library\FIX API Library.csproj" was not found.
Can you confirm that file is there and it is not locked by any other process e.g. antivirus or something else?
Best Regards,
Panagiotis
Yes, I confirm. I first though this is due to old Microsoft Build tools 2017, but I reinstalled both Visual Studio and build tools of 2019.
May be I should try to run this ono an VPS..
@mywebsidekicks
mywebsidekicks
22 Nov 2020, 18:31
Ok, I've connected with C# sample to the TRADE stream,
but still can't make it work on Python... :(
I'm doing exactly the same.
@mywebsidekicks
PanagiotisCharalampous
17 Nov 2020, 08:50
Hi mywebsidekicks,
Unfortunately I cannot help you with Python, as I do not have any experience with the language. If you used .Net, I would have been of greater assistance. I will reply only to the questions I know.
2) if TargetSubID=QUOTE then it needs to be QUOTE, else any string you want
3) Correct. But you should use the host names instead of the IP
4) Correct.
If the message is correct, then the most common reason the server might not respond is the credentials.
I would suggest that you first try to successfully login using the sample project and then compare your messages with the messages you get from the sample.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous