Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the field TestReqID naming issue #12

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ctrader_fix/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
from ctrader_fix.fixProtocol import FixProtocol

class Client(ClientService):
def __init__(self, host, port, ssl=False, delimiter = "", retryPolicy=None, clock=None, prepareConnection=None, numberOfMessagesToSendPerSecond=5):
def __init__(self, host, port, ssl=False, delimiter = "", retryPolicy=None, clock=None, prepareConnection=None):
self._runningReactor = reactor
self.numberOfMessagesToSendPerSecond = numberOfMessagesToSendPerSecond
self.delimiter = delimiter
endpoint = clientFromString(self._runningReactor, f"ssl:{host}:{port}" if ssl else f"tcp:{host}:{port}")
self._factory = Factory.forProtocol(FixProtocol, client=self)
Expand Down
1 change: 0 additions & 1 deletion ctrader_fix/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def __init__(self, *args, **kwargs):
super().__init__()
self.client = kwargs['client']
self.delimiter = self.client.delimiter
self.numberOfMessagesToSendPerSecond = self.client.numberOfMessagesToSendPerSecond
def connected(self):
self.client._connected()
def disconnected(self, reason):
Expand Down
6 changes: 3 additions & 3 deletions ctrader_fix/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ def __init__(self, config):
super().__init__("0", config)

def _getBody(self):
if hasattr(self, "TestReqId") is False:
if hasattr(self, "TestReqID") is False:
return None
return f"112={self.TestReqId}"
return f"112={self.TestReqID}"

class TestRequest(RequestMessage):
def __init__(self, config):
super().__init__("1", config)

def _getBody(self):
return f"112={self.TestReqId}"
return f"112={self.TestReqID}"

class LogoutRequest(RequestMessage):
def __init__(self, config):
Expand Down
2 changes: 1 addition & 1 deletion samples/ConsoleSample/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"SenderSubID": "QUOTE",
"TargetCompID": "cServer",
"TargetSubID": "QUOTE",
"HeartBeat": "30"
"HeartBeat": "40"
}
20 changes: 17 additions & 3 deletions samples/ConsoleSample/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,19 @@ def send(request):
"OrderCancelRequest": OrderCancelRequest,
"OrderCancelReplaceRequest": OrderCancelReplaceRequest}

testReqId = 0

def executeUserCommand():
try:
print("\n")
userInput = inputimeout("Command (ex: Help): ", timeout=30)
userInput = inputimeout("Command (ex: Help): ", timeout=int(config["HeartBeat"]))
except TimeoutOccurred:
print("Command Input Timeout")
print("Timeout, sending TestRequest (Connection will be dropped if you are not logged in yet)")
testRequest = TestRequest(config)
global testReqId
testReqId += 1
testRequest.TestReqID = testReqId
send(testRequest)
reactor.callLater(3, callable=executeUserCommand)
return
if userInput.lower() == "help":
Expand All @@ -101,12 +108,19 @@ def executeUserCommand():
request = commands[command](config)
setParameters(request, **parameters)
send(request)
print("If response message not arrived keep pressing 'Enter'")
else:
print("Invalid Command: ", userInput)
if userInput != "":
print("Invalid Command: ", userInput)
reactor.callLater(3, callable=executeUserCommand)

def onMessageReceived(client, responseMessage): # Callback for receiving all messages
print("\nReceived: ", responseMessage.getMessage().replace("", "|"))
if responseMessage.getFieldValue(35) == "1":
print("TestRequest received, sending back Heartbeat")
heartbeat = Heartbeat(config)
heartbeat.TestReqID = responseMessage.getFieldValue(112)
send(heartbeat)
reactor.callLater(3, callable=executeUserCommand)

def disconnected(client, reason): # Callback for client disconnection
Expand Down
5 changes: 5 additions & 0 deletions samples/KleinWebAppSample/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ def onMessageReceived(client, responseMessage):
if responseDeferred is not None:
responseDeferred.callback(lastReceivedMessage)
print("Received: ", lastReceivedMessage)
if responseMessage.getFieldValue(35) == "1":
print("TestRequest received, sending back Heartbeat")
heartbeat = Heartbeat(config)
heartbeat.TestReqID = responseMessage.getFieldValue(112)
send(heartbeat)
responseDeferred= None

def setParameters(request, **kwargs):
Expand Down