如何将响应发送回发起者

时间:2019-08-22 08:48:48

标签: python-3.x quickfix fix-protocol

所以我试图建立一个FIX服务器,该服务器将帮助我接受FIX消息。 我设法从我制作的演示客户端接收消息。 我想根据收到的消息执行操作,然后将响应返回给启动器。

我已经添加了我使用的代码,它以某种方式通过接收器将其发送回启动器。

import quickfix as fix


def create_fix_response_for_wm(self, session_id, message, api_response):
        try:
            report = quickfix50sp2.ExecutionReport()
            report.setField(fix.Text(api_response.text))
            report.setField(fix.ListID(message.getField(66)))
            if message.getFieldIfSet(fix.OrderID()):
                report.setField(fix.OrderID(message.getField(14)))
            elif message.getFieldIfSet(fix.ListID()):
                report.setField(fix.OrderID(message.getField(66)))


            fix.Session.sendToTarget(report, session_id)
        except Exception as e:
            logger.exception(f'could not create response')

1 个答案:

答案 0 :(得分:1)

因此,在查看并测试了几次之后,这才是我发现的。

import quickfix as fix

def create_fix_response_for_wm(self, session_id, message, api_response):
        try:
            report = quickfix50sp2.ExecutionReport()
            report.setField(fix.Text(api_response.text))
            report.setField(fix.ListID(message.getField(66)))
            if message.getFieldIfSet(fix.OrderID()):
                report.setField(fix.OrderID(message.getField(14)))
            elif message.getFieldIfSet(fix.ListID()):
                report.setField(fix.OrderID(message.getField(66)))


            fix.Session.sendToTarget(report, session_id)
        except Exception as e:
            logger.exception(f'could not create response')

session_id =应该是可以这样构建的SessionID对象:

session_id = fix.SessionID("FIXT.1.1", <ACCEPTOR - SenderCompID of the acceptor configuration>, <INITIATOR - TargetCompID in the acceptor configuration >)

配置示例:

[SESSION]
SocketAcceptPort=12000
StartDay=sunday
EndDay=friday
AppDataDictionary=./glossary/FIX50SP2.xml
TransportDataDictionary=./glossary/FIXT11.xml
DefaultApplVerID=FIX.5.0SP2
BeginString=FIXT.1.1
SenderCompID=MYACCEPTOR
TargetCompID=CLIENT

session_id = fix.SessionID("FIXT.1.1","MYACCEPTOR" , "CLIENT")-在我们的情况下

您在发送时使用此sessionID对象。

fix.Session.sendToTarget(<YOUR MESSAGE>, session_id)