public override int GetHashCode() { unchecked { int hashCode = (SecurityCode != null ? SecurityCode.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OptionNumber != null ? OptionNumber.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (OptionCode != null ? OptionCode.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Bid.GetHashCode(); hashCode = (hashCode * 397) ^ BidVolume.GetHashCode(); hashCode = (hashCode * 397) ^ Ask.GetHashCode(); hashCode = (hashCode * 397) ^ AskVolume.GetHashCode(); hashCode = (hashCode * 397) ^ Volume.GetHashCode(); hashCode = (hashCode * 397) ^ Bid2.GetHashCode(); hashCode = (hashCode * 397) ^ BidVolume2.GetHashCode(); hashCode = (hashCode * 397) ^ Ask2.GetHashCode(); hashCode = (hashCode * 397) ^ AskVolume2.GetHashCode(); hashCode = (hashCode * 397) ^ Bid3.GetHashCode(); hashCode = (hashCode * 397) ^ BidVolume3.GetHashCode(); hashCode = (hashCode * 397) ^ Ask3.GetHashCode(); hashCode = (hashCode * 397) ^ AskVolume3.GetHashCode(); hashCode = (hashCode * 397) ^ Bid4.GetHashCode(); hashCode = (hashCode * 397) ^ BidVolume4.GetHashCode(); hashCode = (hashCode * 397) ^ Ask4.GetHashCode(); hashCode = (hashCode * 397) ^ AskVolume4.GetHashCode(); hashCode = (hashCode * 397) ^ Bid5.GetHashCode(); hashCode = (hashCode * 397) ^ BidVolume5.GetHashCode(); hashCode = (hashCode * 397) ^ Ask5.GetHashCode(); hashCode = (hashCode * 397) ^ AskVolume5.GetHashCode(); hashCode = (hashCode * 397) ^ (Greeks != null ? Greeks.GetHashCode() : 0); hashCode = (hashCode * 397) ^ OpenInterest.GetHashCode(); hashCode = (hashCode * 397) ^ Turnover.GetHashCode(); hashCode = (hashCode * 397) ^ UncoveredPositionQuantity.GetHashCode(); hashCode = (hashCode * 397) ^ PreviousSettlementPrice.GetHashCode(); hashCode = (hashCode * 397) ^ OpeningPrice.GetHashCode(); hashCode = (hashCode * 397) ^ AuctionReferencePrice.GetHashCode(); hashCode = (hashCode * 397) ^ AuctionReferenceQuantity.GetHashCode(); hashCode = (hashCode * 397) ^ HighestPrice.GetHashCode(); hashCode = (hashCode * 397) ^ LowestPrice.GetHashCode(); hashCode = (hashCode * 397) ^ LatestTradedPrice.GetHashCode(); hashCode = (hashCode * 397) ^ Change.GetHashCode(); hashCode = (hashCode * 397) ^ ChangePercentage.GetHashCode(); hashCode = (hashCode * 397) ^ PreviousClose.GetHashCode(); hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); return(hashCode); } }
protected bool Equals(OptionViewModel other) { return(string.Equals(OptionNumber, other.OptionNumber) && Bid.Equals(other.Bid) && BidVolume == other.BidVolume && Ask.Equals(other.Ask) && AskVolume == other.AskVolume && Volume == other.Volume && Bid2.Equals(other.Bid2) && BidVolume2 == other.BidVolume2 && Ask2.Equals(other.Ask2) && AskVolume2 == other.AskVolume2 && Bid3.Equals(other.Bid3) && BidVolume3 == other.BidVolume3 && Ask3.Equals(other.Ask3) && AskVolume3 == other.AskVolume3 && Bid4.Equals(other.Bid4) && BidVolume4 == other.BidVolume4 && Ask4.Equals(other.Ask4) && AskVolume4 == other.AskVolume4 && Bid5.Equals(other.Bid5) && BidVolume5 == other.BidVolume5 && Ask5.Equals(other.Ask5) && AskVolume5 == other.AskVolume5 && Equals(Greeks, other.Greeks) && OpenInterest == other.OpenInterest && Turnover.Equals(other.Turnover) && UncoveredPositionQuantity == other.UncoveredPositionQuantity && PreviousSettlementPrice.Equals(other.PreviousSettlementPrice) && OpeningPrice.Equals(other.OpeningPrice) && AuctionReferencePrice.Equals(other.AuctionReferencePrice) && AuctionReferenceQuantity == other.AuctionReferenceQuantity && HighestPrice.Equals(other.HighestPrice) && LowestPrice.Equals(other.LowestPrice) && LatestTradedPrice.Equals(other.LatestTradedPrice) && Change.Equals(other.Change) && ChangePercentage.Equals(other.ChangePercentage) && PreviousClose.Equals(other.PreviousClose) && string.Equals(Name, other.Name)); }
//private IList<ItemBuyBoxResponse> RequestItemsBuyBoxByAdv(ILogService logger, IList<Item> items, AmazonApi api) //{ // var results = new List<ItemBuyBoxResponse>(); // var index = 0; // //var indexToSleep = 0; // while (index < items.Count) // { // var checkedItems = items.Skip(index).Take(10).ToList(); // var resp = RetryHelper.ActionWithRetries(() => // api.RetrieveOffersWithMerchant(logger, checkedItems.Select(i => i.ASIN).ToList()), // logger); // if (resp != null && resp.Items != null && resp.Items.Any() && resp.Items[0].Item != null) // { // foreach (var item in checkedItems) // { // var status = BuyBoxStatusCode.Undefined; // decimal? price = null; // decimal? salePrice = null; // decimal? amountSaved = null; // string merchantName = null; // var el = resp.Items[0].Item.FirstOrDefault(i => i.ASIN == item.ASIN); // if (el != null && el.Offers != null) // { // if (el != null && el.Offers != null && el.Offers.Offer != null) // { // var itemId = item.Id; // var firstOffer = el.Offers.Offer.FirstOrDefault(); // if (firstOffer != null) // { // merchantName = firstOffer.Merchant.Name; // if (String.IsNullOrEmpty(merchantName)) // { // status = BuyBoxStatusCode.NoWinner; // } // else // { // status = (merchantName == AddressService.Name) // ? BuyBoxStatusCode.Win // : BuyBoxStatusCode.NotWin; // } // if (firstOffer.OfferListing != null && firstOffer.OfferListing.Length > 0) // { // //Note: firstOffer.OfferListing[0].Price.Amount stored price in "1499" format without any separators // if (firstOffer.OfferListing[0].Price != null) // { // price = StringHelper.TryGetInt(firstOffer.OfferListing[0].Price.Amount); // if (price != null) // price = price/100; // } // if (firstOffer.OfferListing[0].SalePrice != null) // { // salePrice = StringHelper.TryGetInt(firstOffer.OfferListing[0].SalePrice.Amount); // if (salePrice != null) // salePrice = salePrice/100; // } // if (firstOffer.OfferListing[0].AmountSaved != null) // { // amountSaved = StringHelper.TryGetInt(firstOffer.OfferListing[0].AmountSaved.Amount); // if (amountSaved != null) // amountSaved = amountSaved/100; // } // } // } // } // } // results.Add(new ItemBuyBoxResponse() // { // ASIN = item.ASIN, // CheckedDate = DateTime.UtcNow, // Status = status, // WinnerPrice = price, // WinnerSalePrice = salePrice, // WinnerAmountSaved = amountSaved, // WinnerMerchantName = merchantName // }); // } // } // index += 10; // Thread.Sleep(TimeSpan.FromSeconds(5)); // } // return results; //} public int ProcessOfferChanges(AmazonSQSReader reader, IList <string> sellerIds) { var index = 0; var maxCount = 100; var existNotification = true; using (var db = _dbFactory.GetRWDb()) { while (index < maxCount && existNotification) { var notifications = reader.GetNotification(); existNotification = notifications.Any(); _log.Info("Receive notifications, count=" + notifications.Count); foreach (var n in notifications) { try { var changeDate = AmazonSQSReader.TryGetDate( n.NotificationPayload.AnyOfferChangedNotification.OfferChangeTrigger .TimeOfOfferChange); if (!changeDate.HasValue) { throw new ArgumentNullException("ChangeDate"); } _log.Info("Notification change date=" + changeDate); LowestPrice buyBoxPrice = null; OfferCount buyBoxAmazonOffers = null; OfferCount buyBoxMerchantOffers = null; LowestPrice merchantLowestPrices = null; LowestPrice amazonLowestPrices = null; OfferCount merchantOffers = null; OfferCount amazonOffers = null; if (n.NotificationPayload.AnyOfferChangedNotification != null && n.NotificationPayload.AnyOfferChangedNotification.Summary != null) { if (n.NotificationPayload.AnyOfferChangedNotification.Summary.BuyBoxPrices != null) { buyBoxPrice = n.NotificationPayload.AnyOfferChangedNotification.Summary.BuyBoxPrices .FirstOrDefault( b => b.Condition == "new"); } if (n.NotificationPayload.AnyOfferChangedNotification.Summary.BuyBoxEligibleOffers != null) { buyBoxAmazonOffers = n.NotificationPayload.AnyOfferChangedNotification.Summary .BuyBoxEligibleOffers .FirstOrDefault(o => o.FulfillmentChannel == "Amazon" && o.Condition == "new"); buyBoxMerchantOffers = n.NotificationPayload.AnyOfferChangedNotification.Summary.BuyBoxEligibleOffers .FirstOrDefault( o => o.FulfillmentChannel == "Merchant" && o.Condition == "new"); } if (n.NotificationPayload.AnyOfferChangedNotification.Summary.OfferCounts != null) { amazonOffers = n.NotificationPayload.AnyOfferChangedNotification.Summary.OfferCounts .FirstOrDefault(o => o.FulfillmentChannel == "Amazon" && o.Condition == "new"); merchantOffers = n.NotificationPayload.AnyOfferChangedNotification.Summary .OfferCounts .FirstOrDefault(o => o.FulfillmentChannel == "Merchant" && o.Condition == "new"); } if (n.NotificationPayload.AnyOfferChangedNotification.Summary.LowestPrices != null) { amazonLowestPrices = n.NotificationPayload.AnyOfferChangedNotification.Summary .LowestPrices .FirstOrDefault( p => p.FulfillmentChannel == "Amazon" && p.Condition == "new"); merchantLowestPrices = n.NotificationPayload.AnyOfferChangedNotification.Summary .LowestPrices.FirstOrDefault( p => p.FulfillmentChannel == "Merchant" && p.Condition == "new"); } } var offerChangeEvent = new OfferChangeEvent() { ASIN = n.NotificationPayload.AnyOfferChangedNotification.OfferChangeTrigger.ASIN, MarketplaceId = n.NotificationPayload.AnyOfferChangedNotification.OfferChangeTrigger.MarketplaceId, ChangeDate = changeDate.Value, BuyBoxLandedPrice = buyBoxPrice != null && buyBoxPrice.LandedPrice != null ? decimal.Parse(buyBoxPrice.LandedPrice.Amount) : (decimal?)null, BuyBoxListingPrice = buyBoxPrice != null && buyBoxPrice.ListingPrice != null ? decimal.Parse(buyBoxPrice.ListingPrice.Amount) : (decimal?)null, BuyBoxShipping = buyBoxPrice != null && buyBoxPrice.Shipping != null ? decimal.Parse(buyBoxPrice.Shipping.Amount) : (decimal?)null, BuyBoxEligibleOffersAmazon = buyBoxAmazonOffers != null ? AmazonSQSReader.TryGetInt(buyBoxAmazonOffers.Value) : (int?)null, BuyBoxEligibleOffersMerchant = buyBoxMerchantOffers != null ? AmazonSQSReader.TryGetInt(buyBoxMerchantOffers.Value) : (int?)null, ListPrice = AmazonSQSReader.GetPrice( n.NotificationPayload.AnyOfferChangedNotification.Summary.ListPrice), LowestLandedPriceAmazon = amazonLowestPrices != null ? AmazonSQSReader.GetPrice(amazonLowestPrices.LandedPrice) : null, LowestListingPriceAmazon = amazonLowestPrices != null ? AmazonSQSReader.GetPrice(amazonLowestPrices.ListingPrice) : null, LowestShippingAmazon = amazonLowestPrices != null ? AmazonSQSReader.GetPrice(amazonLowestPrices.Shipping) : null, LowestLandedPriceMerchant = merchantLowestPrices != null ? AmazonSQSReader.GetPrice(merchantLowestPrices.LandedPrice) : null, LowestListingPriceMerchant = merchantLowestPrices != null ? AmazonSQSReader.GetPrice(merchantLowestPrices.ListingPrice) : null, LowestShippingMerchant = merchantLowestPrices != null ? AmazonSQSReader.GetPrice(merchantLowestPrices.Shipping) : null, NumberOfOffersAmazon = amazonOffers != null?AmazonSQSReader.TryGetInt(amazonOffers.Value) : (int?)null, NumberOfOffersMerchant = merchantOffers != null ? AmazonSQSReader.TryGetInt(merchantOffers.Value) : (int?)null, CreateDate = _time.GetAppNowTime(), }; db.OfferChangeEvents.Add(offerChangeEvent); db.Commit(); var offers = new List <OfferInfo>(); foreach (var offer in n.NotificationPayload.AnyOfferChangedNotification.Offers) { var newOffer = new OfferInfo() { OfferChangeEventId = offerChangeEvent.Id, IsBuyBoxWinner = offer.IsBuyBoxWinner, IsFeaturedMerchant = offer.IsFeaturedMerchant, IsFulfilledByAmazon = offer.IsFulfilledByAmazon, ShipsDomestically = offer.ShipsDomestically, SellerId = offer.SellerId, FeedbackCount = offer.SellerFeedbackRating != null ? AmazonSQSReader.TryGetInt(offer.SellerFeedbackRating.FeedbackCount) : null, SellerPositiveFeedbackRating = offer.SellerFeedbackRating != null ? AmazonSQSReader.TryGetInt( offer.SellerFeedbackRating.SellerPositiveFeedbackRating) : null, ListingPrice = AmazonSQSReader.GetPrice(offer.ListingPrice), Shipping = AmazonSQSReader.GetPrice(offer.Shipping), ShippingTimeMaximumHours = AmazonSQSReader.TryGetInt(offer.ShippingTime.MaximumHours), ShippingTimeMinimumHours = AmazonSQSReader.TryGetInt(offer.ShippingTime.MinimumHours), ShippingTimeAvailabilityType = offer.ShippingTime.AvailabilityType, ShipsFromCountry = offer.ShipsFrom != null ? offer.ShipsFrom.Country : null, ShipsFromState = offer.ShipsFrom != null ? offer.ShipsFrom.State : null, CreateDate = _time.GetAppNowTime(), }; db.OfferInfoes.Add(newOffer); offers.Add(newOffer); } db.Commit(); //Update buybox BuyBoxStatusCode status = BuyBoxStatusCode.NoWinner; var winOffer = offers.FirstOrDefault(o => o.IsBuyBoxWinner); if (winOffer != null) { if (sellerIds.Contains(winOffer.SellerId)) { status = BuyBoxStatusCode.Win; } else { status = BuyBoxStatusCode.NotWin; } } db.BuyBoxStatus.Update(_log, _time, new BuyBoxStatusDTO() { ASIN = offerChangeEvent.ASIN, MarketplaceId = offerChangeEvent.MarketplaceId, CheckedDate = offerChangeEvent.ChangeDate, WinnerPrice = offerChangeEvent.BuyBoxListingPrice, Status = status, }, AmazonUtils.GetMarketByMarketplaceId(offerChangeEvent.MarketplaceId), offerChangeEvent.MarketplaceId); } catch (Exception ex) { _log.Info("Process notification", ex); } } index++; } } return(index); }