/// <summary>	Calculates the market prices and limits. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="market">				[in,out] The market. </param>
        /// <param name="bitsharesBalances">	The bitshares balances. </param>
        /// <param name="bitcoinBalance">       The bitcoin balance. </param>
        public override void ComputeMarketPricesAndLimits(ref MarketRow market,
                                                          Dictionary <int, ulong> bitsharesBalances,
                                                          decimal bitcoinBalance)
        {
            base.ComputeMarketPricesAndLimits(ref market, bitsharesBalances, bitcoinBalance);

            decimal baseBalance  = 0;
            decimal quoteBalance = bitcoinBalance;

            if (bitsharesBalances.ContainsKey(m_asset.id))
            {
                // only non zero balances return data, so this guard is necessary
                baseBalance = m_asset.GetAmountFromLarimers(bitsharesBalances[m_asset.id]);
            }

            decimal maxTransactionFactor;

            if (m_currency.uia)
            {
                // with UIA we got to handle the maximum buy size differently
                BitsharesAccount account = m_bitshares.WalletGetAccount(m_bitsharesAccount);
                if (m_asset.issuer_id == account.id)
                {
                    // we are the issuer!

                    // refresh the asset
                    m_asset = m_bitshares.BlockchainGetAsset(m_asset.symbol);

                    // this is how much we can issue, so lets stick that in there
                    baseBalance = m_asset.GetAmountFromLarimers(m_asset.max_supply - m_asset.current_supply);
                }
                else
                {
                    throw new UnexpectedCaseException();
                }

                maxTransactionFactor = 1;
                //maxTransactionFactor = kMaxTransactionFactor;
            }
            else
            {
                maxTransactionFactor = kMaxTransactionFactor;
            }

            decimal newAskMax, newBidMax;

            // askMax is in BITCOINS
            // bidMax is in BITASSETS

            if (m_flipped)
            {
                // BTC_bitUSD

                // baseBalance = 10 bitUSD
                // ask = 240
                // askMax = 10 / 240 = 0.04 BTC

                newAskMax = Numeric.TruncateDecimal((baseBalance / m_market.ask) * maxTransactionFactor, 8);
                newBidMax = Numeric.TruncateDecimal((quoteBalance * m_market.bid) * maxTransactionFactor, 8);
            }
            else
            {
                // BTS_BTC
                //
                // baseBalance = 1 BTS
                // ask = 0.00004
                // askMax = 1 * 0.0004 = 0.0004 BTC

                newAskMax = Numeric.TruncateDecimal((baseBalance * m_market.ask) * maxTransactionFactor, 8);
                newBidMax = Numeric.TruncateDecimal((quoteBalance / m_market.bid) * maxTransactionFactor, 8);
            }

            m_isDirty |= newAskMax != m_market.ask_max || newBidMax != m_market.bid_max;

            market.ask_max = newAskMax;
            market.bid_max = newBidMax;

            if (m_market.price_discovery)
            {
                //
                // update price discovery engine
                //

                decimal bitsharesBalance = m_asset.GetAmountFromLarimers(bitsharesBalances[m_asset.id]);

                if (m_asset.symbol == CurrencyHelpers.kBtcSymbol)
                {
                    m_lastFeedPrice = 1;
                }
                else
                {
                    m_lastFeedPrice = RecomputeFeedPriceInBtc();
                }

                decimal inventoryRatio = ComputeInventoryRatio(bitsharesBalances, bitcoinBalance);

                if (m_prices == null)
                {
                    //
                    // initialise the price discovery engine
                    //

                    m_prices = new PriceDiscovery(market.spread_percent, market.window_percent, m_lastFeedPrice, inventoryRatio);
                }

                decimal oldBid = m_market.bid;
                decimal oldAsk = m_market.ask;
                m_prices.UpdateParameters(m_lastFeedPrice, inventoryRatio, m_market.spread_percent, m_market.window_percent, out m_market.bid, out m_market.ask);

                m_isDirty |= oldBid != m_market.bid || oldAsk != m_market.ask;
            }
        }