Crypto-toolbox / btfxwss

Bitfinex Websocket API Client written in Python3
MIT License
284 stars 125 forks source link

'Queue' object is not callable. Authenticated #145

Open AndrejLischishin opened 6 years ago

AndrejLischishin commented 6 years ago

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

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

EpicAAA commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

I got quite a bit further.

  1. You need to be in the dev branch, while issue #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 commented 6 years ago

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 commented 6 years ago

I solved that and what I am getting now is:

while not wss.account().empty():
TypeError: 'collections.defaultdict' object is not callable
EpicAAA commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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