public async Task <ITradePlace> BidAsync(decimal price, string ASID, ITradePlace tradeData, CancellationToken ct)
        {
            await logger.Log($"Подача предложения {price} на аукционе {tradeData.PurchCode}");

            if (string.IsNullOrEmpty(ASID))
            {
                throw new ArgumentException(nameof(ASID));
            }

            if (tradeData == null)
            {
                throw new ArgumentNullException(nameof(tradeData));
            }

            var data = configService.GetBidData(price, tradeData);
            var hash = await apiDataProvider.SignAsync(data, ct);

            var bid = new Bid
            {
                reqID   = tradeData.ReqID,
                xmlData = data,
                Hash    = hash
            };

            var jsonData    = JsonConvert.SerializeObject(bid);
            var jsonContent = new StringContent(jsonData, Encoding.UTF8, "application/json");
            var postUrl     = configService.GetTradePlaceBidUrl(tradeData.ReqID, ASID);
            var postResult  = await httpClientService.PostAsync(postUrl, jsonContent, ct);

            var result = serializationService.GetTradePlace(postResult.Text);

            return(result);
        }
Пример #2
0
        // TODO: перенести в SberbankActionsService
        private static async Task <ITradePlace> _waitTradePlace(ISearchResultEntry auction, CancellationToken ct)
        {
            ITradePlace tradeData = null;

            while (tradeData == null)
            {
                try
                {
                    tradeData = await actionsService.GetTradeDataAsync(auction, ct);

                    break;
                }
                catch (Exception e)
                {
                    if (e.ToString().ToLowerInvariant().Contains("торги завершились"))
                    {
                        break;
                    }
                    if (!e.ToString().ToLowerInvariant().Contains("торги начнутся"))
                    {
                        throw;
                    }
                }

                await apiDataProvider.SyncronizeByKeyAsync(auctionInfo.Code, ct);
            }

            return(tradeData);
        }
Пример #3
0
        public string GetBidData(decimal price, ITradePlace tradePlace)
        {
            if (tradePlace == null)
            {
                throw new System.ArgumentNullException(nameof(tradePlace));
            }

            return(_bidDataTemplate
                   .Replace("{{MYNEWPRICE}}", price.ToString().Replace(",", "."))
                   .Replace("{{REQID}}", tradePlace.ReqID)
                   .Replace("{{REQUESTNO}}", tradePlace.ReqNo)
                   .Replace("{{PRICESIGN}}", tradePlace.PriceSign)
                   .Replace("{{PURCHASEID}}", tradePlace.PurchId)
                   .Replace("{{PURCHASECODE}}", tradePlace.PurchCode)
                   .Replace("{{PURCHASENAME}}", tradePlace.PurchName)
                   .Replace("{{SUPPLIERNAME}}", tradePlace.SuppName));
        }