def iMain(): # lGetOptionsArgs adds sMt4Dir/MQL4/Python to the sys.path ( oOptions, lArgs, ) = lGetOptionsArgs() # so lGetOptionsArgs must be called before this import from ZmqBinListener import ZmqBinMixin if not lArgs: # subscribe to everything lArgs = [''] lTopics = lArgs oMixin = None try: # sChartId is in oOptions oMixin = ZmqBinMixin(**oOptions.__dict__) oMixin.eConnectToSubPub(lTopics, iDir=zmq.SUB) oMixin.eConnectToReqRep(iDir=zmq.REQ) i = 0 while True: i += 1 sys.stderr.write("Command: ") sRequest = sys.stdin.readline().strip() if not sRequest: break if oOptions.sExecType == "default": sType = sDefaultExecType(sRequest) elif oOptions.sExecType == "exec": # execs are executed immediately and return a result on the wire # They're things that take less than a tick to evaluate sType = "exec" else: sType = "cmd" # only exec really works right now - cmd misses the retval sometimes sType = "exec" sMarkIn = sMakeMark() gRetval = oMixin.gCmdExec(sMarkIn, sRequest, sType, oOptions) print gRetval except KeyboardInterrupt: if oOptions and oOptions.iDebugLevel >= 1: vInfo("exiting") except Exception as e: vError(str(e) +"\n" + \ traceback.format_exc(10) +"\n") sys.stdout.flush() sys.exc_clear() finally: if oMixin: oMixin.bCloseContextSockets() return 0
def iMain(): # lGetOptionsArgs adds sMt4Dir/MQL4/Python to the sys.path (oOptions, lArgs,) = lGetOptionsArgs() # so lGetOptionsArgs must be called before this import from ZmqBinListener import ZmqBinMixin if not lArgs: # subscribe to everything lArgs = [''] lTopics = lArgs oMixin = None try: # sChartId is in oOptions oMixin = ZmqBinMixin(**oOptions.__dict__) oMixin.eConnectToSubPub(lTopics, iDir=zmq.SUB) oMixin.eConnectToReqRep(iDir=zmq.REQ) i = 0 while True: i += 1 sys.stderr.write("Command: ") sRequest = sys.stdin.readline().strip() if not sRequest: break if oOptions.sExecType == "default": sType = sDefaultExecType(sRequest) elif oOptions.sExecType == "exec": # execs are executed immediately and return a result on the wire # They're things that take less than a tick to evaluate sType = "exec" else: sType = "cmd" # only exec really works right now - cmd misses the retval sometimes sType = "exec" sMarkIn = sMakeMark() gRetval = oMixin.gCmdExec(sMarkIn, sRequest, sType, oOptions) print gRetval except KeyboardInterrupt: if oOptions and oOptions.iDebugLevel >= 1: vInfo("exiting") except Exception as e: vError(str(e) +"\n" + \ traceback.format_exc(10) +"\n") sys.stdout.flush() sys.exc_clear() finally: if oMixin: oMixin.bCloseContextSockets() return 0
def iMain(): # lGetOptionsArgs adds sMt4Dir/MQL4/Python to the sys.path ( oOptions, lArgs, ) = lGetOptionsArgs() # so lGetOptionsArgs must be called before this import from ZmqBinListener import ZmqBinMixin if not lArgs: # subscribe to everything lArgs = [''] elif lKnownTypes: for sElt in lArgs: assert sElt in lKnownTypes lTopics = lArgs iSubPubPort = oOptions.iSubPubPort assert 0 < int(iSubPubPort) < 66000 sHostAddress = oOptions.sHostAddress assert sHostAddress oMixin = None try: oMixin = ZmqBinMixin(**oOptions.__dict__) #print("INFO: setting linger to 0") oMixin.oContext.linger = 0 oMixin.eConnectToSubPub(lTopics) iReqRepPort = oOptions.iReqRepPort oReqRepSocket = None sTopic = '' while True: # was: sString = oMixin.oSubPubSocket.recv() sString = oMixin.sRecvOnSubPub() if not sString: continue sTopic = "" try: lElts = sString.split('|') if len(lElts) < 6: print "WARN: somethings a little wrong: expected len>=6 " + \ repr(lElts) sCmd = lElts[0] # the first part of the message is the topic if sCmd not in lKnownTypes: print "WARN: unrecognized beginning of message: " + \ repr(map(ord, sCmd)) # should check for bytes < 32 or > 128 for sElt in lKnownTypes: if sCmd.endswith(sElt): sCmd = sElt break if sCmd not in lKnownTypes: continue if sTopic == "": sTopic = sCmd except Exception as e: print "ERROR: exception in recv: " + str(e) # if not sString: continue print "INFO: %s at %15.5f" % (sString, time.time()) sTopic = '' # print map(ord, sString[:18]) except KeyboardInterrupt: pass finally: if oMixin: oMixin.bCloseContextSockets()
def iMain(): # lGetOptionsArgs adds sMt4Dir/MQL4/Python to the sys.path (oOptions, lArgs,) = lGetOptionsArgs() # so lGetOptionsArgs must be called before this import from ZmqBinListener import ZmqBinMixin if not lArgs: # subscribe to everything lArgs = [''] elif lKnownTypes: for sElt in lArgs: assert sElt in lKnownTypes lTopics = lArgs iSubPubPort = oOptions.iSubPubPort assert 0 < int(iSubPubPort) < 66000 sHostAddress = oOptions.sHostAddress assert sHostAddress oMixin = None try: oMixin = ZmqBinMixin(**oOptions.__dict__) #print("INFO: setting linger to 0") oMixin.oContext.linger = 0 oMixin.eConnectToSubPub(lTopics) iReqRepPort = oOptions.iReqRepPort oReqRepSocket = None sTopic = '' while True: # was: sString = oMixin.oSubPubSocket.recv() sString = oMixin.sRecvOnSubPub() if not sString: continue sTopic = "" try: lElts = sString.split('|') if len(lElts) < 6: print "WARN: somethings a little wrong: expected len>=6 " + \ repr(lElts) sCmd = lElts[0] # the first part of the message is the topic if sCmd not in lKnownTypes: print "WARN: unrecognized beginning of message: " + \ repr(map(ord, sCmd)) # should check for bytes < 32 or > 128 for sElt in lKnownTypes: if sCmd.endswith(sElt): sCmd = sElt break if sCmd not in lKnownTypes: continue if sTopic == "": sTopic = sCmd except Exception as e: print "ERROR: exception in recv: " +str(e) # if not sString: continue print "INFO: %s at %15.5f" % (sString , time.time()) sTopic = '' # print map(ord, sString[:18]) except KeyboardInterrupt: pass finally: if oMixin: oMixin.bCloseContextSockets()