Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

'Queue' object is not callable. Authenticated #145

Open
AndrejLischishin opened this issue Jul 12, 2018 · 9 comments
Open

'Queue' object is not callable. Authenticated #145

AndrejLischishin opened this issue Jul 12, 2018 · 9 comments

Comments

@AndrejLischishin
Copy link

AndrejLischishin commented Jul 12, 2018

wss.authenticate()
positions_q = wss.positions()
print(positionss_q.get())

added to README code and error is: 'Queue' object is not callable

@AndrejLischishin AndrejLischishin changed the title 'Queue' object is not callable 'Queue' object is not callable. Authenticated Jul 12, 2018
@EpicAAA
Copy link

EpicAAA commented Jul 12, 2018

I've also been working on this most of today. With minimal success, I've used this.

wss = BtfxWss(key, secret)
wss.start()

while not wss.conn.connected.is_set():
    time.sleep(1)
wss.authenticate()

p = wss.positions

while True:
    print(p.get())
    time.sleep(5)

It may be that your wss.positions() should be wss.positions and I also see an extra s on positionss_q.get() but that's probably just a typo because you would get syntax errors,

The problem with this implementation that I can't currently figure out is I can get one initial snapshot of my positions but it's missing things like profit/loss as those are coming back as null. From the docs this needs to be fixed with a calc but I don't know how to implement that in this system or where the rest of the responses are going.

@AndrejLischishin
Copy link
Author

I have now the same issue as you, there is smth similar in issue #101 , take a look at it, I ll look at it later today

@EpicAAA
Copy link

EpicAAA commented Jul 13, 2018

I got quite a bit further.

  1. You need to be in the dev branch, while issue How to read "calc" from websocket #101 is from 7 months ago the main branch hasn't been updated to allow access to the wss.accounts() queue.
    2 The calc function doesn't work as is so you need to use the send function in the websocket connector to send your own calc payload.

Here's my code to make a live ticker of the current profit loss percentage as that's what I'm interested in mainly. I've left in some of my 'debugging' comments as they may be useful to you or anyone else who stumbles across this in future. (At 1 second intervals it usually gets the ticker but once a minute you may get a null response)

wss = BtfxWss(key,secret)
wss.start()

while not wss.conn.connected.is_set():
    time.sleep(1)
wss.authenticate()
payload = [0, "calc", None, [["position_tDSHUSD"],]]
time.sleep(1)

#print(wss.account().qsize())
while not wss.account().empty():
    wss.account().get()

while True:
    wss.conn.send(list_data=payload)
    time.sleep(1)

# print(wss.account().qsize())
# while not wss.account().empty():
    if not wss.account().empty():
        pu = wss.account().get()
        print(pu[0][1][7])
    else:
        print ('none')

# print(pos)
# print(pos[0])
# print(pos[0][0])
# print(pu[0][1][7])
    time.sleep(1)

@AndrejLischishin
Copy link
Author

AndrejLischishin commented Jul 14, 2018

I keep getting this error:

File "bitfinex_api.py", line 36, in <module>
while not wss.account().empty():
AttributeError: 'BtfxWss' object has no attribute 'account'

I guess this is because of the dev/master branch thing, I've installed btfxwss with pip and then just cloned dev branch separately, but it seems still not to work, how did u install it?

@AndrejLischishin
Copy link
Author

I solved that and what I am getting now is:

while not wss.account().empty():
TypeError: 'collections.defaultdict' object is not callable

@EpicAAA
Copy link

EpicAAA commented Jul 18, 2018

I'm not sure. Can I look at some more code? All I could recommend is make sure you're using wss.account() instead of without the () wss.account won't work

@AndrejLischishin
Copy link
Author


import logging
import time
import sys
from btfxwss import client, connection, queue_processor

log = logging.getLogger(__name__)

fh = logging.FileHandler('test.log')
fh.setLevel(logging.DEBUG)
sh = logging.StreamHandler(sys.stdout)
sh.setLevel(logging.DEBUG)

log.addHandler(sh)
log.addHandler(fh)
logging.basicConfig(level=logging.DEBUG, handlers=[fh, sh])

key = '...'
secret='...'

wss = client.BtfxWss(key,secret)
wss.start()

while not wss.conn.connected.is_set():
    time.sleep(1)

# Subscribe to some channels
wss.subscribe_to_ticker('BTCUSD')
wss.subscribe_to_order_book('BTCUSD')
wss.subscribe_to_candles(pair = 'BTCUSD', timeframe = '1m')

wss.authenticate()
payload = [0, "calc", None, [["position_tIOTUSD"],]]
time.sleep(1)


while not wss.account().empty():
    wss.account().get()

while True:
    wss.conn.send(list_data=payload)
    time.sleep(1)

if not wss.account().empty():
    pu = wss.account().get()
    print(pu[0][1][7])
else:
    print ('none')

# Unsubscribing from channels:
wss.unsubscribe_from_ticker('BTCUSD')
wss.unsubscribe_from_order_book('BTCUSD')
wss.unsubscribe_from_candles(pair = 'BTCUSD', timeframe = '1m')

# Shutting down the client:
wss.stop()



@EpicAAA
Copy link

EpicAAA commented Jul 18, 2018

I use

from btfxwss import BtfxWss
wss = BtfxWss(key secret)

so your wss = client.BtfxWss(key,secret) may not be working correctly. Try importing like that.

@AndrejLischishin
Copy link
Author

I ve manually imported client.py and other files because account() is only in dev branch and btfxwss
is installed via pip, but it doesn't contain dev branch, only master

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants