private double suggestBuyPrice(MarketDepth market) { const double MIN_WALL_VOLUME = 0.1; double sumVolume = 0.0; foreach (var bid in market.bid) { //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.01; } } //All BUY orders are too high (probably some wild race). Suggest BUY order with minimum profit and hope return _executedSellPrice - MIN_DIFFERENCE; }
private double suggestSellPrice(MarketDepth market) { double sum = 0; var minDiff = _wallVolume * PRICE_DELTA; var highestBid = market.bid.First().price; foreach (var ask in market.ask) { if (sum + _operativeAmount > _wallVolume && ask.price-MIN_DIFFERENCE > highestBid) { double sellPrice = ask.price - 0.01; //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.ask[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.ask.Last().price - 0.01; if (-1 != _sellOrderId && Math.Abs(price - _sellOrderPrice) < minDiff) return _sellOrderPrice; return price; }
private double suggestBuyPrice(MarketDepth market) { double sum = 0; var minDiff = VOLUME_WALL * PRICE_DELTA; var lowestAsk = market.ask.First().price; foreach (var bid in market.bid) { 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.bid[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.bid.Last().price + 0.01; if (-1 != _buyOrderId && Math.Abs(price - _buyOrderPrice) < minDiff) return _buyOrderPrice; return price; }
private double suggestSellPrice(MarketDepth market) { const double MIN_WALL_VOLUME = 0.1; double sumVolume = 0.0; foreach (var ask in market.ask) { //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 + MIN_DIFFERENCE) { return ask.price.eq(_sellOrderPrice) ? _sellOrderPrice : ask.price - 0.01; } } //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 + MIN_DIFFERENCE; }
private double suggestSellPrice(MarketDepth market, double spread) { var sellPrice = Math.Round(market.ask.First().price - spread/3.0, 2); if (sellPrice > _executedBuyPrice + MIN_DIFFERENCE && -1 == _sellOrderId) return sellPrice; if (-1 != _sellOrderId) { var minDiff = spread * PRICE_DELTA; if (Math.Abs(sellPrice - _buyOrderPrice) < minDiff) { log("DEBUG: SELL price {0} too similar, using previous", sellPrice); return _buyOrderPrice; } } return _executedBuyPrice + MIN_DIFFERENCE; }
private double suggestBuyPrice(MarketDepth market, double spread) { var firstBid = market.bid.First(); //Either we don't have active BUY or we do, but someone else gave better price if (-1 == _buyOrderId || !firstBid.price.eq(_buyOrderPrice)) return Math.Round(firstBid.price + spread / 3.0, 2); //Someone else shares the price if (firstBid.amount > _operativeAmount) return Math.Round(firstBid.price + spread / 3.0, 2); var buyPrice = Math.Round(market.bid[1].price + spread / 3.0, 2); var minDiff = spread * PRICE_DELTA; if (Math.Abs(buyPrice - _buyOrderPrice) < minDiff) { log("DEBUG: BUY price {0} too similar, using previous", buyPrice); return _buyOrderPrice; } return buyPrice; }
private double getSpread(MarketDepth market) { //Find highest BUY order that's not ours var firstBid = market.bid.First(); double highestBidPrice; if (-1 == _buyOrderId) highestBidPrice = firstBid.price; else { if (_buyOrderPrice.eq(firstBid.price)) { //It's only us if (firstBid.amount.eq(_buyOrderAmount)) highestBidPrice = market.bid[1].price; else highestBidPrice = firstBid.price; } else highestBidPrice = firstBid.price; } //Find lowest SELL order not from us var firstAsk = market.ask.First(); double lowestAskPrice; if (-1 == _sellOrderId) lowestAskPrice = firstAsk.price; else { if (_sellOrderPrice.eq(firstAsk.price)) { //It's only us if (_sellOrderAmount.eq(firstAsk.amount)) lowestAskPrice = market.ask[1].price; else lowestAskPrice = firstAsk.price; } else lowestAskPrice = firstAsk.price; } log("DEBUG: lowestAsk={0}; highestBid={1};", lowestAskPrice, highestBidPrice); return lowestAskPrice - highestBidPrice; }