如何将响应发送回发起者

How to send response back to initiator

所以我正在尝试设置一个 FIX 服务器来为我提供接收 FIX 消息的服务。 我设法从我制作的演示客户端接收消息。 我想根据收到的消息执行一个动作,然后 return 响应发起者。

我已经添加了我使用的代码,它以某种方式通过接受者将它发送回发起者。

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')

所以在查看和测试了几次之后,这就是我发现的。

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)