public void ProcessExistingItems(IUnitOfWork db, IMarketApi api, List <ItemDTO> items) { _log.Debug("Begin process existing items"); var index = 0; //var logUpdatedItems = new List<string>(); foreach (var dtoItem in items) { try { Item dbItem = null; var dbListing = db.Listings.GetBySKU(dtoItem.SKU, api.Market, api.MarketplaceId); if (dbListing != null) { dbItem = db.Items.Get(dbListing.ItemId); } if (dbItem == null) { _log.Fatal("ProcessExistingItems. Can't find item in DB with SKU=" + dtoItem.SKU); continue; } if (dtoItem.IsExistOnAmazon == true) { _log.Info("Filled by Amazon (exist item), asin=" + dtoItem.ASIN + ", SKU=" + dtoItem.SKU + ", parentASIN=" + dtoItem.ParentASIN); SetItemFieldsIfExistOnAmazon(db, dtoItem, dbItem); SetListingFieldsIfExistOnAmazon(db, dbListing, dtoItem); } else { if (dtoItem.IsExistOnAmazon == false) //NOTE: skip when =NULL { SetItemFieldsIfNotExistOnAmazon(db, dbItem); } _syncInfo.AddWarning(dtoItem.ASIN, "Item is not filled by Amazon (exist item)"); _log.Warn("Item is not filled by Amazon, item=" + dtoItem.ASIN); } } catch (Exception ex) { _syncInfo.AddError(dtoItem.ASIN, "Error while updating item", ex); _log.Error(string.Format("Error while updating item {0}", dtoItem.ASIN), ex); } index++; if (index % 100 == 0) { db.Commit(); db.ReCreate(); } } db.Commit(); //_syncInfo.AddEntities(SyncMessageStatus.Success, logUpdatedItems, "Updated by Amazon (exist items)"); _log.Debug("End process items"); }
public WooCommerceOrdersSynchronizer(ILogService log, IMarketApi api, CompanyDTO company, ISettingsService settings, ISyncInformer syncInfo, IList <IShipmentApi> rateProviders, IQuantityManager quantityManager, IEmailService emailService, IOrderValidatorService validatorService, IOrderHistoryService orderHistoryService, ICacheService cacheService, ISystemActionService systemAction, ICompanyAddressService companyAddress, ITime time, IWeightService weightService, ISystemMessageService messageService) : base(log, api, company, settings, syncInfo, rateProviders, quantityManager, emailService, validatorService, orderHistoryService, cacheService, systemAction, companyAddress, time, weightService, messageService) { }
/// <summary> /// Register a market api to use in BotHandlerService /// </summary> /// <param name="marketApi"></param> /// <returns></returns> public Builder RegisterMarketApi(IMarketApi marketApi) { Preconditions.CheckNotNull(marketApi); _botHandlerService._marketApis.Add(marketApi); return(this); }
protected override bool FillOrderItemsBy(ILogService log, IUnitOfWork db, IMarketApi api, IList <ListingOrderDTO> orderItems) { //Check order listings var allListingsUpdated = db.Listings.FillOrderItemsBySKU(orderItems, api.Market, api.MarketplaceId); return(allListingsUpdated); }
public static MemoryStream ExportToExcelUS(ILogService log, ITime time, IMarketCategoryService categoryService, IHtmlScraperService htmlScraper, IMarketApi marketApi, IUnitOfWork db, CompanyDTO company, string asin, MarketType market, string marketplaceId, bool useStyleImage, out string filename) { var models = GetItemsFor(log, time, categoryService, htmlScraper, marketApi, db, company, asin, ExportToExcelMode.Normal, null, market, marketplaceId, useStyleImage ? UseStyleImageModes.StyleImage : UseStyleImageModes.ListingImage, out filename); return(ExcelHelper.ExportIntoFile(HttpContext.Current.Server.MapPath(USTemplatePath), "Template", models)); }
public TradingAlgo(IMarketApi marketApi, Configuration config) { Config = config; Market = marketApi; Market.OnNewTrade += Market_OnNewTrade; this.DoMarginTrading = config.MarginTrading; }
public void ImportListings(IMarketApi api) { var itemSyncService = new WooCommerceItemsImporter(_log, _time, _dbFactory); itemSyncService.Import(api); }
public void GetItems(IMarketApi api, IList <string> marketIds) { var asinsWithError = new List <string>(); var items = api.GetItems(_log, _time, MarketItemFilters.Build(marketIds), ItemFillMode.Defualt, out asinsWithError); }
public void CallUpdateParentItemEBay(IMarketApi api, string parentAsin) { var list = new List <string>() { parentAsin }; var parentASINsWithError = new List <string>(); var parents = api.GetItems(_log, _time, MarketItemFilters.Build(list), ItemFillMode.Defualt, out parentASINsWithError); }
public UpdateOrdersFromOrderApiThread(string logTag, IMarketApi api, long companyId, ISystemMessageService messageService, TimeSpan?callbackInterval) : base(logTag, companyId, messageService, callbackInterval) { _api = api; _market = api.Market; }
public void ImportShopifyListings(IMarketApi api) { var itemSyncService = new ShopifyItemsImporter(_log, _time, _dbFactory, _styleHistoryService, null); itemSyncService.Import(api, null, ShopifyItemsImporter.ImportModes.Full, false, true, true, importDescription: false); }
public void Import(IMarketApi api) { var asinsWithError = new List <string>(); var items = api.GetItems(_log, _time, null, ItemFillMode.Defualt, out asinsWithError); _log.Info("Items count: " + items.Count()); var index = 0; var updatedListingIds = new List <long>(); var processOnlyStyle = true; foreach (var item in items) { _log.Info("item: " + index); CreateOrUpdateListing(_dbFactory, _time, _log, api.Market, api.MarketplaceId, item, canCreate: true, updateQty: true, updateStyleInfo: true, mapByBarcode: true, processOnlyStyle: false); updatedListingIds.AddRange(item.Variations.Where(v => v.ListingEntityId.HasValue).Select(v => v.ListingEntityId.Value).ToList()); index++; } //Mark as deleted not exists if (!processOnlyStyle) { using (var db = _dbFactory.GetRWDb()) { var notExistListings = db.Listings.GetAll().Where(l => !updatedListingIds.Contains(l.Id) && l.Market == (int)api.Market && (l.MarketplaceId == api.MarketplaceId || String.IsNullOrEmpty(api.MarketplaceId))) .ToList(); foreach (var listing in notExistListings) { _log.Info("Listing was removed, SKU=" + listing.SKU); listing.IsRemoved = true; listing.UpdateDate = _time.GetAppNowTime(); } db.Commit(); } } }
public void ProcessNewParents(IUnitOfWork db, IMarketApi api, IList <ItemDTO> parents, IList <ItemDTO> items) { var parentASINsWithError = new List <string>(); _log.Debug("Begin process new parents, count=" + parents.Count); var parentsDto = api.GetItems(_log, _time, MarketItemFilters.Build(parents.Select(p => p.ParentASIN).ToList()), ItemFillMode.NoAdv, out parentASINsWithError).ToList(); _log.Debug("Error when GetItems, parentASINS: " + String.Join(", ", parentASINsWithError)); //Fill fake parentItem with item info var notAmazonUpdatedParents = parentsDto.Where(p => p.IsAmazonUpdated != true).ToList(); foreach (var parent in notAmazonUpdatedParents) { _log.Warn("Parent item is not filled by Amazon (setting image from first item), ParentASIN=" + parent.ASIN); _syncInfo.AddWarning(parent.ASIN, "Parent item is not filled by Amazon (setting image from first item)"); //NOTE: parent EQUAL to first item (contains the same info) var item = items.FirstOrDefault(r => r.ParentASIN == parent.ASIN); if (item != null) { parent.ImageSource = item.ImageUrl; parent.AmazonName = item.Name; } } foreach (var parent in parentsDto) { //NOTE: prepare ParentSKU if (String.IsNullOrEmpty(parent.SKU)) { var mainStyleString = db.Items.GetAllViewAsDto() .Where(pi => pi.ASIN == parent.ASIN && pi.Market == (int)api.Market && pi.MarketplaceId == api.MarketplaceId) .OrderByDescending(i => i.IsDefault) .ThenBy(i => i.Id) .FirstOrDefault()?.StyleString; parent.SKU = StringHelper.JoinTwo("-", mainStyleString, parent.ASIN); } var dbParent = db.ParentItems.CreateOrUpdateParent(parent, api.Market, api.MarketplaceId, _time.GetAppNowTime()); _log.Warn("Parent item was stored, ParentASIN=" + parent.ASIN); _syncInfo.AddSuccess(parent.ASIN, "Parent item was stored"); } _log.Debug("End process new parents"); }
public async Task <IList <CurrencyPair> > LoadCurrencyPairs(Exchange exchange) { IMarketApi marketApi = _marketApis.FirstOrDefault(m => m.Exchange == exchange); if (ReferenceEquals(marketApi, null)) { return(new List <CurrencyPair>()); } return(await marketApi.ReadCurrencyPairs()); }
public override void Process(IMarketApi api, ITime time, AmazonReportInfo reportInfo, IList <IReportItemDTO> reportItems) { using (var uow = new UnitOfWork(Log)) { var items = reportItems.Cast <ItemDTO>().ToList(); Log.Debug("Begin process items"); ProcessItems(uow, api, items); Log.Debug("End process items"); } }
public void Dispose() { if (ITradeApi != null) { ITradeApi.Dispose(); } if (IMarketApi != null) { IMarketApi.Dispose(); } }
protected IList <ListingOrderDTO> GetOrderItemsFromMarket(ILogService log, IMarketApi api, ISyncInformer syncInfo, string orderId) { try { return(api.GetOrderItems(orderId).ToList()); } catch (Exception ex) { log.Error("Error when getting order items", ex); syncInfo.AddError(orderId, "Failed getting order items", ex); return(new List <ListingOrderDTO>()); } }
protected override bool FillOrderItemsBy(ILogService log, IUnitOfWork db, IMarketApi api, IList <ListingOrderDTO> orderItems) //NOTE: Only using for listings lookup { //Checking listings (inventory may haven't some listing, ex. not synced new listings) //In this case skipping calculation, waiting listing var allListingsUpdated = db.Listings.FillOrderItemsBySKU(orderItems, api.Market, api.MarketplaceId); return(allListingsUpdated); }
protected override bool FillOrderItemsBy(ILogService log, IUnitOfWork db, IMarketApi api, //DTOMarketOrder order, IList <ListingOrderDTO> orderItems //, //string orderMarketplaceId ) //NOTE: only using for listings lookup (on Amazon) { //Check order listings var allListingsUpdated = db.Listings.FillOrderItemsByStyleAndSize(orderItems, api.Market, api.MarketplaceId); return(allListingsUpdated); }
public LiveOhlcInstrument(Exchange exchange, CurrencyPair currencyPair, IMarketApi marketApi) { _marketApi = Preconditions.CheckNotNull(marketApi); Exchange = Preconditions.CheckNotNull(exchange); CurrencyPair = Preconditions.CheckNotNull(currencyPair); // Add Ohlc series to dictionary _ohlcSeries.Add(new LiveOhlcSeries(300)); // 5 min _ohlcSeries.Add(new LiveOhlcSeries(900)); // 15 min _ohlcSeries.Add(new LiveOhlcSeries(1800)); // 30 min _ohlcSeries.Add(new LiveOhlcSeries(7200)); // 2 hour _ohlcSeries.Add(new LiveOhlcSeries(14400)); // 4 hour _ohlcSeries.Add(new LiveOhlcSeries(86400)); // 1 day }
public void OrderValidationStepAlways(IUnitOfWork db, ITime time, IMarketApi api, CompanyDTO company, DTOMarketOrder marketOrder, IList <ListingOrderDTO> orderItems, IList <OrderShippingInfoDTO> shippings, Order dbOrder) { var hasCancellationChecker = new HasCancellationChecker(_log, _actionService, _time); var result = hasCancellationChecker.Check(db, marketOrder, orderItems); hasCancellationChecker.ProcessResult(result, dbOrder); }
public void Create(Exchange exchange, CurrencyPair currencyPair, IMarketApi marketApi) { Preconditions.CheckNotNull(exchange); Preconditions.CheckNotNull(currencyPair); Preconditions.CheckNotNull(marketApi); // Check if LiveInstrument doesn't already exist for exchange/currenypair if (_liveInstruments.Any(i => i.Exchange == exchange && i.CurrencyPair.Equals(currencyPair))) { return; } _liveInstruments.Add(new LiveOhlcInstrument(exchange, currencyPair, marketApi)); }
public void GetOrders(IMarketApi api, string orderId) { if (String.IsNullOrEmpty(orderId)) { var orders = api.GetOrders(_log, DateTime.UtcNow.AddDays(-4), null); _log.Info(orders.Count().ToString()); } else { var orders = api.GetOrders(_log, new List <string>() { orderId }); _log.Info(orders.Count().ToString()); } }
public override void Process(IMarketApi api, ITime time, AmazonReportInfo reportInfo, IList <IReportItemDTO> reportItems) { var listingProcessor = new ListingLineProcessing(Context, time, _canCreateStyleInfo); using (var uow = new UnitOfWork(Log)) { uow.DisableValidation(); var items = reportItems.Cast <ItemDTO>().ToList(); if (!_isProcessInactive) { items = items.Where(i => i.PublishedStatus != (int)PublishedStatuses.PublishedInactive).ToList(); } foreach (var item in items) { item.MarketplaceId = api.MarketplaceId; item.Market = (int)api.Market; item.CurrentPriceCurrency = "USD"; if (api.MarketplaceId == MarketplaceKeeper.AmazonCaMarketplaceId) { item.CurrentPriceCurrency = "CAD"; } if (api.MarketplaceId == MarketplaceKeeper.AmazonUkMarketplaceId) { item.CurrentPriceCurrency = "GBP"; } if (api.MarketplaceId == MarketplaceKeeper.AmazonMxMarketplaceId) { item.CurrentPriceCurrency = "MXN"; } if (api.MarketplaceId == MarketplaceKeeper.AmazonAuMarketplaceId) { item.CurrentPriceCurrency = "AUD"; } item.CurrentPriceInUSD = PriceHelper.RougeConvertToUSD(item.CurrentPriceCurrency, item.CurrentPrice); } Log.Debug("Begin process items"); ProcessItems(uow, api, time, listingProcessor, items, reportInfo.WasModified); Log.Debug("End process items"); } }
public static ItemRankViewModel GetRank(IMarketApi api, IUnitOfWork db, ILogService log, ITime time, string asin) { var model = new ItemRankViewModel(); var soldFrom = time.GetAppNowTime().Date.AddDays(-7); asin = StringHelper.TrimWhitespace(asin); model.ASIN = asin; var asinsWithError = new List <string>(); var parentItems = api.GetItems(log, time, MarketItemFilters.Build(new List <string>() { asin }), ItemFillMode.NoAdv, out asinsWithError) .Where(i => i.IsAmazonUpdated == true) .ToList(); if (parentItems.Any()) { var parentItem = parentItems.First(); if (!String.IsNullOrEmpty(parentItem.TempParentASIN)) { parentItems = api.GetItems(log, time, MarketItemFilters.Build(new List <string>() { parentItem.TempParentASIN }), ItemFillMode.NoAdv, out asinsWithError) .Where(i => i.IsAmazonUpdated == true) .ToList(); } if (parentItems.Any()) { model.Rank = parentItems.First().Rank; model.ClosestListings = GetClosestListings(db, model.Rank, soldFrom); return(model); } } throw new Exception("Not found"); }
public override void Process(IMarketApi api, ITime time, AmazonReportInfo reportInfo, IList <IReportItemDTO> reportItems) { var listingProcessor = new ListingLineProcessing(Context, time, _canCreateStyleInfo); var items = reportItems.Cast <ItemDTO>().ToList(); if (!_isProcessInactive) { items = items.Where(i => i.PublishedStatus != (int)PublishedStatuses.PublishedInactive).ToList(); } //NOTE: Exclude all Rusty items = items.Where(i => !StringHelper.ContainsNoCase(i.Name, "Rusty")).ToList(); foreach (var item in items) { item.MarketplaceId = api.MarketplaceId; item.Market = (int)api.Market; item.CurrentPriceCurrency = "USD"; if (api.MarketplaceId == MarketplaceKeeper.AmazonCaMarketplaceId) { item.CurrentPriceCurrency = "CAD"; } if (api.MarketplaceId == MarketplaceKeeper.AmazonUkMarketplaceId) { item.CurrentPriceCurrency = "GBP"; } if (api.MarketplaceId == MarketplaceKeeper.AmazonMxMarketplaceId) { item.CurrentPriceCurrency = "MXN"; } if (api.MarketplaceId == MarketplaceKeeper.AmazonAuMarketplaceId) { item.CurrentPriceCurrency = "AUD"; } item.CurrentPriceInUSD = PriceHelper.RougeConvertToUSD(item.CurrentPriceCurrency, item.CurrentPrice); } Log.Debug("Begin process items"); ProcessItems(api, time, listingProcessor, items, reportInfo.WasModified); Log.Debug("End process items"); }
public void ProcessExistingParents(IUnitOfWork db, IMarketApi api, ISyncInformer syncInfo, IList <string> parentASINs, IList <ItemDTO> items) { var parentASINsWithError = new List <string>(); _log.Debug("Begin process existing parents, count=" + parentASINs.Count); var parentsDto = api.GetItems(_log, _time, MarketItemFilters.Build(parentASINs), ItemFillMode.NoAdv, out parentASINsWithError).ToList(); _log.Debug("Error when GetItems, parentASINS: " + String.Join(", ", parentASINsWithError)); //Only update fields foreach (var parent in parentsDto) { //NOTE: in case when parent item has "no-img" using child image if (String.IsNullOrEmpty(parent.ImageSource)) { var childImage = items.FirstOrDefault(i => i.ParentASIN == parent.ASIN && !String.IsNullOrEmpty(i.ImageUrl)); if (childImage != null) { parent.ImageSource = childImage.ImageUrl; } } var dbParent = db.ParentItems.CreateOrUpdateParent(parent, api.Market, api.MarketplaceId, _time.GetAppNowTime()); _log.Warn("Parent item was updated, ParentASIN=" + parent.ASIN); syncInfo.AddSuccess(parent.ASIN, "Parent item was updated"); } _log.Debug("End process existing parents"); }
public override void Process(IMarketApi api, ITime time, AmazonReportInfo reportInfo, IList <IReportItemDTO> sourceItems) { using (var db = new UnitOfWork(Log)) { var returnItems = sourceItems.Select(i => (ReturnRequestDTO)i).ToList(); var updatedList = new List <string>(returnItems.Count); foreach (var item in returnItems) { var returnRequest = db.ReturnRequests.GetAll() .OrderByDescending(r => r.CreateDate) .FirstOrDefault(r => r.OrderNumber == item.OrderNumber); if (returnRequest != null) { if (!updatedList.Contains(item.OrderNumber)) { Log.Info("Return request has been updated, orderNumber=" + item.OrderNumber); returnRequest.HasPrepaidLabel = item.HasPrepaidLabel; returnRequest.PrepaidLabelCost = item.PrepaidLabelCost; returnRequest.PrepaidLabelBy = item.PrepaidLabelBy; updatedList.Add(item.OrderNumber); } else { Log.Info("Order has multiple returns: " + item.OrderNumber); } } else { Log.Info("Return request == null, orderNumber=" + item.OrderNumber); } } db.Commit(); } }
public override void Process(IMarketApi api, ITime time, AmazonReportInfo reportInfo, IList <IReportItemDTO> reportItems) { using (var uow = new UnitOfWork(Log)) { uow.DisableValidation(); var items = reportItems.Cast <ListingDefectDTO>().ToList(); string reportId = reportInfo.ReportId; foreach (var item in items) { item.MarketplaceId = api.MarketplaceId; item.MarketType = (int)api.Market; item.ReportId = reportId; } Log.Debug("Begin process items"); ProcessItems(uow, reportId, items); Log.Debug("End process items"); } }
public override void Process(IMarketApi api, ITime time, AmazonReportInfo reportInfo, IList <IReportItemDTO> reportItems) { using (var uow = new UnitOfWork(Log)) { uow.DisableValidation(); var items = reportItems.Cast <ItemDTO>().ToList(); foreach (var item in items) { item.MarketplaceId = api.MarketplaceId; item.Market = (int)api.Market; item.CurrentPriceCurrency = "USD"; if (api.MarketplaceId == MarketplaceKeeper.AmazonCaMarketplaceId) { item.CurrentPriceCurrency = "CAD"; } if (api.MarketplaceId == MarketplaceKeeper.AmazonUkMarketplaceId) { item.CurrentPriceCurrency = "GBP"; } if (api.MarketplaceId == MarketplaceKeeper.AmazonMxMarketplaceId) { item.CurrentPriceCurrency = "MXN"; } if (api.MarketplaceId == MarketplaceKeeper.AmazonAuMarketplaceId) { item.CurrentPriceCurrency = "AUD"; } item.CurrentPriceInUSD = PriceHelper.RougeConvertToUSD(item.CurrentPriceCurrency, item.CurrentPrice); } Log.Debug("Begin process items"); ProcessItems(uow, api, time, items); Log.Debug("End process items"); } }