Bitcoin Forum
July 09, 2024, 04:49:40 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Mt Gox Websocket Streaming API and Depth Question[PYTHON][ANSWERED]  (Read 887 times)
bitkapp (OP)
Hero Member
*****
Offline Offline

Activity: 517
Merit: 500


aka alaniz


View Profile
July 10, 2013, 03:01:04 PM
Last edit: July 11, 2013, 10:39:12 AM by bitkapp
 #1

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!

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( )

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!