Skip to content

Commit

Permalink
Merge pull request #12 from spotware/dev
Browse files Browse the repository at this point in the history
Fixed the field TestReqID naming issue
  • Loading branch information
amusleh-spotware-com authored Apr 13, 2022
2 parents f213449 + 5645bdc commit c030d0d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
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

0 comments on commit c030d0d

Please sign in to comment.