contract TradingVolume is CompanyConstants {
    
    struct Traders {
        uint relaseTime;
        address winningTrader;
        mapping (address => uint) sharesTraded;
    }
    
    mapping (uint => Traders) companyIdToTraders;
    
    // unique _companyId
    function _addNewCompanyTraders(uint _companyId) 
    internal {
        Traders memory traders = Traders({
            winningTrader : 0x0,
            relaseTime : now + TRADING_COMPETITION_PERIOD 
        });
        
        companyIdToTraders[_companyId] = traders;
    }
    
    // _from!=_to , _amount > 0
    function _updateTradingVolume(Traders storage _traders, address _from, address _to, uint _amount) 
    internal {
        _traders.sharesTraded[_from] += _amount;
        _traders.sharesTraded[_to] += _amount;
        
        if (_traders.sharesTraded[_from] > _traders.sharesTraded[_traders.winningTrader]) {
            _traders.winningTrader = _from;
        } 
        
        if (_traders.sharesTraded[_to] > _traders.sharesTraded[_traders.winningTrader]) {
            _traders.winningTrader = _to;
        } 
    }
    
    // Get reference of winningTrader before clearing
    function _clearWinner(Traders storage _traders) 
    internal {
        delete _traders.sharesTraded[_traders.winningTrader];
        delete _traders.winningTrader;
        _traders.relaseTime = now + TRADING_COMPETITION_PERIOD;
    }
}
function _updateTradingVolume(Traders storage _traders, address _from, address _to, uint _amount) 
internal {
    _traders.sharesTraded[_from] += _amount;
    _traders.sharesTraded[_to] += _amount;
        
    if (_traders.sharesTraded[_from] > _traders.sharesTraded[_traders.winningTrader]) {
        _traders.winningTrader = _from;
    } 
        
    if (_traders.sharesTraded[_to] > _traders.sharesTraded[_traders.winningTrader]) {
        _traders.winningTrader = _to;
    } 
}

// _from!=_to , _amount > 0