예제 #1
0
        private double suggestSellPrice(MarketDepthResponse market)
        {
            double sum = 0;
            var highestBid = market.bids.First().Price;

            foreach (var ask in market.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 (-1 != _sellOrderId && sellPrice > market.asks[0].Price && Math.Abs(sellPrice - _sellOrderPrice) < MIN_PRICE_DELTA)
                    {
                        log(String.Format("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.asks.Last().Price - 0.001;
            if (-1 != _sellOrderId && Math.Abs(price - _sellOrderPrice) < MIN_PRICE_DELTA)
            {
                return _sellOrderPrice;
            }
            return Math.Round(price, 3);
        }
예제 #2
0
        private double suggestBuyPrice(MarketDepthResponse market)
        {
            const double MIN_WALL_VOLUME = 0.8;

            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;
        }
예제 #3
0
        private double suggestBuyPrice(MarketDepthResponse market)
        {
            foreach (var bid in market.Bids)
            {
                if (bid.Price < _executedSellPrice - MIN_DIFFERENCE)
                {
                    return bid.Price.eq(_buyOrderPrice)
                        ? _buyOrderPrice
                        : bid.Price + 0.01;
                }
            }

            //Dirty fix. Sometimes the Huobi server gives so chaotic responses, that closed SELL order is recognised by insufficient
            //           balance and we don't have the SELL price
            if (_executedSellPrice < 0.0)
                return market.Bids.First().Price + 0.01;

            //All BUY orders are too high (probably some wild race). Suggest BUY order with minimum profit and hope
            return _executedSellPrice - MIN_DIFFERENCE;
        }
예제 #4
0
        private double suggestBuyPrice(MarketDepthResponse market)
        {
            double sum = 0;
            var minDiff = VOLUME_WALL * PRICE_DELTA;
            var lowestAsk = market.Asks.First().Price;

            foreach (var bid in market.Bids)
            {
                if (sum + OPERATIVE_AMOUNT > VOLUME_WALL && bid.Price + MIN_DIFFERENCE < lowestAsk)
                {
                    double buyPrice = bid.Price + 0.01;

                    //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) < minDiff)
                    {
                        log("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) < minDiff)
                return _buyOrderPrice;
            return price;
        }