Giter VIP home page Giter VIP logo

Comments (8)

deepbrook avatar deepbrook commented on August 27, 2024

The attribute error stems from the fact that I haven't updated the sample (thanks for reporting that :D) ; it should be tickers, not ticker. See if you can connect using that! :)
Keep the issues coming! They're much appreciated!

from btfxwss.

rafaelcapucho avatar rafaelcapucho commented on August 27, 2024

Thx for your fast answer!

I changed it to tickers but seems like it is a connection problem with the WS, the logs remains the same:

INFO:btfxwss.connection:Connection Error - cafile, capath and cadata cannot be all omitted
INFO:btfxwss.connection:Connection closed
INFO:btfxwss.connection:Attempting to connect again in 10 seconds.

And seems like the self.queue_processor.tickers is empty because the pair BTCUSD wasn't found:

print(wss.queue_processor.tickers)
wss.tickers('BTCUSD')

results in:

defaultdict(<class 'queue.Queue'>, {})
Traceback (most recent call last):
  File "/home/kepler/Workspace/FinexMonitor/main.py", line 33, in <module>
    wss.tickers('BTCUSD')
  File "/usr/lib/python3.6/site-packages/btfxwss/client.py", line 48, in tickers
    raise KeyError(pair)
KeyError: 'BTCUSD'

from btfxwss.

deepbrook avatar deepbrook commented on August 27, 2024

I have pushed a hotfix for this (1.0.3) - could you verify this works for you?
By the way, I confused my own examples in the previous comments.
tickers doesn't subscribe anymore. You need to call subscribe_to_ticker('BTCUSD).

To elaborate on the above error:
The key error occurs because there's no data yet. It may be either because you haven't subscribed, or because the connection wasn't esablished (due to the issue you referenced with the websocket module).

from btfxwss.

deepbrook avatar deepbrook commented on August 27, 2024

Also, could you verify that this doesn't happen with the dev branch version ?

from btfxwss.

rafaelcapucho avatar rafaelcapucho commented on August 27, 2024

Thanks for your patch, I'm testing with this sample:


import logging
import sys
import time

from btfxwss import BtfxWss

apikey = '....'
apisecret = '....'

logging.basicConfig(level=logging.DEBUG, filename='test.log')
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)

wss = BtfxWss()
wss.start()
time.sleep(3)  # give the client some prep time to set itself up.

# Subscribe to some channels
wss.subscribe_to_ticker('BTCUSD')

# Do something else
t = time.time()
while time.time() - t < 10:
    pass

ticker_q = wss.tickers('BTCUSD')  # returns a Queue object for the pair.
while not ticker_q.empty():
    print(ticker_q.get())

On your master version, 1.0.3 it returns:

Traceback (most recent call last):
  File "/home/kepler/Workspace/FinexMonitor/main.py", line 32, in <module>
    wss.subscribe_to_ticker('BTCUSD')
  File "/usr/lib/python3.6/site-packages/btfxwss/client.py", line 132, in subscribe_to_ticker
    self._subscribe('ticker', identifier, symbol=pair, **kwargs)
  File "/usr/lib/python3.6/site-packages/btfxwss/client.py", line 111, in _subscribe
    self.conn.send(**q)
  File "/usr/lib/python3.6/site-packages/btfxwss/connection.py", line 235, in send
    self.conn.send(payload)
  File "/usr/lib/python3.6/site-packages/websocket/_app.py", line 120, in send
    "Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
INFO:btfxwss.connection:Connection Error - [Errno 2] No such file or directory
INFO:btfxwss.connection:Connection closed
INFO:btfxwss.connection:Attempting to connect again in 10 seconds.
DEBUG:btfxwss.client:_subscribe: {'event': 'subscribe', 'channel': 'ticker', 'symbol': 'BTCUSD'}

On Dev version:

Traceback (most recent call last):
  File "/home/kepler/Workspace/FinexMonitor/main.py", line 40, in <module>
    ticker_q = wss.tickers('BTCUSD')  # returns a Queue object for the pair.
  File "/usr/lib/python3.6/site-packages/btfxwss/client.py", line 151, in tickers
    raise KeyError(pair)
KeyError: 'BTCUSD'
INFO:btfxwss.connection:Connection Error - [Errno 2] No such file or directory
INFO:btfxwss.connection:Connection closed
INFO:btfxwss.connection:Attempting to connect again in 10 seconds.
ERROR:btfxwss.client:Cannot call subscribe_to_ticker() on unestablished connection!
INFO:btfxwss.connection:Connection Error - cafile, capath and cadata cannot be all omitted
INFO:btfxwss.connection:Connection closed
INFO:btfxwss.connection:Attempting to connect again in 10 seconds.

from btfxwss.

deepbrook avatar deepbrook commented on August 27, 2024

see if it works now (dev) - I'm now getting the default path for the certificates via the ssl module, that should take care of it. Otherwise I have to look at this in depth tomorrow.

from btfxwss.

rafaelcapucho avatar rafaelcapucho commented on August 27, 2024

Tested on dev! It seems to be working!, at least it is returning data.

$ python3 main.py

([[3252.1, 1.78920249, 3255.6, 3.35648544, 425.2, 0.1502, 3255.6, 47986.71579181, 3339.5, 2820.5]], 1501961446.8678486)
([[3255.6, 1.738, 3257.6, 3.33813918, 424.8, 0.1501, 3255.2, 48063.90211299, 3339.5, 2820.5]], 1501961446.9137855)

Thank you for your effort/time, I will now see how could I add/cancel margin funding operations with your API.

from btfxwss.

deepbrook avatar deepbrook commented on August 27, 2024

Excellent, glad to hear it's fixed!

from btfxwss.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.