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

Error "cafile, capath and cadata cannot be all omitted" #19

Closed
rafaelcapucho opened this issue Aug 5, 2017 · 8 comments
Closed

Error "cafile, capath and cadata cannot be all omitted" #19

rafaelcapucho opened this issue Aug 5, 2017 · 8 comments
Assignees
Labels

Comments

@rafaelcapucho
Copy link

When running this:

import logging
import sys
import time

from btfxwss import BtfxWss

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)

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

wss = BtfxWss(key=apikey, secret=apisecret)
wss.start()
time.sleep(2)  # give the client some prep time to set itself up.

# wss.authenticate()

# Subscribe to some channels
wss.ticker('BTCUSD')
wss.order_book('BTCUSD')

# Send a ping - if this returns silently, everything's fine.
wss.ping()

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

print(wss.tickers['BTCUSD'])
print(wss.books['BTCUSD'].bids())  # prints all current bids for the BTCUSD order book
print(wss.books['BTCUSD'].asks())  # prints all current asks for the BTCUSD order book

I got these:

/usr/bin/python3.6 /home/kepler/Workspace/FinexMonitor/main.py
Traceback (most recent call last):
  File "/home/kepler/Workspace/FinexMonitor/main.py", line 29, in <module>
    wss.ticker('BTCUSD')
AttributeError: 'BtfxWss' object has no attribute 'ticker'

Process finished with exit code 1

Log:

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.

might it be related to websocket-client/websocket-client#227 ?

Thx.

@deepbrook
Copy link
Collaborator

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!

@rafaelcapucho
Copy link
Author

rafaelcapucho commented Aug 5, 2017

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'

@deepbrook
Copy link
Collaborator

deepbrook commented Aug 5, 2017

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).

deepbrook pushed a commit that referenced this issue Aug 5, 2017
@deepbrook
Copy link
Collaborator

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

@deepbrook deepbrook self-assigned this Aug 5, 2017
@deepbrook deepbrook added the bug label Aug 5, 2017
@rafaelcapucho
Copy link
Author

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.

@deepbrook
Copy link
Collaborator

deepbrook commented Aug 5, 2017

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.

deepbrook pushed a commit that referenced this issue Aug 5, 2017
@rafaelcapucho
Copy link
Author

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.

@deepbrook
Copy link
Collaborator

Excellent, glad to hear it's fixed!

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

No branches or pull requests

2 participants