Bitcoin Forum
November 07, 2024, 03:53:50 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: MtGox websocket API: I get ticker and depth messages, but no trade or lag  (Read 4646 times)
pescador (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0



View Profile
April 20, 2013, 04:26:30 PM
 #1

I'm experimenting with the MtGox websocket API. This API is documented here https://en.bitcoin.it/wiki/MtGox/API/Streaming and discussed here https://bitcointalk.org/index.php?topic=5855.msg86219#msg86219. However since I'm a newbie I can't post my question there, so I have to ask it here. I'm using Python with the websocket module from https://pypi.python.org/pypi/websocket-client. See example code below

Code:
import threading
import websocket
import json

class mtgox( threading.Thread ):

    def run( self ):
        websocket.enableTrace( True )
        url = 'ws://websocket.mtgox.com/mtgox?Currency=USD'
        self.socket = websocket.WebSocketApp( url, on_open = self.on_open )
        self.socket.run_forever( )

    def subscribe( self, channel ):
        output = { 'op': 'mtgox.subscribe', 'type': channel }
        output = json.dumps( output )
        self.socket.send( output )

    def on_open( self, socket ):
        self.subscribe( 'depth' )
        self.subscribe( 'lag' )        
        self.subscribe( 'ticker' )
        self.subscribe( 'trades' )

if __name__ == '__main__':
    mtgox = mtgox( )
    mtgox.start( )

When I run this code I receive ticker and depth messages, but no lag or trade messages. Also I do not get any replies to my mtgox.subscribe commands, that the documentation seems to promise. However when I send a mtgox.subscribe command with a wrong type parameter, I get an error message "Unknown mtgox message type", so it seems my subscribe commands are received and accepted.

Could somebody please tell me why I'm not receiving trade and lag messages?
Webengers
Newbie
*
Offline Offline

Activity: 42
Merit: 0


View Profile
April 23, 2013, 07:07:26 AM
 #2

I've been experiencing the same thing from the websocket. A stream of Ticker messages, and occasional depth message and I haven't seen a trade message yet.
I'd really like to figure this out!
pescador (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0



View Profile
April 27, 2013, 08:53:33 AM
 #3

It seems to be working now. Now I also get trade and lag messages. Apparently it was something at MtGox's side.
RomanKnight
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
April 30, 2013, 02:25:20 AM
 #4

Hello I am trying to do the same thing you are and yet when I run the code I made I get.

-----------------------
--- response header ---
HTTP/1.1 400 Bad Request
-----------------------
Handshake Status 400
### closed ###

This is very frustrating would you happen to know what I am doing wrong?
ralphtheninja
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
May 02, 2013, 01:37:06 AM
 #5

Same here and using the same python code. Bad request 400. What's going on?
pescador (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 0



View Profile
May 02, 2013, 07:10:50 PM
 #6

Try changing ws into wss.
milkyman
Newbie
*
Offline Offline

Activity: 30
Merit: 0


View Profile
January 05, 2014, 12:47:19 PM
 #7

I'm not sure whether anyone is still reading here, but I'll give it a try. I ran the above code in python 2.7.6 - using wss instead of ws - and get the following response:

Code:
--- request header ---
GET /mtgox?Currency=USD HTTP/1.1

Upgrade: websocket

Connection: Upgrade

Host: websocket.mtgox.com:443

Origin: http://websocket.mtgox.com:443

Sec-WebSocket-Key: 81DMJF11Qdm5wmo2mtVKjw==

Sec-WebSocket-Version: 13




-----------------------
--- response header ---
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: pu7sv8PRAVRv/5VknsU2qMvbfhI=
-----------------------
send: '\x81\xaa\xc6\x00\x86\xa9\xbd"\xf2\xd0\xb6e\xa4\x93\xe6"\xe2\xcc\xb6t\xee\x8b\xea \xa4\xc6\xb6"\xbc\x89\xe4m\xf2\xce\xa9x\xa8\xda\xb3b\xf5\xca\xb4i\xe4\xcc\xe4}'
send: '\x81\xa8\x91\xbf\xdc\xc1\xea\x9d\xa8\xb8\xe1\xda\xfe\xfb\xb1\x9d\xb0\xa0\xf6\x9d\xf0\xe1\xb3\xd0\xac\xe3\xab\x9f\xfe\xac\xe5\xd8\xb3\xb9\xbf\xcc\xa9\xa3\xe2\xdc\xae\xa8\xf3\xda\xfe\xbc'
send: "\x81\xab\x05\xc5!#~\xe7UZu\xa0\x03\x19%\xe7UJf\xaeDQ'\xe9\x01\x01j\xb5\x03\x19%\xe7LWb\xaaY\rv\xb0CPf\xb7HA`\xe7\\"
send: '\x81\xab\x9ddq\xaa\xe6F\x05\xd3\xed\x01S\x90\xbdF\x05\xd8\xfc\x00\x14\xd9\xbfHQ\x88\xf2\x14S\x90\xbdF\x1c\xde\xfa\x0b\t\x84\xee\x11\x13\xd9\xfe\x16\x18\xc8\xf8F\x0c'

Does anyone know whether this is what I should get? How do I interpret this response? How do I get the ticker / depth / etc. updates?
Thanks
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!