private bool AddOrder(OrderTracker tracker, double price) { bool matched = false; Order order = tracker.Order; if (order.IsBuy) { matched = MatchBidOrder(tracker, price, Asks); } else { matched = MatchAskOrder(tracker, price, Bids); } if (tracker.Open != 0 && !tracker.IsImmediate) { if (order.IsBuy) { Bids.Add(price, tracker); } else { Asks.Add(price, tracker); } } return(matched); }
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); }
/// <summary> /// Places a bid on an auction. /// </summary> /// <param name="offer">Details of the bid offer.</param> /// <returns>true if the bid is a high bid.</returns> public virtual bool PlaceBid(Bid offer) { bool winningBid = false; Console.WriteLine(); Console.WriteLine($"Placing bid by {offer.Bidder.ToUpper()} for {offer.BidAmount.ToString("C")}"); // Add the bid to the log Bids.Add(offer); // The first bidder will be the high bidder if (HighBidder == null) { HighBidder = offer; winningBid = true; } // Any new bidder must exceed the current high bidder if (offer.BidAmount > HighBidder.BidAmount) { Console.WriteLine($"High Bidder {HighBidder.Bidder.ToUpper()} has been outbid by {offer.Bidder.ToUpper()}!"); // Replace the high bidder with offer HighBidder = offer; winningBid = true; } Console.WriteLine($"Current high bid is held by {HighBidder.Bidder.ToUpper()} for {HighBidder.BidAmount.ToString("C")}"); Console.WriteLine(); return(winningBid); }
private void Dispatch(OrderBookModel orderBookModel) { Asks.Clear(); Bids.Clear(); int count = orderBookModel.Asks.Count; int takeCount = 100; orderBookModel.Asks.Skip(count - takeCount).Take(takeCount).ToList().ForEach(x => Asks.Add(new OrderBookEntry { Amount = x.Amount, DateTime = x.DateTime, Price = x.Price, GroupedPrice = x.GroupedPrice, GroupedVolume = x.GroupedVolume })); orderBookModel.Bids.Take(100).ToList().ForEach(x => Bids.Add(new OrderBookEntry { Amount = x.Amount, DateTime = x.DateTime, Price = x.Price, GroupedPrice = x.GroupedPrice, GroupedVolume = x.GroupedVolume })); }
public void ReceiveBid(Interested interested, double amount) { if (BidIsValid(interested)) { Bids.Add(new Bid(interested, amount)); _lastInterested = interested; } }
public virtual void AddBid(Bid bid) { if (bid == null) { throw new ArgumentException("Can't add a null Bid."); } Bids.Add(bid); }
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); }
public void MakeBid(int userId, double amount) { User user = LoanUsers .FirstOrDefault(x => x.UserId == userId) ?.User; Bid bid = new Bid(amount, user, DateTime.Now); ValidateNewBid(bid); Bids.Add(bid); }
internal void OnLevel2(Level2Snapshot l2s) { Bids.Clear(); Asks.Clear(); foreach (var b in l2s.Bids) { Bids.Add(new Tick(b)); } foreach (var a in l2s.Asks) { Asks.Add(new Tick(a)); } }
public Orderbook(string assetPairId, decimal bid, decimal ask, int depth) { AssetPairId = assetPairId; var jitter = TheRandom.Range(1, Program.Settings.books.bestPriceDeviation); bid *= jitter; ask *= jitter; for (var(i, offset) = (0, 0.001m * (ask - bid)); i < depth; offset = Max(0.001m, Min((ask - bid) * i / depth, offset * i++))) { // volume = 10 * (i * i + 1) Bids.Add(Level(bid - i * offset, Vol(i))); Asks.Add(Level(ask + i * offset, Vol(i))); } }
public void PerformBidding() { HashSet <Player> hasPassed = new HashSet <Player>(); bool stillBidding = true; do { foreach (Player player in Players) { if (hasPassed.Contains(player)) { continue; } SetHand(player); int?playerBid = player.MakeBid(this); if (playerBid is null) { if (hasPassed.Count == 3) { throw new Exception(player.Name + " has passed when all other players have already passed."); } hasPassed.Add(player); if (hasPassed.Count == 3) { break; } } else if (Bids.Count > 0 && playerBid <= Bids.Keys.Max()) { throw new Exception(player.Name + " has bid at or below the current bid."); } else if (playerBid < 10) { throw new Exception(player.Name + " has bid at or below the minimum bid of 10."); } Bids.Add(playerBid.Value, player); } if (hasPassed.Count > 2) { stillBidding = false; } }while (stillBidding); SetHand(Bids[Bids.Keys.Max()]); Trump = Bids[Bids.Keys.Max()].ChooseTrump(this); }
/// <summary> /// Read from a binary reader /// </summary> /// <param name="reader">Binary reader</param> public void FromBinary(BinaryReader reader) { Asks.Clear(); Bids.Clear(); int askCount = reader.ReadInt32(); int bidCount = reader.ReadInt32(); while (askCount-- > 0) { var exchangeOrderPrice = new ExchangeOrderPrice(reader); Asks.Add(exchangeOrderPrice.Price, exchangeOrderPrice); } while (bidCount-- > 0) { var exchangeOrderPrice = new ExchangeOrderPrice(reader); Bids.Add(exchangeOrderPrice.Price, exchangeOrderPrice); } }
protected void btnBidNow_Click(object sender, EventArgs e) { if (item == null) { GetListing(); } Users user = HelperClass.GetLoggedInUser(); var _price = txtYourBudget.Text; int price; int.TryParse(_price, out price); Bids bid = new Bids(item, user, price); bid.Add(); Response.Redirect("Single.aspx?id=" + item.Id); }
protected void btnSave_Click(object sender, EventArgs e) { Bids bid = new Bids(); var _userId = Session["user"].ToString(); bid.BuyerId = int.Parse(_userId); bid.Date = DateTime.Now; bid.Price = int.Parse(txtAmount.Text); id = Request.QueryString["id"]; bid.ProductId = int.Parse(id); bid.Add(); divBidAmount.Visible = true; divBidNow.Visible = false; lblYourBid.Text = bid.Price.ToString(); Contract contract = new Contract(); contract.Bid = bid; contract.Add(); }
public Bid PostBid(User user, Currency bidAmount) { Contract.Requires(user != null); if (bidAmount.Code != CurrencyCode) { throw new InvalidBidException(bidAmount, WinningBid); } if (bidAmount.Value <= CurrentPrice.Value) { throw new InvalidBidException(bidAmount, WinningBid); } var bid = new Bid(user, this, bidAmount); CurrentPrice = bidAmount; WinningBidId = bid.Id; Bids.Add(bid); return(bid); }
/// <summary> /// Evaluate and place the specified bid. Checks if the last 3 bids are Pass /// or a Pass and Double or Re-double is placed, the last bid is the winner and /// the bidding is closed. /// </summary> public void PlaceBid(Bid bid) { if (!IsClosed) { if (gameSession.GetPlayer(CurrentTurn) == bid.Player) { //TODO: handle pass&double and re-double bids Bid lastBid = GetLastNonPassBid(); if (bid.IsPass || lastBid == null || (lastBid != null && bid.CompareTo(lastBid) > 0)) { Bids.Add(bid); if (bid.IsPass && GetNumberOfPassBids() >= 3) { IsClosed = true; gameSession.BiddingComplete(); } else { NextTurn(); } } else { throw new ArgumentException("The placed bid is less than the last bid"); } } else { throw new InvalidOperationException("The player placed a bit not in the right turn"); } } else { throw new InvalidOperationException("Cannot place bids when the bidding is closed"); } }
public bool GetBids() { if (null != Bids) { Bids.Clear(); } else { Bids = new List <BidVieModel>(); } try { RealEntities db = new RealEntities(); var bids = db.bids.Where(b => b.property_id == PropertyId); if (null != bids) { foreach (var b in bids) { BidVieModel bid = new BidVieModel(); bid.BidId = b.bid_id; bid.PropertyId = b.property_id; bid.BuyerId = b.buyer_id; bid.Status = ( BidStatus )b.status; //bid.LandPrice = ( double )b.bid_price.plot_price; //bid.HousePrice = ( double )b.bid_price.apartment_price; //bid.BuyerName = b.buyer.user.first_name + " " + b.buyer.user.last_name; //bid.BuyerAddress = b.buyer.user.address; Bids.Add(bid); } } return(true); } catch (Exception ex) { } return(false); }
protected internal void ForceAddBid(OrderBookUpdateInfo info) { Bids.Add(info.Entry); }
public void MakeBid(Bid bid) { Bids.Add(bid); }
private void BBookData_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { Global.Shared.IncomingBinance.BBookData.Purge(); if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { var bookdata = (BinanceStreamOrderBook)e.NewItems[0]; if (Ask.Count() > 0 || Bids.Count() > 0) { for (int i = 0; i < bookdata.Asks.Count(); i++) { var correspondingBookAskLine = bookdata.Asks[i]; var correspondingBookBidLine = bookdata.Bids[i]; var AskLine = Ask[i]; var BidLine = Bids[i]; if (AskLine.Weight != correspondingBookAskLine.Quantity.ChangeType <double>() || AskLine.Y != correspondingBookAskLine.Price.ChangeType <double>()) { AskLine.Weight = bookdata.Asks[i].Quantity.ChangeType <double>(); AskLine.Y = bookdata.Asks[i].Price.ChangeType <double>(); } if (BidLine.Weight != correspondingBookBidLine.Quantity.ChangeType <double>() || BidLine.Y != correspondingBookBidLine.Price.ChangeType <double>()) { BidLine.Weight = bookdata.Bids[i].Quantity.ChangeType <double>(); BidLine.Y = bookdata.Bids[i].Price.ChangeType <double>(); } } } else { for (int i = 0; i < bookdata.Asks.Count(); i++) { Ask.Add(new HeatPoint(i, double.Parse(bookdata.Asks[i].Price.ToString()), double.Parse(bookdata.Asks[i].Quantity.ToString()))); } for (int i = 0; i < bookdata.Asks.Count(); i++) { Bids.Add(new HeatPoint(i, double.Parse(bookdata.Bids[i].Price.ToString()), double.Parse(bookdata.Bids[i].Quantity.ToString()))); } } //Ask.Add(new HeatPoint(0, double.Parse(bookdata.Asks[0].Price.ToString()), double.Parse(bookdata.Asks[0].Quantity.ToString()))); //Ask.Add(new HeatPoint(1, double.Parse(bookdata.Asks[1].Price.ToString()), double.Parse(bookdata.Asks[1].Quantity.ToString()))); //Ask.Add(new HeatPoint(2, double.Parse(bookdata.Asks[2].Price.ToString()), double.Parse(bookdata.Asks[2].Quantity.ToString()))); //Ask.Add(new HeatPoint(3, double.Parse(bookdata.Asks[3].Price.ToString()), double.Parse(bookdata.Asks[3].Quantity.ToString()))); try { cartesianChart3.Invoke((MethodInvoker) delegate { try { cartesianChart3.Series[0].Values = Ask; cartesianChart3.Series[1].Values = Bids; cartesianChart3.Update(false, true); } catch { } //var dt = cartesianChart3.Series[0].DataLabels; }); } catch { } //bookdata.Asks.ForEach(y => //{ // Ask.Add(new HeatPoint()) // //Invoke((MethodInvoker)delegate //}); } }
public override void Parse(Response response) { var beginBidLength = Bids.Count; var i = beginBidLength; foreach (var title_link in response.Css("h1.title a")) { string strTitle = title_link.TextContentClean; string detailUrl = title_link.Attributes["href"]; var newBid = new Bid(); newBid.Name = strTitle; newBid.DetailUrl = detailUrl; Scrape(newBid); Bids.Add(newBid); ++i; } i = beginBidLength; foreach (var title_link in response.Css("h1.title em")) { string em = title_link.InnerTextClean; var resultString = Regex.Match(em, @"\d+").Value; Bids[i].LotNumber = Int32.Parse(resultString); ++i; } i = beginBidLength; foreach (var priceString in response.Css("span.NumberPart")) { string s = priceString.TextContentClean; try { var converted = Convert.ToDouble(s); Bids[i].CurrentBid = converted; } catch (FormatException fe) { } ++i; } i = beginBidLength; foreach (var bidCount in response.Css("span.awe-rt-AcceptedListingActionCount")) { string s = bidCount.TextContentClean; int count = 0; try { var converted = Convert.ToInt32(s); count = converted; } catch (FormatException fe) { } Bids[i].BidCount = count; ++i; } if (response.CssExists("ul.pagination > li:last-child > a[href]")) { var next_page = response.Css("ul.pagination > li:last-child > a[href]")[0].Attributes["href"]; this.Request(next_page, Parse); } else { _eventAggregator.GetEvent <AuctionNewResponeEvent>().Publish(Bids.ToList()); } }
public void AddBid(Bid bid) { Bids.Add(bid); }
//protected int lastUpdate_FinalUpdateID; public void Update(BinanceOrderBookUpdate update, bool isFirstEvent) { if (update.EventType != "depthUpdate") { return; } if (update.FinalUpdateID <= this.LastUpdateId) { return; } if (isFirstEvent && (update.FirstUpdateID > LastUpdateId + 1 || update.FinalUpdateID < LastUpdateId + 1)) { throw new Exception("Update ID manquant"); } if (!isFirstEvent && update.FirstUpdateID != LastUpdateId + 1) { Debug.WriteLine($"Dans BinanceOderBookSanpshot.Update(): firstUpdateID du nouvel event différent de u + 1 avec u: finalUpdateID du dernier event"); //return; throw new Exception("Incohérence dans les update IDs"); } //lastUpdate_FinalUpdateID = update.FinalUpdateID; LastUpdateId = update.FinalUpdateID; LastEventTime = update.EventTime; foreach (BinanceAskBid ask in update.Asks) { var matchingAsk = this.Asks.OfType <BinanceAskBid>().FirstOrDefault(a => a.Price == ask.Price); if (matchingAsk != null && ask.Volume > 0) { matchingAsk.Volume = ask.Volume; } else if (matchingAsk != null && ask.Volume == 0) { Asks.Remove(matchingAsk); } else if (ask.Volume > 0) { Asks.Add(ask); Asks.Sort(new AsksComparer()); } } foreach (var bid in update.Bids) { var matchingBid = this.Bids.FirstOrDefault(b => b.Price == bid.Price); if (matchingBid != null && bid.Volume > 0) { matchingBid.Volume = bid.Volume; } else if (matchingBid != null && bid.Volume == 0) { Bids.Remove(matchingBid); } else if (bid.Volume > 0) { Bids.Add(bid); Bids.Sort(new BidsComparer()); } } }
public void AddBid(Participant p, int b) { Bids.Add(p, b); }
public void MakeBid(Bid bid) { bid.PlayerPosition = Position; Bids.Add(bid); }
public void AddBid(Sneaker sneaker, double size, double price) { Bids.Add(new Bid(this, sneaker, size, price)); }
private void Place(WinningBid newBid) { Bids.Add(new HistoricalBid(newBid.Bidder, newBid.MaximumBid, newBid.TimeOfBid)); WinningBid = newBid; }