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
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?