Search code examples
pythoncryptocurrency

How can I use Cryptofeed python library on mac


I'm tried to use cryptofeed python library on mac Mojave 10.14. https://github.com/bmoscon/cryptofeed

Following code working well on windows.

from cryptofeed.callback import  BookCallback
from cryptofeed import FeedHandler
from cryptofeed.exchanges import Bitmex
from cryptofeed.defines import  L2_BOOK, BID, ASK
import os, curses
rows=5
async def bitmex_book(feed, pair, book, timestamp):
    Max_book=len(book[BID])-1    
    fmt2="{:11.2f}"  
    stdscr = curses.initscr() 
    stdscr.addstr(0,0,'                        BITMEX                 ')
    stdscr.addstr(1,0,"   [ QTY ]   |   [ BID ]   |   [ ASK ]   |   [ QTY ]   ")
    stdscr.addstr(2,1,'-------------+-------------+-------------+-------------')
    for i in range(rows):
        stdscr.addstr(i+3,1,
                      fmt2.format(book[BID].items()[Max_book-i][1])+' | '+\
                      fmt2.format(book[BID].items()[Max_book-i][0])+' | '+\
                      fmt2.format(book[ASK].items()[i][0])+' | '+\
                      fmt2.format(book[ASK].items()[i][1]))
    stdscr.refresh()
def main(): 
    os.system('mode con: cols=60 lines='+str(rows+5)) 
    print("Hello bitmex ...") 

    f1 = FeedHandler()
    f1.add_feed(Bitmex(pairs=['XBTUSD'], channels=[L2_BOOK], callbacks={L2_BOOK: BookCallback(bitmex_book)}))
    f1.run()
if __name__ == '__main__':
    main()
    curses.endwin() #Clo+se screen

But on mac, got following error.

2019-12-14 01:46:38,042 : WARNING : BITMEX: encountered connection issue [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076) - reconnecting...
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cryptofeed/feedhandler.py", line 189, in _connect
async with websockets.connect(feed.address, ping_interval=30, ping_timeout=None, max_size=2**23) as websocket:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websockets/client.py", line 517, in aenter
return await self
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/websockets/client.py", line 535, in await_impl
transport, protocol = await self._create_connection()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 981, in create_connection
ssl_handshake_timeout=ssl_handshake_timeout)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 1009, in _create_connection_transport
await waiter
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/sslproto.py", line 530, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/sslproto.py", line 189, in feed_ssldata
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 774, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)

Please help me.

Windows working result is following.

enter image description here


Solution

  • Please us "Install Certificates.command" of python. enter image description here

    Please refer following url.

    certificate verify failed: unable to get local issuer certificate