Example #1
0
        protected virtual double SuggestSellPrice(IMarketDepthResponse<Order> market)
        {
            const double MIN_WALL_VOLUME = 0.1;

            double sumVolume = 0.0;
            foreach (var ask in market.Asks)
            {
                //Don't count self
                if (ask.Price.eq(_sellOrderPrice) && ask.Amount.eq(_sellOrderAmount))
                {
                    continue;
                }
                //Skip SELL orders with tiny amount
                sumVolume += ask.Amount;
                if (sumVolume < MIN_WALL_VOLUME)
                {
                    continue;
                }

                if (ask.Price > _executedBuyPrice + _minDifference)
                {
                    return ask.Price.eq(_sellOrderPrice)
                        ? _sellOrderPrice
                        : ask.Price - 0.001;
                }
            }

            //All SELL orders are too low (probably some terrible fall). Suggest SELL order with minimum profit and hope :-( TODO: maybe some stop-loss strategy
            return _executedBuyPrice + _minDifference;
        }
Example #2
0
        //TODO: Clear candidate for movement to parent class
        protected virtual double SuggestBuyPrice(IMarketDepthResponse<Order> market)
        {
            const double MIN_WALL_VOLUME = 0.1;

            double sumVolume = 0.0;
            foreach (var bid in market.Bids)
            {
                //Don't count self
                if (bid.Price.eq(_buyOrderPrice) && bid.Amount.eq(_buyOrderAmount))
                {
                    continue;
                }
                //Skip BUY orders with tiny amount
                sumVolume += bid.Amount;
                if (sumVolume < MIN_WALL_VOLUME)
                {
                    continue;
                }

                if (bid.Price < _executedSellPrice - MIN_DIFFERENCE)
                {
                    return bid.Price.eq(_buyOrderPrice)
                        ? _buyOrderPrice
                        : bid.Price + 0.001;
                }
            }

            //All BUY orders are too high (probably some wild race). Suggest BUY order with minimum profit and hope
            return _executedSellPrice - MIN_DIFFERENCE;
        }
Example #3
0
        //TODO: To TraderBase
        protected virtual double SuggestBuyPrice(IMarketDepthResponse<Order> market)
        {
            double sum = 0;
            var lowestAsk = market.Asks.First().Price;

            foreach (var bid in market.Bids)
            {
                if (sum + _operativeAmount > _volumeWall && bid.Price + _minDifference < lowestAsk)
                {
                    double buyPrice = Math.Round(bid.Price + 0.001, 3);

                    //The difference is too small and we'd be not first in BUY orders. Leave previous price to avoid server call
                    if (-1 != _buyOrderId && buyPrice < market.Bids[0].Price && Math.Abs(buyPrice - _buyOrderPrice) < _minPriceUpdate)
                    {
                        log(String.Format("DEBUG: BUY price {0} too similar, using previous", buyPrice));
                        return _buyOrderPrice;
                    }

                    return buyPrice;
                }
                sum += bid.Amount;

                //Don't consider volume of own order
                if (bid.Price.eq(_buyOrderPrice))
                {
                    sum -= _buyOrderAmount;
                }
            }

            //Market too dry, use BUY order before last, so we see it in chart
            var price = market.Bids.Last().Price + 0.01;
            if (-1 != _buyOrderId && Math.Abs(price - _buyOrderPrice) < _minPriceUpdate)
            {
                return _buyOrderPrice;
            }
            return Math.Round(price, 3);
        }
Example #4
0
        protected virtual double SuggestSellPrice(IMarketDepthResponse<MarketOrder> market)
        {
            foreach (var ask in market.Asks)
            {
                //Don't count self
                if (ask.Price.eq(_sellOrderPrice) && ask.Amount.eq(_sellOrderAmount))
                {
                    continue;
                }

                if (ask.Price > _executedBuyPrice + _minDifference)
                {
                    return ask.Price.eq(_sellOrderPrice)
                        ? _sellOrderPrice
                        : ask.Price - _minPriceUpdate;
                }
            }

            //All SELL orders are too low (probably some terrible fall). Suggest SELL order with minimum profit and hope :-( TODO: maybe some stop-loss strategy
            return _executedBuyPrice + _minDifference;
        }