【问题标题】:Argument required when calling function调用函数时需要参数
【发布时间】:2017-09-28 14:21:17
【问题描述】:

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

类 内置对象 电子客户端

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)

我不断收到此错误:

Traceback(最近一次调用最后一次): 文件“E:/Python/IB/IBTest/IBTutorial.py”,第 30 行,在 ibapi.client.EClient.connect("127.0.0.1",7497,999) 类型错误:connect() 缺少 1 个必需的位置参数:'clientId'

所以我隐约看出问题在于我没有传入的参数self,但我不知道如何让它正常工作。

【问题讨论】:

  • ibapi.client.EClient(wrapper).connect("127.0.0.1",7497,999).
  • 你必须创建一个EClient的实例。
  • 我怎样才能将它作为参数'wrapper = self' 传递,我是否需要编写另一个函数来覆盖它的 init

标签: python


【解决方案1】:

你忘记创建类实例了。

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

# assuming you have the wrapper object.

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    相关资源
    最近更新 更多