调用函数时需要参数

时间:2017-09-28 14:21:17

标签: python

我有一个包含以下文档结构的包:

类     builtins.object         EClient

class EClient(builtins.object)
 |  Methods defined here:
 |  
 |  __init__(self, wrapper)
 |      Initialize self.  See help(type(self)) for accurate signature.

 |  connect(self, host, port, clientId)
 |      This function must be called before any other. There is no
 |      feedback for a successful connection, but a subsequent attempt to
 |      connect will return the message "Already connected."
 |      
 |      host:str - The host name or IP address of the machine where TWS is
 |          running. Leave blank to connect to the local host.
 |      port:int - Must match the port specified in TWS on the
 |          Configure>API>Socket Port field.
 |      clientId:int - A number used to identify this client connection. All
 |          orders placed/modified from this client will be associated with
 |          this client identifier.
 |      
 |          Note: Each client MUST connect with a unique clientId.

这里我想调用这样的连接方法:

if __name__ == '__main__':
ibapi.client.EClient.connect("127.0.0.1",7497,999)

我一直收到这个错误:

  

追踪(最近一次通话):    文件“E:/Python/IB/IBTest/IBTutorial.py”,第30行,in     ibapi.client.EClient.connect( “127.0.0.1”,7497,999)   TypeError:connect()缺少1个必需的位置参数:'clientId'

所以我模糊地看到问题出在我没有传递的论证中,但我不知道如何让它正常工作。

1 个答案:

答案 0 :(得分:2)

您忘了创建类实例。

ibapi.client.EClient(wrapper).connect("127.0.0.1",7497,999)

# assuming you have the wrapper object.

你只是在类本身上调用一个未绑定的方法,而不提供它的所有参数。