Example #1
0
        private double suggestSellPrice(MarketDepthResponse market)
        {
            const int DEC_PLACES = 14;
            double increment = Math.Pow(10.0, -1.0 * DEC_PLACES); // 0.00000000000001;

            double sum = 0;
            var highestBid = market.Bids.First().Price;

            foreach (var ask in market.Asks)
            {
                if (sum + _operativeAmount > _volumeWall && ask.Price - _minDifference > highestBid)
                {
                    double sellPrice = Math.Round(ask.Price - increment, DEC_PLACES);

                    //The difference is too small and we'd be not the first SELL order. Leave previous price to avoid server call
                    if (-1 != _sellOrderId && sellPrice > market.Asks[0].Price)
                    {
                        log($"DEBUG: SELL price {sellPrice} too similar, using previous");
                        return _sellOrderPrice;
                    }

                    return sellPrice;
                }
                sum += ask.Amount;

                //Don't consider volume of own order
                if (ask.Amount.eq(_sellOrderAmount))
                {
                    sum -= _sellOrderAmount;
                }
            }

            //Market too dry, use SELL order before last, so we see it in chart
            var price = market.Asks.Last().Price - increment;
            if (-1 != _sellOrderId)
            {
                return _sellOrderPrice;
            }

            return Math.Round(price, DEC_PLACES);
        }
Example #2
0
        private double suggestBuyPrice(MarketDepthResponse market)
        {
            const int decPlaces = 14;
            double increment = Math.Pow(10.0, -1.0 * decPlaces); // 0.00000000000001;
            double minWallVolume = _minOrderAmount / 2;

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

                if (bid.Price < _executedSellPrice - _minDifference)
                {
                    return bid.Price.eq(_buyOrderPrice, increment)
                        ? _buyOrderPrice
                        : Math.Round(bid.Price + increment, decPlaces);
                }
            }

            //All BUY orders are too high (probably some wild race). Suggest BUY order with minimum profit and hope
            return _executedSellPrice - _minDifference;
        }