private void ValidateNewBid(Bid bid) { string errorMessage = ""; DateTime biddingStartTime = GetNearestBidStatTime(bid.CreatedDate); DateTime biddingEndTime = biddingStartTime.AddSeconds(BidTimeDurationSeconds); if (bid.CreatedDate < biddingStartTime || bid.CreatedDate > biddingEndTime) { errorMessage += "Invalid time for bidding."; } if (bid.Amount < 1 || bid.Amount > MaxBidAmount) { errorMessage += "\nInvalid bid amount."; } if (bid.User == null) { errorMessage += "\nCurrent user doesn't participate in specified loan."; } if (Bids.Any(x => x.User.Id == bid.User.Id && x.CreatedDate.Date == biddingStartTime.Date)) { errorMessage += "\nCurrent user already has made a bid."; } if (!string.IsNullOrEmpty(errorMessage)) { throw new BusinessLogicException(errorMessage); } }
public OrderBook AddOrder(Order mmsOrder) { if (mmsOrder.MarketSide == MarketSide.Ask) { if (Asks.Any(askOrder => askOrder.MMSId == mmsOrder.MMSId)) { throw new ApplicationException("Ask Order added received, but existing order found: {0}".FormatAs(mmsOrder)); } List <Order> newAsks = Asks.ToList(); newAsks.Add(mmsOrder); return(new OrderBook(Bids, newAsks, Exchange, Pair, Time)); } else { if (Bids.Any(bidOrder => bidOrder.MMSId == mmsOrder.MMSId)) { throw new ApplicationException("Bid Order added received, but existing order found: {0}".FormatAs(mmsOrder)); } List <Order> newBids = Bids.ToList(); newBids.Add(mmsOrder); return(new OrderBook(newBids, Asks, Exchange, Pair, Time)); } }
public SynthOrderBook(AssetPair assetPair, IReadOnlyList <OrderBook> originalOrderBooks) { AssetPair = assetPair; OriginalOrderBooks = originalOrderBooks; BestBid = Bids.Any() ? Bids.First() : (VolumePrice?)null; BestAsk = Asks.Any() ? Asks.First() : (VolumePrice?)null; }
public long GetMaxBet() { if (!Bids.Any()) { return(0); } return(Bids.Max(x => x.Value.Bet)); }
public async Task <bool> DetectNegativeSpread() { if (Asks.Any() && Bids.Any()) { var bestAsk = Asks.Values.Min(ob => ob.Price); var bestBid = Bids.Values.Max(ob => ob.Price); if (bestAsk < bestBid) { await _log.WriteInfoAsync(nameof(DetectNegativeSpread), $"Exchange {Source} AssetPair {AssetPair} Ask {bestAsk} Bid {bestBid}", "Negative spread detected"); return(true); } } return(false); }
/// <summary> /// Calculate the next minimum bid /// </summary> /// <returns>Minimum bid amount</returns> public decimal NextPrice() { if (!Bids.Any()) { return(CurrentItem.StartingBid); } var nextPrice = Bids.Max(bid => bid.Amount); var incrementalRenges = IncrementalRules.OrderByDescending(range => range.MinimumItemValue).ToList(); incrementalRenges.ForEach(range => { if (nextPrice >= range.MinimumItemValue) { return; } nextPrice += range.Increment; }); return(nextPrice); }
// marks the auction as closed and returns tokens to all users public void ProclaimWinner() { if (DateTime.Now > ClosedAt && State == AuctionState.Opened) { // if there is bids if (Bids.Any()) { // select the highest bid var HighestBid = Bids.OrderByDescending(b => b.Amount).First(); // select the other bids var OtherBids = Bids.Where(b => b.UserId != HighestBid.UserId).OrderByDescending(b => b.Amount).GroupBy(b => b.UserId).ToList(); // return tokens to each user foreach (Bid Bid in OtherBids) { Bid.User.Tokens += Bid.Amount; } } // mark the auction as closed State = AuctionState.Closed; } }
/// <summary> /// Reserved for internal use. /// </summary> protected override void ReconstructSubTargets() { ReconstructApiBids( LocationTargetType.City, t => new CityTargetBid { BidAdjustment = t.BidAdjustment, City = t.Location }, () => Location.CityTarget, _ => Location.CityTarget = _, () => Location.CityTarget.Bids, _ => Location.CityTarget.Bids = _ ); ReconstructApiBids( LocationTargetType.MetroArea, t => new MetroAreaTargetBid() { BidAdjustment = t.BidAdjustment, MetroArea = t.Location }, () => Location.MetroAreaTarget, _ => Location.MetroAreaTarget = _, () => Location.MetroAreaTarget.Bids, _ => Location.MetroAreaTarget.Bids = _ ); ReconstructApiBids( LocationTargetType.State, t => new StateTargetBid() { BidAdjustment = t.BidAdjustment, State = t.Location }, () => Location.StateTarget, _ => Location.StateTarget = _, () => Location.StateTarget.Bids, _ => Location.StateTarget.Bids = _ ); ReconstructApiBids( LocationTargetType.Country, t => new CountryTargetBid() { BidAdjustment = t.BidAdjustment, CountryAndRegion = t.Location }, () => Location.CountryTarget, _ => Location.CountryTarget = _, () => Location.CountryTarget.Bids, _ => Location.CountryTarget.Bids = _ ); ReconstructApiBids( LocationTargetType.PostalCode, t => new PostalCodeTargetBid() { BidAdjustment = t.BidAdjustment, PostalCode = t.Location }, () => Location.PostalCodeTarget, _ => Location.PostalCodeTarget = _, () => Location.PostalCodeTarget.Bids, _ => Location.PostalCodeTarget.Bids = _ ); if (Bids.Any()) { Location.IntentOption = Bids.First().IntentOption; } }