Having some trouble calling stream_to_stop() from within StreamingForexPrices.. The following code gives this error:
TypeError: unbound method stream_to_stop() must be called with StreamingForexPrices instance as first argument (got int instance instead)
Can someone please help me understand? Thanks
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
My goal is to print the output of stream_to_stop.. Thanks again!
Edited indentation..
asked Apr 24, 2015 at 16:07
MacD
6863 gold badges10 silver badges28 bronze badges
1 Answer 1
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()
answered Apr 24, 2015 at 16:25
Shuo
9,0274 gold badges32 silver badges37 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
MacD
Thanks @Shuo.. This gives me the error 'NameError: name 'domain' is not defined'
jonrsharpe
@user2883183 well obviously you'll need to define the parameters you pass to
__init__ - where were you expecting them to come from?MacD
Got it.. I had taken out the parameters when writing the question here. Thanks a lot guys!
lang-py
StreamingForexPricesobject and then calling the function?StreamingForexPrices. Shouldstream_to_stopbe a@classmethod? Given that you have two methods, one of which is__init__, you might find this useful: youtube.com/watch?v=o9pEzgHorH0stream_to_stopis not a method ofStreamingForexPrices. Is the indentation right? And if it's a method ofStreamingForexPricesthen you should call it on an instance ofStreamingForexPrices, not on the class itself.