Example #1
0
        public async Task <StockXAccount> VerifyStockXAccount(StockXAccount Account)
        {
            StockXApiResult <LoginCookieToken> Data;

            Data = await StockxApi.StockXApi.GetLogin(Account);

            switch (Data.Code)
            {
            case HttpStatusCode.OK:
                Db.UpdateOnly(() => new StockXAccount()
                {
                    Token                  = Data.RO.AccessToken,
                    CustomerID             = Data.RO.CustomerInfo.Id,
                    Currency               = Data.RO.CustomerInfo.DefaultCurrency,
                    Verified               = true,
                    LoginFails             = 0,
                    Disabled               = false,
                    NextVerification       = DateTime.Now.AddMinutes(5),
                    NextAccountInteraction = DateTime.Now,
                    AccountThread          = ""
                }, A => A.Id == Account.Id);

                break;

            default:
                try
                {
                    var ErrorMessage = JsonConvert.DeserializeObject <FunBoyAutoErrorResponse>(Data.ResultText);
                    if (ErrorMessage != null)
                    {
                        AuditExtensions.CreateAudit(Db, Account.Id, "FunBoy/VerifyStockXAccount", "Login Failed", ErrorMessage.error);
                        if (ErrorMessage.error.Contains(".wait() for") || ErrorMessage.error.Contains("capchta but solved"))
                        {
                            PushFailedLoginBackIntoqueue(Account);
                            return(Account);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
                Account.LoginFails++;
                Account.NextVerification = DateTime.Now.AddMinutes(Account.LoginFails - 1 * 1.5 + 1);
                if (Account.LoginFails > 12)
                {
                    DisableAccountDuetoLoginFailure(Account);
                    AuditExtensions.CreateAudit(Db, Account.Id, "FunBoy/VerifyStockXAccount", "Login Disabled", Data.ResultText);
                }
                else
                {
                    PushFailedLoginBackIntoqueue(Account);
                }

                break;
            }

            return(Account);
        }
            private async Task <bool> CreateAnyNewInventory(StockXAccount login, List <PortfolioItem> ListedItems)
            {
                var Created           = false;
                var AllInventory      = Db.Select(Db.From <Inventory>().Where(A => A.UserId == login.UserId && A.StockXAccountId == login.Id && A.Active && A.Quantity > 0));
                var AllListed         = Db.Select(Db.From <StockXListedItem>().Where(A => A.UserId == login.UserId && A.Id == login.Id && !A.Sold));
                var UnListedInventory = AllInventory.Where(A => !ListedItems.Any(B => B.SkuUuid == A.Sku));

                if (ListedItems.Count > 0)
                {
                    var Deleted = AllListed.Where(A => !ListedItems.Any(B => B.ChainId == A.ChainId));
                    foreach (var Delete in Deleted)
                    {
                        Db.Delete(Delete);
                    }
                }
                foreach (var Listling in ListedItems)
                {
                    if (Db.Exists(Db.From <StockXListedItem>().Where(A => A.UserId == login.UserId && A.AccountId == login.Id && A.ChainId == Listling.ChainId)))
                    {
                        continue;
                    }
                    StockXListedItem Item = Listling;
                    Item.UserId    = login.UserId;
                    Item.AccountId = login.Id;

                    Db.Insert(Item);
                }
                foreach (var tory in UnListedInventory)
                {
                    var Listing = await login.MakeListing(tory.StockXUrl, tory.Sku, tory.StartingAsk, StockXAccount.MakeTimeString());

                    if ((int)Listing.Code > 399 && (int)Listing.Code < 500)
                    {
                        throw new NeedsVerificaitonException(login);
                    }
                    if (Listing.Code == System.Net.HttpStatusCode.OK)
                    {
                        StockXListedItem Item = Listing.RO.PortfolioItem;
                        Item.UserId    = login.UserId;
                        Item.AccountId = tory.StockXAccountId;
                        Db.Insert(Item);

                        Db.UpdateAdd(() => new Inventory()
                        {
                            Quantity = -1
                        }, Ab => Ab.Id == tory.Id);
                        AuditExtensions.CreateAudit(Db, login.Id, "StockxListingGetter", "Inventory Created", Listing.RO.PortfolioItem.ChainId);
                        Created = true;
                        await StockxListingEvent.Listed(Item, login);

                        continue;
                    }
                    return(false); //error 500+ -- their server is down end task.
                }

                return(Created);
            }
            private async Task <bool> ProcessNewBid(StockXAccount login, PortfolioItem Item, Inventory Invntory)
            {
                var Bids = Db.Select(Db.From <StockXBid>().Where(I => I.Sku == Item.SkuUuid && I.Bid >= Invntory.MinSell && I.Bid < Invntory.StartingAsk).OrderByDescending(A => A.Bid));
                var Bid  = Bids.FirstOrDefault();

                if (Bid != null && Bid.Bid != Item.Amount)
                {
                    var Result = await login.UpdateListing(Item.ChainId, Invntory.Sku, Item.ExpiresAt, (int)Bid.Bid);

                    string actionTaken = $"Update Because Bid ({Item.Amount}) -> ({Bid.Bid})";
                    AuditExtensions.CreateAudit(Db, login.Id, "StockxListingGetter", actionTaken, JsonConvert.SerializeObject(Result));
                    ListingExtensions.CreateStockXListingEvent("Bid", Item.ChainId, Invntory.Sku, (int)Bid.Bid, login.UserId, actionTaken);
                    if ((int)Result.Code > 399 && (int)Result.Code < 500)
                    {
                        throw new NeedsVerificaitonException(login);
                    }
                    if (Result.Code == System.Net.HttpStatusCode.OK)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            private async Task <bool> ProcessNewAsk(StockXAccount login, PortfolioItem Item, Inventory Invntory)
            {
                var Asks = Db.Select(Db.From <StockXAsk>().Where(I => I.Sku == Item.SkuUuid && I.Ask >= Invntory.MinSell + 1 && I.Ask < Item.Amount).OrderBy(A => A.Ask));
                var Ask  = Asks.FirstOrDefault();

                if (Ask != null)
                {
                    var Result = await login.UpdateListing(Item.ChainId, Invntory.Sku, Item.ExpiresAt, (int)Ask.Ask - 1);

                    if ((int)Result.Code > 399 && (int)Result.Code < 500)
                    {
                        throw new NeedsVerificaitonException(login);
                    }
                    if (Result.Code == System.Net.HttpStatusCode.OK)
                    {
                        string actionTaken = $"Update Because Ask ({Item.Amount}) -> ({Ask.Ask})";
                        AuditExtensions.CreateAudit(Db, login.Id, "StockxListingGetter", actionTaken, Item.ChainId);
                        ListingExtensions.CreateStockXListingEvent("Bid", Item.ChainId, Invntory.Sku, (int)Ask.Ask, login.UserId, actionTaken);
                        return(true);
                    }
                    return(true);
                }
                return(false);
            }