<s> import urllib . request <EOL> import urllib . error <EOL> import urllib . parse <EOL> import json <EOL> from . market import Market <EOL> class BtceUSD ( Market ) : <EOL> def __init__ ( self ) : <EOL> super ( BtceUSD , self ) . __init__ ( "<STR_LIT>" ) <EOL> self . update_rate = <NUM_LIT> <EOL> def update_depth ( self ) : <EOL> url = '<STR_LIT>' <EOL> req = urllib . request . Request ( url , None , headers = { <EOL> "<STR_LIT:Content-Type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } ) <EOL> res = urllib . request . urlopen ( req ) <EOL> depth = json . loads ( res . read ( ) . decode ( '<STR_LIT:utf8>' ) ) <EOL> self . depth = self . format_depth ( depth ) <EOL> def sort_and_format ( self , l , reverse = False ) : <EOL> l . sort ( key = lambda x : float ( x [ <NUM_LIT:0> ] ) , reverse = reverse ) <EOL> r = [ ] <EOL> for i in l : <EOL> r . append ( { '<STR_LIT>' : float ( i [ <NUM_LIT:0> ] ) , '<STR_LIT>' : float ( i [ <NUM_LIT:1> ] ) } ) <EOL> return r <EOL> def format_depth ( self , depth ) : <EOL> bids = self . sort_and_format ( depth [ '<STR_LIT>' ] , True ) <EOL> asks = self . sort_and_format ( depth [ '<STR_LIT>' ] , False ) <EOL> return { '<STR_LIT>' : asks , '<STR_LIT>' : bids } <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> market = BtceUSD ( ) <EOL> print ( market . get_ticker ( ) ) </s>
