Ok so I am working on a application that displays a recent self updating orderbook of the first 20 or so (not decided) bids and asks. I am doing this for fun and as a learning experience i know it would be easily accessible through clark moody and the sort. The question is, its easy to get the full depth by using
http://data.mtgox.com/api/2/BTCUSD/money/depth. However ive been looking around and most people say to get it to update you should use the websocket API. I am not familiar with this type of programming (my programming knowledge is quite limited anyways) and i've found this script which gives me the output of the websocket, however I would like this output to be appended into an array and i cant get that to happen. So the question is how can i handle or define a variable which consitutes the output of the websocket api at mtgox.
THIS HAS BEEN ANSWERED THANKS ANYWAYS!
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( )