如何将响应发送回发起者

问题描述 投票:0回答:1

所以我正在尝试设置一个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')

python-3.x quickfix fix-protocol
1个回答
0
投票

所以经过几次测试后,我发现了。

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", <RECEIVER MACHINE>, <SENDER MACHINE>)

发送时您是这个sessionID对象。

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

© www.soinside.com 2019 - 2024. All rights reserved.