예제 #1
0
        private double suggestSellPrice(MarketDepth market)
        {
            double sum = 0;
            var minDiff = _volumeWall * PRICE_DELTA;
            var highestBid = market.XXBTZEUR.Bids.First().Price;

            foreach (var ask in market.XXBTZEUR.Asks)
            {
                if (sum + _operativeAmount > _volumeWall && ask.Price - MIN_DIFFERENCE > highestBid)
                {
                    double sellPrice = Math.Round(ask.Price - 0.001, 3);

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

                    return sellPrice;
                }
                sum += ask.Amount;

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

            //Market too dry, use SELL order before last, so we see it in chart
            var price = market.XXBTZEUR.Asks.Last().Price - 0.001;
            if (null != _sellOrderId && Math.Abs(price - _sellOrderPrice) < minDiff)
                return _sellOrderPrice;
            return Math.Round(price, 3);
        }
예제 #2
0
        private double suggestBuyPrice(MarketDepth market)
        {
            const double MIN_WALL_VOLUME = 0.1;

            double sumVolume = 0.0;
            foreach (var bid in market.XXBTZEUR.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;
        }