Bitcoin-central socket.io

262 views
Skip to first unread message

workin...@gmail.com

unread,
Oct 23, 2013, 5:41:20 AM10/23/13
to gevent-...@googlegroups.com
Hello,

I would like to get live bitcoin price from this exchange https://bitcoin-central.net/
According to Chrome Web developer tools there is a socket.io server which send push message

(1382520738096 is a unix timestamp)

but it also seems to work with https://bitcoin-central.net/ws/socket.io/1/

Server send a reply like y6qC0Ujanb8KJIqPareh:60:60:websocket,htmlfile,xhr-polling,jsonp-polling


I would like to try to subscribe to messages from this channel... unfortunately I still have no experience with both
websocket and socket.io.
I have some good Python skills, I also know patterns such as publish/subscribe (signal/slot).

Any help is welcome

Kind regards

WFC 

workin...@gmail.com

unread,
Oct 23, 2013, 5:51:06 AM10/23/13
to gevent-...@googlegroups.com
See as attachment code

I get this error message

$ python feed_bc_socketio.py
[[u'vvXsGRNc0clTACmwarfW', u'60', u'60', u'websocket'], u'htmlfile', u'xhr-polling', u'jsonp-polling']
vvXsGRNc0clTACmwarfW
Traceback (most recent call last):
  File "feed_bc_socketio.py", line 40, in <module>
    main()
  File "feed_bc_socketio.py", line 31, in main
    socketIO = SocketIO(url_socketio, 80)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/socketIO_client/__init__.py", line 98, in __init__
    self._socketIO = _SocketIO(host, port, secure, headers, proxies)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/socketIO_client/__init__.py", line 305, in __init__
    proxies=proxies)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/requests/sessions.py", line 323, in request
    prep = self.prepare_request(req)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/requests/sessions.py", line 264, in prepare_request
    hooks=merge_setting(request.hooks, self.hooks),
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/requests/models.py", line 280, in prepare
    self.prepare_url(url, params)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/requests/models.py", line 321, in prepare_url
    scheme, auth, host, port, path, query, fragment = parse_url(url)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/requests/packages/urllib3/util.py", line 390, in parse_url
    raise LocationParseError("Failed to parse: %s" % url)
requests.packages.urllib3.exceptions.LocationParseError: Failed to parse: Failed to parse: wss:
Exception AttributeError: "'_SocketIO' object has no attribute 'connection'" in <bound method _SocketIO.__del__ of <socketIO_client._SocketIO object at 0x101242a50>> ignored
Exception AttributeError: "'SocketIO' object has no attribute '_socketIO'" in <bound method SocketIO.__del__ of <socketIO_client.SocketIO object at 0x101242c10>> ignored
feed_bc_socketio.py

Alexandre Bourget

unread,
Oct 23, 2013, 9:26:28 AM10/23/13
to gevent-...@googlegroups.com
This is the handshake. It expects you to follow up with the rest of the protocol.


btw, take a look at bitcredits.io which I founded :)

Alexandre


--
You received this message because you are subscribed to the Google Groups "gevent-socketio" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gevent-socket...@googlegroups.com.
To post to this group, send email to gevent-...@googlegroups.com.
Visit this group at http://groups.google.com/group/gevent-socketio.
For more options, visit https://groups.google.com/groups/opt_out.

workin...@gmail.com

unread,
Oct 23, 2013, 10:59:52 AM10/23/13
to gevent-...@googlegroups.com, al...@bourget.cc
Thanks handshake was the word... but it doesn't solve my issue ;-)

I also try this code

HOSTNAME = "bitcoin-central.net"
PORT = 80


def handshake(host, port):
    url = "http://%s:%d/ws/socket.io/1/" % (host, port)
    print(url)
    u = urlopen(url)
    if u.getcode() == 200:
        response = u.readline()
        (sid, hbtimeout, ctimeout, supported) = response.split(":")
        supportedlist = supported.split(",")
        if "websocket" in supportedlist:
            return (sid, hbtimeout, ctimeout)
        else:
            raise TransportException()
    else:
        raise InvalidResponseException()

def main():
    print("ok")
    try:
        print("ok2")
        (sid, hbtimeout, ctimeout) = handshake(HOSTNAME, PORT) #handshaking according to socket.io spec.
    except Exception as e:
        print e
        sys.exit(1)
    url_ws = "wss://%s:%d/ws/socket.io/1/websocket/%s" % (HOSTNAME, PORT, sid)
    print(url_ws)
    ws = websocket.create_connection(url_ws)
    print ws.recv()
    ws.send("2::")
    ws.send("5:1::{'name':'newimg', 'args':'bla'}")
    print ws.recv()
    print "Closing connection"
    ws.close()
    
if __name__ == "__main__":
    main()


but I get 

$ python feed_bc_socketio.py
ok
ok2
Traceback (most recent call last):
  File "feed_bc_socketio.py", line 82, in <module>
    main()
  File "feed_bc_socketio.py", line 73, in main
    ws = websocket.create_connection(url_ws)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/websocket.py", line 201, in create_connection
    websock.connect(url, **options)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/websocket.py", line 451, in connect
    self.sock = ssl.wrap_socket(self.sock, **sslopt)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/ssl.py", line 381, in wrap_socket
    ciphers=ciphers)
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/ssl.py", line 143, in __init__
    self.do_handshake()
  File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/ssl.py", line 305, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [Errno 1] _ssl.c:504: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

About bitcredits....
I follow you on Twitter
I stay tuned...

Alexandre Bourget

unread,
Oct 23, 2013, 11:02:24 AM10/23/13
to gevent-...@googlegroups.com
Have you tried:



??

Alexandre

workin...@gmail.com

unread,
Oct 23, 2013, 11:06:17 AM10/23/13
to gevent-...@googlegroups.com, al...@bourget.cc
I didn't manage to use it...

but I'm going forward...

wss is secured... so port is 443 but it's 80 for handshake

now this is what I get

$ python feed_bc_socketio.py
ok
ok2

How can I get tickers (price) ?

I probably need to reverse engineered their webpage...

Any idea ?
Reply all
Reply to author
Forward
0 new messages