@@ -291,7 +291,9 @@ ws.subscribe_to_ticker_update(tickers)
291291ws.disconnect()
292292```
293293
294- Let's get some 'practical' examples. Check examples folder.
294+ Let's get some 'practical' examples.
295+
296+ Note that with library updates, the methods and data structure might change, so check the examples folder for the most up to date examples.
295297#### Record trades
296298``` python
297299from __future__ import print_function
@@ -313,21 +315,24 @@ def main():
313315 # Ping
314316 print (' [Trades]: {} ' .format(msg[' ticker' ]))
315317
318+ # Create the socket instance
316319 ws = MySocket()
320+ # Enable logging
321+ ws.enable_log()
322+ # Define tickers
317323 tickers = [' BTC-ETH' , ' BTC-XMR' ]
324+ # Subscribe to trade fills
318325 ws.subscribe_to_trades(tickers)
319326
320327 while len (set (tickers) - set (ws.trade_history)) > 0 :
321328 sleep(1 )
322- continue
323329 else :
324330 for ticker in ws.trade_history.keys():
325331 print (' Printing {} trade history.' .format(ticker))
326332 for trade in ws.trade_history[ticker]:
327333 print (trade)
328334 ws.disconnect()
329335
330-
331336if __name__ == " __main__" :
332337 main()
333338```
@@ -338,13 +343,19 @@ from __future__ import print_function
338343from time import sleep
339344from bittrex_websocket.websocket_client import BittrexSocket
340345
346+
341347def main ():
342348 class MySocket (BittrexSocket ):
343349 def on_orderbook (self , msg ):
344350 print (' [OrderBook]: {} ' .format(msg[' MarketName' ]))
345351
352+ # Create the socket instance
346353 ws = MySocket()
354+ # Enable logging
355+ ws.enable_log()
356+ # Define tickers
347357 tickers = [' BTC-ETH' , ' BTC-NEO' , ' BTC-ZEC' , ' ETH-NEO' , ' ETH-ZEC' ]
358+ # Subscribe to live order book
348359 ws.subscribe_to_orderbook(tickers)
349360
350361 while True :
@@ -366,6 +377,41 @@ def main():
366377 else :
367378 sleep(1 )
368379
380+ if __name__ == " __main__" :
381+ main()
382+ ```
383+ #### Ticker general information update
384+ ``` python
385+ from __future__ import print_function
386+ from time import sleep
387+ from bittrex_websocket.websocket_client import BittrexSocket
388+
389+
390+ def main ():
391+ class MySocket (BittrexSocket ):
392+ def on_open (self ):
393+ self .ticker_updates_container = {}
394+
395+ def on_ticker_update (self , msg ):
396+ name = msg[' MarketName' ]
397+ if name not in self .ticker_updates_container:
398+ self .ticker_updates_container[name] = msg
399+ print (' Just received ticker update for {} .' .format(name))
400+
401+ # Create the socket instance
402+ ws = MySocket()
403+ # Enable logging
404+ ws.enable_log()
405+ # Define tickers
406+ tickers = [' BTC-ETH' , ' BTC-NEO' , ' BTC-ZEC' , ' ETH-NEO' , ' ETH-ZEC' ]
407+ # Subscribe to ticker information
408+ ws.subscribe_to_ticker_update(tickers)
409+
410+ while len (ws.ticker_updates_container) < len (tickers):
411+ sleep(1 )
412+ else :
413+ print (' We have received updates for all tickers. Closing...' )
414+ ws.disconnect()
369415
370416if __name__ == " __main__" :
371417 main()
0 commit comments