Exemplo n.º 1
0
        public async Task <bool> InformTaxTobin(TaxNotifyObject taxNotifyObject)
        {
            var httpOrder    = new StringContent(JsonConvert.SerializeObject(taxNotifyObject), Encoding.UTF8, "application/json");
            var httpResponse = await Client.PostAsync("tax", httpOrder);

            return(httpResponse.IsSuccessStatusCode);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Buy([FromBody] BuyOrder buyOrder)
        {
            Console.Out.WriteLine($"Received buyorder with " +
                                  $"{nameof(buyOrder.Quantity)}={buyOrder.Quantity}, " +
                                  $"{nameof(buyOrder.TickerSymbol)}={buyOrder.TickerSymbol}, " +
                                  $"{nameof(buyOrder.MaxPrice)}={buyOrder.MaxPrice}");

            var buyRecord  = SaveOrderToDatabase(buyOrder);
            var sellRecord = FindMatchingOrder(buyRecord);

            if (sellRecord == null)
            {
                Response.StatusCode = 202;
                var noMatchFoundWillBuyLater = "No match found. Will buy later.";
                Console.Out.WriteLine(noMatchFoundWillBuyLater);
                return(Json(new { status = noMatchFoundWillBuyLater }));
            }

            var changeOwnershipObject = new ChangeOwnershipObject
            {
                BuyerId      = buyRecord.BuyerId,
                Quantity     = sellRecord.Quantity,
                SellerId     = sellRecord.SellerId,
                TickerSymbol = sellRecord.TickerSymbol
            };

            if (await _registryService.ChangeOwnershipAsync(changeOwnershipObject) == false)
            {
                Response.StatusCode = 503;
                var couldNotChangeOwnership = "Could not change ownership.";
                Console.Out.WriteLine(couldNotChangeOwnership);
                return(Json(new { status = couldNotChangeOwnership }));
            }

            UpdateRecordsOnMatch(sellRecord, buyRecord);

            var taxNotifyObject = new TaxNotifyObject
            {
                SellerId   = sellRecord.SellerId,
                TotalPrice = sellRecord.Price * sellRecord.Quantity
            };

            if (await _taxService.InformTaxTobin(taxNotifyObject) == false)
            {
                Response.StatusCode = 503;
                var taxWasNotApplied = "Tax was not applied.";
                Console.Out.WriteLine(taxWasNotApplied);
                return(Json(new { status = taxWasNotApplied }));
            }

            Response.StatusCode = 201;
            var matchFoundWasBought = "Match found. Was bought.";

            Console.Out.WriteLine(matchFoundWasBought);
            return(Json(new { status = matchFoundWasBought }));
        }
Exemplo n.º 3
0
 public Task <bool> InformTaxTobin(TaxNotifyObject taxNotifyObject)
 {
     throw new NotImplementedException();
 }