Skip to main content
 首页 » 编程设计

python之QuickFix Python API之可以在 Python 中子类化 MessageStoreFactory 吗

2025年05月04日27langtianya

当使用 QuickFix 的 Python 绑定(bind)时,如何在 Python 中子类化 MessageStoreFactory 类?

当我尝试这样做时,对象没有被“视为”MessageStoreFactory:

NotImplementedError: Wrong number of arguments for overloaded function  'new_SocketInitiatorBase'. 
  Possible C/C++ prototypes are: 
FIX::SocketInitiator(FIX::Application &,FIX::MessageStoreFactory &,FIX::SessionSettings const &) 
FIX::SocketInitiator(FIX::Application &,FIX::MessageStoreFactory &,FIX::SessionSettings const &,FIX::LogFactory &) 

当类型错误时,SWIG 似乎会返回此错误。 (我过去只使用过 Boost - 在 SWIG 中甚至可以在 Python 中对 C++ 类进行子类化吗?)

已更新 Python 绑定(bind)是为 Ubuntu 12.04 打包的。我相当确定我的参数是正确的,因为只有当我在创建 SocketInitiator 时将其中一个 QuickFix 对象换成下面的对象时才会发生错误:

class TestStoreFactory(quickfix.MessageStoreFactory): 
    def __init__(self): 
        logging.info("TestStoreFactory()") 
 
    def create(self, sessionId): 
        logging.info("Create %s"%sessionId) 
 
    def destroy(self, messageStore): 
        logging.info("Destroy %s" % messageStore) 

请您参考如下方法:

通过调用基类构造函数解决了这个问题。

class TestStoreFactory(quickfix.MessageStoreFactory): 
    def __init__(self): 
        quickfix.MessageStoreFactory.__init__(self) 
        logging.info("TestStoreFactory()")