在 Python3.5 中调用函数时出错

Error while calling function in Python3.5

我正在尝试 运行 IqoptionAppi

的存储库

虽然我正在尝试 运行 命令:api.getcandles(1,60,25)
发生以下错误:

api.getcandles(1,60,25)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __call__() takes 3 positional arguments but 4 were given

我看过这个函数,是这样的:

from iqoptionapi.ws.chanels.base import Base


class GetCandles(Base):
    """Class for IQ option candles websocket chanel."""
    # pylint: disable=too-few-public-methods

    name = "candles"

    def __call__(self, active_id, duration, amount):
        """Method to send message to candles websocket chanel.

        :param active_id: The active/asset identifier.
        :param duration: The candle duration (timeframe for the candles).
        :param amount: The number of candles you want to have
        """
        data = {"active_id": active_id,
                "duration": duration,
                "chunk_size": 25,
                "from": self.api.timesync.server_timestamp - (duration * amount),
                "till": self.api.timesync.server_timestamp}

        self.send_websocket_request(self.name, data)

存储库说它可以在 Python 2.7 上运行,但我尝试在 Python 3.5 上安装它,但它仍然可以运行,除了上述问题。指导我到底错过了什么。

这里的问题是iqoptionapi/ws/chanels/candles.py module from latest PyPI version differs from Github's master branch version没有amount参数(好像等于2)。

master 分支中:

def __call__(self, active_id, duration, amount):
    ...
    "from": self.api.timesync.server_timestamp - (duration * amount),
    ...

0.5 版本中:

def __call__(self, active_id, duration):
    ...
    "from": self.api.timesync.server_timestamp - (duration * 2),
    ...

所以我们可以忽略这个参数(完全不传,使用默认值2)或者install master branch version using git like

> pip install --upgrade git+https://github.com/n1nj4z33/iqoptionapi.git@master

这里我们使用 --upgrade 标志,因为版本没有改变,所以我们强制重新安装包。

或者另一种选择:您可以要求 repo 所有者发布新版本并在 PyPI.

上发布