1

我正在使用“http://www.quickfixengine.org”中的 python 代码示例并且有一个问题。我使用下面显示的代码段创建我的应用程序

import quickfix

if len(sys.argv) < 2: return
fileName = sys.argv[1]

try:
    settings = quickfix.SessionSettings(fileName)
    application = quickfix.MyApplication()
    storeFactory = quickfix.FileStoreFactory(settings)
    logFactory = quickfix.FileLogFactory(settings)
    initiator = quickfix.SocketInitiator(application, storeFactory, settings, logFactory)
    initiator.start()
    # while condition == true: do something
    initiator.stop()
except quickfix.ConfigError, e:
    print e

建立连接并登录,现在我想发送一条消息(例如订单)。为此提供的代码段是:

def sendOrderCancelRequest:
    message = quickfix.Message();
    header = message.getHeader();

    header.setField(...)
    *<...build the header and body...>*
    message.setField(...)

    Session.sendToTarget(message)

我的问题是关于那个Session物体的。它是在哪里/如何创建的?它是用类似的东西创建的Session = quickfix.Session(),还是他们没有显示的其他东西?我已经尝试了一些东西,但是由于缺乏文档,它只是反复试验......

4

1 回答 1

1

Session不是一个对象,它是一个。在这种情况下,sendToTarget()是静态方法。

Session,维护会话的类静态列表。 sendToTarget()'s 使用消息中的标题字段(或您明确提供的标题字段)来确定要发送的会话。


编辑:我误读了你的问题。这是您所问问题的答案。

会话是在 QF 引擎的内部创建的。它是由 a 创建的SessionFactory,它本身是在 and 的函数initialize()中创建的。只有当您想破解引擎源代码时,您才需要了解这些内容。InitiatorAcceptor

作为应用程序开发人员,您真的不需要会话句柄。如果你认为你这样做了,那么我猜你可能打算做一些不推荐的事情(比如想要以编程方式重置 seq#s,这是 QF 列表中常见的新手坏主意)。

If you really want a handle to it, you can use Session.lookupSession() or one of the getSession() functions of Initiator or Acceptor. But again, I don't see any reason to bother. I'm a seasoned QF user, and I had to go look this up, because it's something I never ever do.

于 2012-11-17T19:49:08.513 回答