public AuktionBudViewModel([NotNull] AuktionModel auktion,
                                   [NotNull, ItemNotNull] List <BudModel> bud)
        {
            AuktionID   = auktion.AuktionID;
            Titel       = auktion.Titel;
            Beskrivning = auktion.Beskrivning;
            StartDatum  = auktion.StartDatum;
            SlutDatum   = auktion.SlutDatum;
            Utropspris  = auktion.Utropspris ?? 0;
            SkapadAv    = auktion.SkapadAv;
            Gruppkod    = auktion.Gruppkod;

            Bids       = bud.Select(b => new BudViewModel(b)).ToList();
            MaxedPrice = Bids.Count == 0
                ? Utropspris : Bids.Max(b => b.Summa);

            HighestBid = Bids.FirstOrDefault();

            DateTime now = DateTime.Now;

            TimeUntilEnd            = SlutDatum - now;
            TimeUntilEndFormatted   = DateTimeHelpers.FormatRemainingTime(SlutDatum);
            TimeSinceStart          = now - StartDatum;
            TimeSinceStartFormatted = DateTimeHelpers.FormatRemainingTime(StartDatum);
            IsClosed = SlutDatum < now;
        }
Exemplo n.º 2
0
 public SynthOrderBook(AssetPair assetPair, IReadOnlyList <OrderBook> originalOrderBooks)
 {
     AssetPair          = assetPair;
     OriginalOrderBooks = originalOrderBooks;
     BestBid            = Bids.FirstOrDefault();
     BestAsk            = Asks.FirstOrDefault();
 }
Exemplo n.º 3
0
        public bool AddBid(Player player, decimal amount, out decimal currentBid)
        {
            if (!IsValidBid(amount, out currentBid))
            {
                return(false);
            }

            GetBidPrice(player, amount);

            var bid = Bids.FirstOrDefault(c => c.Player.Id == player.channel.owner.playerID.steamID.m_SteamID);

            if (bid == null)
            {
                bid = new AuctionBid()
                {
                    Player = new CachedPlayer(player),
                    Amount = amount
                };
                Bids.Add(bid);
            }
            else
            {
                bid.Amount = amount;
            }

            BestBid = bid;
            return(true);
        }
Exemplo n.º 4
0
 void OnRemove(OrderBookUpdateInfo info)
 {
     if (info.Type == OrderBookEntryType.Bid)
     {
         OrderBookEntry entry = Bids.FirstOrDefault((e) => e.Value == info.Entry.Value);
         if (entry == null)
         {
             Debug.WriteLine("Error removing: '" + info.Type + "' with rate " + info.Entry.Value + " not found");
             return;
         }
         Bids.Remove(entry);
     }
     else
     {
         OrderBookEntry entry = Asks.FirstOrDefault((e) => e.Value == info.Entry.Value);
         if (entry == null)
         {
             Debug.WriteLine("Error removing: '" + info.Type + "' with rate " + info.Entry.Value + " not found");
             return;
         }
         Asks.Remove(entry);
     }
     RaiseOnChanged(info);
     OnChangedCore(info);
 }
Exemplo n.º 5
0
        public void EndAuction()
        {
            ThrowIfCompletedOrCanceled();
            Completed = true;
            var winningBid = Bids.FirstOrDefault(b => b.Price == Bids.Max(bid => bid.Price));

            Buyer = winningBid?.UserIdentity;
            AddEvent(new AuctionCompleted(AggregateId, winningBid, Owner));
        }
Exemplo n.º 6
0
        public decimal GetBidPrice(Player player, decimal amount)
        {
            var bid = Bids.FirstOrDefault(c => c.Player.Id == player.channel.owner.playerID.steamID.m_SteamID);

            if (bid == null)
            {
                return(amount);
            }
            return(amount - bid.Amount);
        }
Exemplo n.º 7
0
        void OnAddBid(OrderBookUpdateInfo info)
        {
            OrderBookEntry before = Bids.FirstOrDefault((e) => e.Value < info.Entry.Value);

            if (before == null)
            {
                Bids.Add(info.Entry);
                return;
            }
            Bids.Insert(Bids.IndexOf(before), info.Entry);
        }
Exemplo n.º 8
0
        public Offer GetOffer(string hash)
        {
            Offer result = null;

            result = Bids.FirstOrDefault(o => o.HashStr == hash);

            if (result == null)
            {
                result = Asks.FirstOrDefault(o => o.HashStr == hash);
            }

            return(result);
        }
Exemplo n.º 9
0
        protected internal void OnModify(OrderBookUpdateInfo info)
        {
            OrderBookEntry entry = info.Type == OrderBookEntryType.Ask ?
                                   Asks.FirstOrDefault((e) => e.Value == info.Entry.Value) :
                                   Bids.FirstOrDefault((e) => e.Value == info.Entry.Value);

            if (entry == null)
            {
                OnAdd(info);
                return;
            }
            entry.Amount = info.Entry.Amount;
            info.Entry   = entry;
            RaiseOnChanged(info);
            OnChangedCore(info);
        }
Exemplo n.º 10
0
        private void CancelBid(Bid bid, bool fromEvents)
        {
            ThrowIfBuyNowOnly();
            ThrowIfCompletedOrCanceled();

            var existingBid = _bids.FirstOrDefault(b => b.BidId.Equals(bid.BidId));

            if (existingBid == null)
            {
                throw new DomainException($"Cannot find bid with BidId: {bid.BidId}");
            }

            if (!fromEvents && DateTime.UtcNow.Subtract(existingBid.DateCreated)
                .Minutes > 10)
            {
                throw new DomainException($"Bid ({bid.BidId}) was created more than 10 minutes ago");
            }

            _bids.Remove(existingBid);
            Bid newWinningBid = null;

            if (existingBid.Price.Equals(ActualPrice))
            {
                var topBid = Bids.FirstOrDefault(b => b.Price == Bids.Max(mbid => mbid.Price));
                if (topBid != null)
                {
                    ActualPrice   = topBid.Price;
                    newWinningBid = topBid;
                }
                else
                {
                    ActualPrice   = 0;
                    newWinningBid = existingBid;
                }
            }
            AddEvent(new BidCanceled(existingBid, newWinningBid));
        }