#NEWLINE# def get_matching_orders( input_order ) : #NEWLINE# #INDENT# search_criteria_rate = { #NEWLINE# #INDENT# 'currency' : input_order [ 'currency' ] , #NEWLINE# #UNINDENT# } #NEWLINE# search_criteria_rate [ 'action' ] = ( 'Buy' if ( input_order [ 'action' ] == 'Sell' ) else 'Sell' ) #NEWLINE# search_criteria_rate [ 'is_complete' ] = 0 #NEWLINE# search_criteria_market = copy . deepcopy ( search_criteria_rate ) #NEWLINE# search_criteria_rate [ 'order_type' ] = 'For Price' #NEWLINE# search_criteria_market [ 'order_type' ] = 'At Market' #NEWLINE# query_market = True #NEWLINE# quote = c . get ( 'currencies' , input_order [ 'currency' ] ) #NEWLINE# rate = input_order [ 'rate' ] #NEWLINE# is_sell = ( input_order [ 'action' ] == 'Sell' ) #NEWLINE# is_rate = ( input_order [ 'order_type' ] == 'For Price' ) #NEWLINE# if ( ( not is_rate ) and ( quote [ 'last_trade' ] == ( - 1 ) ) ) : #NEWLINE# #INDENT# query_market = False #NEWLINE# #UNINDENT# if is_rate : #NEWLINE# #INDENT# search_criteria_rate [ 'rate' ] = ( GreaterEqual ( rate ) if is_sell else LessEqual ( rate ) ) #NEWLINE# if ( is_sell and ( rate > quote [ 'lowest_sell_rate' ] ) ) : #NEWLINE# #INDENT# query_market = False #NEWLINE# #UNINDENT# if ( ( not is_sell ) and ( rate < quote [ 'highest_buy_rate' ] ) ) : #NEWLINE# #INDENT# query_market = False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# query_market = False #NEWLINE# #UNINDENT# market_orders_itr = ( c . search ( 'orders' , search_criteria_market ) if query_market else None ) #NEWLINE# rate_orders_itr = c . search ( 'orders' , search_criteria_rate ) #NEWLINE# market_orders = ( [ dict ( row ) for row in market_orders_itr ] if ( market_orders_itr is not None ) else [ ] ) #NEWLINE# rate_orders = [ dict ( row ) for row in rate_orders_itr ] #NEWLINE# return ( rate_orders , market_orders , quote )