<s> from dateutil import parser as date_parse <EOL> from time import sleep <EOL> from OpenSSL . SSL import SysCallError <EOL> import pandas as pd <EOL> from requests . packages . urllib3 . exceptions import ProtocolError <EOL> from . . lib . oandapy import OandaError <EOL> class OandaBrokerBase ( object ) : <EOL> default_history_dataframe_columns = ( <EOL> '<STR_LIT:time>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> def __init__ ( self , api ) : <EOL> self . _api = api <EOL> self . _tick = None <EOL> def get_instrument_detail ( self , instrument ) : <EOL> params = { '<STR_LIT>' : instrument } <EOL> ret = self . _api . get_instruments ( self . _account_id , ** params ) <EOL> return ret <EOL> def set_current_tick ( self , tick ) : <EOL> self . _tick = tick <EOL> def get_history ( self , * args , ** kwargs ) : <EOL> columns = kwargs . pop ( '<STR_LIT>' , self . default_history_dataframe_columns ) <EOL> include_current = kwargs . pop ( '<STR_LIT>' , False ) <EOL> if '<STR_LIT:time>' not in columns : <EOL> columns = ( '<STR_LIT:time>' , ) + tuple ( columns ) <EOL> while True : <EOL> try : <EOL> response = None <EOL> response = self . _api . get_history ( * args , ** kwargs ) <EOL> if response and response . get ( '<STR_LIT>' ) : <EOL> df = pd . DataFrame ( <EOL> data = response [ '<STR_LIT>' ] , <EOL> columns = columns , <EOL> ) <EOL> df [ '<STR_LIT:time>' ] = df [ '<STR_LIT:time>' ] . map ( date_parse . parse ) <EOL> df [ '<STR_LIT>' ] = df [ [ '<STR_LIT>' , '<STR_LIT>' ] ] . mean ( axis = <NUM_LIT:1> ) <EOL> if not include_current : <EOL> df = df [ df . complete == True ] <EOL> return df <EOL> else : <EOL> return pd . DataFrame ( ) <EOL> except ( ValueError ) as e : <EOL> print "<STR_LIT>" . format ( kwargs [ '<STR_LIT>' ] , e ) <EOL> return pd . DataFrame ( ) <EOL> except ( ProtocolError , OandaError , SysCallError ) as e : <EOL> print "<STR_LIT>" . format ( e ) <EOL> sleep ( <NUM_LIT:3> ) <EOL> def get_price ( self , instrument ) : <EOL> raise NotImplementedError ( ) <EOL> def open_order ( self , instrument , units , side , order_type , <EOL> price = None , expiry = None , stop_loss = None , take_profit = None ) : <EOL> raise NotImplementedError ( ) <EOL> def sync_transactions ( self , position ) : <EOL> raise NotImplementedError ( ) <EOL> def delete_pending_order ( self , position ) : <EOL> raise NotImplementedError ( ) <EOL> def close_trade ( self , position ) : <EOL> raise NotImplementedError ( ) </s>
