<s> from decimal import Decimal <EOL> from . util import namedtuple <EOL> SATOSHIS_IN_A_BITCOIN = Decimal ( '<STR_LIT>' . replace ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) ) <EOL> class CoinbaseAmount ( namedtuple ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) ) : <EOL> def __new__ ( cls , amount , currency ) : <EOL> return super ( CoinbaseAmount , cls ) . __new__ ( <EOL> cls , <EOL> Decimal ( amount ) , <EOL> currency , <EOL> ) <EOL> @ classmethod <EOL> def from_coinbase_dict ( cls , x ) : <EOL> if '<STR_LIT>' in x : <EOL> return CoinbaseAmount ( x [ '<STR_LIT>' ] , x [ '<STR_LIT>' ] ) <EOL> elif '<STR_LIT>' in x : <EOL> currency = x [ '<STR_LIT>' ] <EOL> amount = x [ '<STR_LIT>' ] / ( SATOSHIS_IN_A_BITCOIN if currency == '<STR_LIT>' <EOL> else Decimal ( '<STR_LIT:100>' ) ) <EOL> return CoinbaseAmount ( amount , currency ) <EOL> else : <EOL> raise Exception <EOL> def to_coinbase_dict ( self ) : <EOL> return { <EOL> '<STR_LIT>' : str ( self . amount ) , <EOL> '<STR_LIT>' : self . currency , <EOL> } <EOL> def convert ( self , currency , exchange_rate ) : <EOL> return CoinbaseAmount ( self . amount * exchange_rate , currency ) <EOL> class BtcAndNative ( namedtuple ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> @ classmethod <EOL> def from_coinbase_dict ( cls , x , prefix ) : <EOL> btc_key = prefix + '<STR_LIT>' <EOL> native_key = prefix + '<STR_LIT>' <EOL> if btc_key not in x : <EOL> return None <EOL> return CoinbaseAmount . BtcAndNative ( <EOL> btc = CoinbaseAmount . from_coinbase_dict ( x [ btc_key ] ) , <EOL> native = CoinbaseAmount . from_coinbase_dict ( x [ native_key ] ) <EOL> ) </s>
