Open AndrejLischishin opened 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.
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
I got quite a bit further.
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)
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?
I solved that and what I am getting now is:
while not wss.account().empty():
TypeError: 'collections.defaultdict' object is not callable
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
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()
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.
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
wss.authenticate()
positions_q = wss.positions()
print(positionss_q.get())
added to README code and error is: 'Queue' object is not callable