<commit_before>import datetime
from currency import ExchangeRate

class Trade(object):
    '''Represents an exchange of two currency amounts. May include the 
    entities between which the trade is made'''
    def __init__(self, from_amount, to_amount, from_entity=None, to_entity=None, opening_time=None, closing_time=None, market=None):
        self.from_amount=   from_amount
        self.to_amount=     to_amount
        self.from_entity=   from_entity
        self.to_entity=     to_entity
        self.opening_time=  opening_time
        self.closing_time=  closing_time
        self.market=market

class Market(object):
    '''Represents a market - where Trade's are made'''
    def __init__(self, market_name, c1, c2):
        '''c1 is the "buy" currency'''
        self.name= market_name
        self.c1, self.c2= c1, c2
    
    def getTicker(self):
        '''returns the most recent ticker'''
        raise NotImplementedError()
    
    def getOpenTrades(self):
        '''returns a list with all the open Trade's in the market'''
        raise NotImplementedError()
    
    def getClosedTrades(self):
        '''returns all completed trades'''
        raise NotImplementedError()

class Party( Market ):
    '''Represents a party in a market'''
    def __init__(self, market):
        assert isinstance( market, Market )
        self.market= market

class PassiveParty( Party ):
    '''A party over which the user has no control'''
    pass

class ActiveParty( Party ):
    '''A party under user control'''
    def placeTrade( trade ):
        '''places a trade in the market'''
        raise NotImplementedError()
    def cancelTrade( trade ):
        raise NotImplementedError()
    class TradeAlreadyClosed( Exception ):
        '''occurs when trying to cancel a already-closed trade'''
        pass

class Ticker( object ):
    '''A ticker datapoint.'''
    TIME_PERIOD= 24*60*60   #time period (in seconds) associated with the
                            #returned results: high, low, average, 
                            #last, sell, buy, volume
    def __init__(self, market, time, high=None, low=None, average=None, last=None, sell=None, buy=None, volume=None):
        '''market: the market this ticker is associated with
        time: the time at which this ticker was retrieved. This is preferably the server time, if available.
        high, low,average,last,sell,buy: ExchangeRate.
        '''
        assert isinstance(market, Market)
        assert all( [ x is None or isinstance(x, ExchangeRate) for x in (high,low, average, last, sell, buy)] )
        assert (volume is None) or (type(volume)==long)
        assert (buy is None and sell is None) or (buy<=sell) #market invariant. The market always buys a currency cheaper than it sells it
        assert isinstance(time, datetime.datetime)
        self.market, self.time, self.volume= market, time, volume
        self.high, self.low,self.average,self.last, self.sell, self.buy= high, low, average, last, sell, buy

class NotAuthorized( Exception ):
    '''Occurs when the user is not authorized to do the requested 
    operation'''
    pass<commit_msg>concepts/market: some class renaming, etc<commit_after>import datetime
from currency import ExchangeRate

class Trade(object):
    '''Represents an exchange of two currency amounts. May include the 
    entities between which the trade is made'''
    def __init__(self, from_amount, to_amount, from_entity=None, to_entity=None, opening_time=None, closing_time=None, market=None):
        self.from_amount=   from_amount
        self.to_amount=     to_amount
        self.from_entity=   from_entity
        self.to_entity=     to_entity
        self.opening_time=  opening_time
        self.closing_time=  closing_time
        self.market=market

class Market(object):
    '''Represents a market - where Trade's are made'''
    def __init__(self, market_name, c1, c2):
        '''c1 is the "buy" currency'''
        self.name= market_name
        self.c1, self.c2= c1, c2
    
    def getTicker(self):
        '''returns the most recent ticker'''
        raise NotImplementedError()
    
    def getOpenTrades(self):
        '''returns a list with all the open Trade's in the market'''
        raise NotImplementedError()
    
    def getClosedTrades(self):
        '''returns all completed trades'''
        raise NotImplementedError()

class Participant( Market ):
    '''Represents a participant in a market (which places'''
    def __init__(self, market):
        assert isinstance( market, Market )
        self.market= market

class PassiveParticipant( Participant ):
    '''A participant over which the user has no control'''
    pass

class ActiveParticipant( Participant ):
    '''A participant under user control (may be the user itself)'''
    def placeTrade( trade ):
        '''places a trade in the market'''
        raise NotImplementedError()
    def cancelTrade( trade ):
        raise NotImplementedError()
    class TradeAlreadyClosed( Exception ):
        '''occurs when trying to cancel a already-closed trade'''
        pass
    class NotAuthorized( Exception ):
        '''Occurs when the user is not authorized to do the requested 
        operation'''
        pass

class Ticker( object ):
    '''A ticker datapoint.'''
    TIME_PERIOD= 24*60*60   #time period (in seconds) associated with the
                            #returned results: high, low, average, 
                            #last, sell, buy, volume
    def __init__(self, market, time, high=None, low=None, average=None, last=None, sell=None, buy=None, volume=None):
        '''market: the market this ticker is associated with
        time: the time at which this ticker was retrieved. This is preferably the server time, if available.
        high, low,average,last,sell,buy: ExchangeRate.
        '''
        assert isinstance(market, Market)
        assert all( [ x is None or isinstance(x, ExchangeRate) for x in (high,low, average, last, sell, buy)] )
        assert (volume is None) or (type(volume)==long)
        assert (buy is None and sell is None) or (buy<=sell) #market invariant. The market always buys a currency cheaper than it sells it
        assert isinstance(time, datetime.datetime)
        self.market, self.time, self.volume= market, time, volume
        self.high, self.low,self.average,self.last, self.sell, self.buy= high, low, average, last, sell, buy


{'fraction_non_alphanumeric': 0.09550561797752809, 'fraction_numerical': 0.004057428214731586, 'mean_word_length': 2.8608433734939758, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '748129', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1736, 'n_words': 644}