从Python类外部调用函数

2024-10-03 23:27:23 发布

您现在位置:Python中文网/ 问答频道 /正文

StreamingForexPrices内调用stream_to_stop()时遇到一些问题。。以下代码给出了此错误:

TypeError: unbound method stream_to_stop() must be called with StreamingForexPrices instance as first argument (got int instance instead)

有人能帮我理解吗?谢谢

class StreamingForexPrices(object):
    def __init__(
        self, domain, access_token,
        account_id, instruments, events_queue
    ):
        self.domain = domain
        self.access_token = access_token
        self.account_id = account_id
        self.instruments = instruments
        self.events_queue = events_queue

    def stream_to_stop(self):
        response = self.connect_to_stream()
        if response.status_code != 200:
            return
        for line in response.iter_lines(1):
            if line:
                try:
                    msg = json.loads(line)
                except Exception as e:
                    print "Caught exception when converting message into json\n" + str(e)
                    return
                if msg.has_key("instrument") or msg.has_key("tick"):
                    print msg["tick"]["ask"] - .001
                    instrument = msg["tick"]["instrument"]
                    time = msg["tick"]["time"]
                    bid = msg["tick"]["bid"]
                    ask = msg["tick"]["ask"]
                    stopLoss = msg["tick"]["ask"] - .001
                    tev = StopEvent(stopLoss)
                    self.events_queue.put(tev)

stop = StreamingForexPrices.stream_to_stop()
print stop

我的目标是将流的输出输出输出到\u stop。。再次感谢!你知道吗

已编辑缩进。。你知道吗


Tags: toselftokenidstreamaccessqueuedomain
1条回答
网友
1楼 · 发布于 2024-10-03 23:27:23
domain = "www.example.com"
access_token = "ldkjflekfjelkxlk"
account_id = "account"
instruments = ["some instrument I don't how to play"]
events_queue = xxx # It sounds like an object created to handle queue
stop = StreamingForexPrices(domain, access_token, account_id, instruments, events_queue).stream_to_stop()

How to use python class

相关问题 更多 >