Exemplo n.º 1
0
        public ActionResult <IEnumerable <string> > EditDealerOrder(int id, DealerOrder dealerOrder)
        {
            if (id != dealerOrder.OrderId)
            {
                return(BadRequest());
            }

            var newCustomerOrder = _business.Update(dealerOrder);

            return(new OkObjectResult(dealerOrder));
        }
 public Task Update(DealerOrder dealerOrder)
 {
     try
     {
         _repository.Update(dealerOrder);
         return(Task.CompletedTask);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         throw ex;
     }
 }
Exemplo n.º 3
0
        public void MostRecentDateEvent_When_NoDomainDates_Then_ReturnsUtcDate()
        {
            // arrange
            var underTest = new DealerOrder(
                A.Fake <IFinancialInstrument>(),
                string.Empty,
                string.Empty,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                string.Empty,
                string.Empty,
                string.Empty,
                string.Empty,
                OrderTypes.LIMIT,
                OrderDirections.BUY,
                new Currency("GBP"),
                new Currency("USD"),
                OrderCleanDirty.NONE,
                null,
                string.Empty,
                string.Empty,
                string.Empty,
                null,
                null,
                null,
                null,
                null,
                null,
                OptionEuropeanAmerican.NONE);

            // act
            var before = DateTime.UtcNow;
            var actual = underTest.MostRecentDateEvent();
            var after  = DateTime.UtcNow;

            // assert
            Assert.True(before <= actual); // allows for time to pass in test execution
            Assert.True(after >= actual);
            Assert.AreEqual(DateTimeKind.Utc, actual.Kind);
        }
Exemplo n.º 4
0
        public void MostRecentDateEvent_When_PlacedDateOnly_Then_ReturnsPlacedDate()
        {
            // arrange
            var placedDate = new DateTime(2019, 1, 1, 1, 1, 1);
            var underTest  = new DealerOrder(
                A.Fake <IFinancialInstrument>(),
                string.Empty,
                string.Empty,
                placedDate,
                null,
                null,
                null,
                null,
                null,
                null,
                string.Empty,
                string.Empty,
                string.Empty,
                string.Empty,
                OrderTypes.LIMIT,
                OrderDirections.BUY,
                new Currency("GBP"),
                new Currency("USD"),
                OrderCleanDirty.NONE,
                null,
                string.Empty,
                string.Empty,
                string.Empty,
                null,
                null,
                null,
                null,
                null,
                null,
                OptionEuropeanAmerican.NONE);

            // act
            var actual = underTest.MostRecentDateEvent();

            // assert
            Assert.AreEqual(placedDate, actual);
        }
Exemplo n.º 5
0
        private OrderFileContract MapTradeFields2(DealerOrder trad, OrderFileContract contract)
        {
            contract.DealerOrderId                     = trad.DealerOrderId;
            contract.DealerOrderPlacedDate             = trad.PlacedDate?.ToString("yyyy-MM-ddTHH:mm:ss");
            contract.DealerOrderBookedDate             = trad.BookedDate?.ToString("yyyy-MM-ddTHH:mm:ss");
            contract.DealerOrderAmendedDate            = trad.AmendedDate?.ToString("yyyy-MM-ddTHH:mm:ss");
            contract.DealerOrderRejectedDate           = trad.RejectedDate?.ToString("yyyy-MM-ddTHH:mm:ss");
            contract.DealerOrderCancelledDate          = trad.CancelledDate?.ToString("yyyy-MM-ddTHH:mm:ss");
            contract.DealerOrderFilledDate             = trad.FilledDate?.ToString("yyyy-MM-ddTHH:mm:ss");
            contract.DealerOrderDealerId               = trad.DealerId;
            contract.DealerOrderCounterParty           = trad.DealerCounterParty;
            contract.DealerOrderType                   = ((int?)trad.OrderType).ToString();
            contract.DealerOrderDirection              = ((int?)trad.OrderDirection).ToString();
            contract.DealerOrderCurrency               = trad.Currency.Code;
            contract.DealerOrderLimitPrice             = trad.LimitPrice?.Value.ToString();
            contract.DealerOrderAverageFillPrice       = trad.AverageFillPrice?.Value.ToString();
            contract.DealerOrderOrderedVolume          = trad.OrderedVolume?.ToString();
            contract.DealerOrderFilledVolume           = trad.FilledVolume?.ToString();
            contract.DealerOrderOptionStrikePrice      = trad.OptionStrikePrice?.ToString();
            contract.DealerOrderOptionExpirationDate   = trad.OptionStrikePrice?.ToString("yyyy-MM-ddTHH:mm:ss");
            contract.DealerOrderOptionEuropeanAmerican = ((int?)trad.OptionEuropeanAmerican).ToString();

            return(contract);
        }
Exemplo n.º 6
0
        private Order MapOrder(OrderFileContract contract, IReadOnlyCollection <DealerOrder> dealerOrder)
        {
            if (dealerOrder == null)
            {
                dealerOrder = new DealerOrder[0];
            }

            var instrument = this.MapInstrument(contract);
            var market     = this.MapMarket(contract);

            var placedDate    = this.MapDate(contract.OrderPlacedDate);
            var bookedDate    = this.MapDate(contract.OrderBookedDate);
            var amendedDate   = this.MapDate(contract.OrderAmendedDate);
            var rejectedDate  = this.MapDate(contract.OrderRejectedDate);
            var cancelledDate = this.MapDate(contract.OrderCancelledDate);
            var filledDate    = this.MapDate(contract.OrderFilledDate);

            var orderType               = this.MapToEnum <OrderTypes>(contract.OrderType);
            var orderDirection          = this.MapToEnum <OrderDirections>(contract.OrderDirection);
            var orderCurrency           = new Currency(contract.OrderCurrency);
            var orderSettlementCurrency = !string.IsNullOrWhiteSpace(contract.OrderSettlementCurrency)
                                              ? new Currency(contract.OrderSettlementCurrency)
                                              : (Currency?)null;

            var orderCleanDirty = this.MapToEnum <OrderCleanDirty>(contract.OrderCleanDirty);

            var limitPrice   = new Money(this.MapDecimal(contract.OrderLimitPrice), contract.OrderCurrency);
            var averagePrice = new Money(this.MapDecimal(contract.OrderAverageFillPrice), contract.OrderCurrency);

            var orderOptionStrikePrice = new Money(
                this.MapDecimal(contract.OrderOptionStrikePrice),
                contract.OrderCurrency);
            var orderOptionExpirationDate   = this.MapDate(contract.OrderOptionExpirationDate);
            var orderOptionEuropeanAmerican =
                this.MapToEnum <OptionEuropeanAmerican>(contract.OrderOptionEuropeanAmerican);

            var orderedVolume = this.MapDecimal(contract.OrderOrderedVolume);
            var filledVolume  = this.MapDecimal(contract.OrderFilledVolume);

            var accInterest = this.MapDecimal(contract.OrderAccumulatedInterest);

            return(new Order(
                       instrument,
                       market,
                       null,
                       contract.OrderId,
                       DateTime.UtcNow,
                       contract.OrderVersion,
                       contract.OrderVersionLinkId,
                       contract.OrderGroupId,
                       placedDate,
                       bookedDate,
                       amendedDate,
                       rejectedDate,
                       cancelledDate,
                       filledDate,
                       orderType,
                       orderDirection,
                       orderCurrency,
                       orderSettlementCurrency,
                       orderCleanDirty,
                       accInterest,
                       limitPrice,
                       averagePrice,
                       orderedVolume,
                       filledVolume,
                       contract.OrderTraderId,
                       contract.OrderTraderName,
                       contract.OrderClearingAgent,
                       contract.OrderDealingInstructions,
                       new OrderBroker(string.Empty, string.Empty, contract.OrderBroker, null, false),
                       orderOptionStrikePrice,
                       orderOptionExpirationDate,
                       orderOptionEuropeanAmerican,
                       dealerOrder));
        }
Exemplo n.º 7
0
        public void Ctor_AssignsVariables_Correctly()
        {
            var placedDate    = new DateTime(2019, 1, 1, 1, 1, 1);
            var bookedDate    = new DateTime(2019, 2, 1, 1, 1, 1);
            var amendedDate   = new DateTime(2019, 3, 1, 1, 1, 1);
            var rejectedDate  = new DateTime(2019, 4, 1, 1, 1, 1);
            var cancelledDate = new DateTime(2019, 5, 1, 1, 1, 1);
            var filledDate    = new DateTime(2019, 6, 1, 1, 1, 1);
            var createdDate   = new DateTime(2019, 7, 1, 1, 1, 1);

            var fi         = new FinancialInstrument();
            var redOrderId = "red-order-id";
            var orderId    = "order-id";

            var traderId          = "trader-id";
            var dealerName        = "mr.dealer";
            var notes             = "my notes";
            var tradeCounterParty = "trade counter party";

            var orderType          = OrderTypes.LIMIT;
            var orderDirection     = OrderDirections.SHORT;
            var currency           = new Currency("GBP");
            var settlementCurrency = new Currency("USD");

            var cleanDirty             = OrderCleanDirty.DIRTY;
            var accumInterest          = 1231.12312m;
            var dealerOrderVersion     = "do-version-1";
            var dealerOrderVersionLink = "do-version-1-link-id";
            var dealerOrderGroupId     = "group-90";
            var limitPrice             = new Money(100, "GBP");
            var averageFillPrice       = new Money(99, "USD");
            var orderedVolume          = 1002;
            var filledVolume           = 1000;
            var optionStrikePrice      = 99.9m;
            var optionExpirationDate   = new DateTime(2019, 08, 1, 1, 1, 1);
            var optionEuropeanAmerican = OptionEuropeanAmerican.AMERICAN;

            var dO = new DealerOrder(
                fi,
                redOrderId,
                orderId,
                placedDate,
                bookedDate,
                amendedDate,
                rejectedDate,
                cancelledDate,
                filledDate,
                createdDate,
                traderId,
                dealerName,
                notes,
                tradeCounterParty,
                orderType,
                orderDirection,
                currency,
                settlementCurrency,
                cleanDirty,
                accumInterest,
                dealerOrderVersion,
                dealerOrderVersionLink,
                dealerOrderGroupId,
                limitPrice,
                averageFillPrice,
                orderedVolume,
                filledVolume,
                optionStrikePrice,
                optionExpirationDate,
                optionEuropeanAmerican);

            Assert.AreEqual(fi, dO.Instrument);
            Assert.AreEqual(redOrderId, dO.ReddeerDealerOrderId);
            Assert.AreEqual(orderId, dO.DealerOrderId);
            Assert.AreEqual(createdDate, dO.CreatedDate);
            Assert.AreEqual(traderId, dO.DealerId);
            Assert.AreEqual(dealerName, dO.DealerName);
            Assert.AreEqual(notes, dO.Notes);
            Assert.AreEqual(tradeCounterParty, dO.DealerCounterParty);
            Assert.AreEqual(orderType, dO.OrderType);
            Assert.AreEqual(orderDirection, dO.OrderDirection);
            Assert.AreEqual(currency, dO.Currency);
            Assert.AreEqual(settlementCurrency, dO.SettlementCurrency);
            Assert.AreEqual(cleanDirty, dO.CleanDirty);
            Assert.AreEqual(accumInterest, dO.AccumulatedInterest);
            Assert.AreEqual(dealerOrderVersion, dO.DealerOrderVersion);
            Assert.AreEqual(dealerOrderVersionLink, dO.DealerOrderVersionLinkId);
            Assert.AreEqual(dealerOrderGroupId, dO.DealerOrderGroupId);
            Assert.AreEqual(limitPrice, dO.LimitPrice);
            Assert.AreEqual(averageFillPrice, dO.AverageFillPrice);
            Assert.AreEqual(orderedVolume, dO.OrderedVolume);
            Assert.AreEqual(filledVolume, dO.FilledVolume);
            Assert.AreEqual(optionStrikePrice, dO.OptionStrikePrice);
            Assert.AreEqual(optionExpirationDate, dO.OptionExpirationDate);
            Assert.AreEqual(optionEuropeanAmerican, dO.OptionEuropeanAmerican);
        }
Exemplo n.º 8
0
        private Order Frame()
        {
            var exch       = new Market("1", "XLON", "LSE", MarketTypes.STOCKEXCHANGE);
            var orderDates = DateTime.UtcNow;
            var tradeDates = DateTime.UtcNow;

            var securityIdentifiers = new InstrumentIdentifiers(
                "1",
                "1",
                null,
                "stan",
                "st12345",
                "sta123456789",
                "stan",
                "sta12345",
                "stan",
                "stan",
                "STAN",
                "stanRic");

            var security = new FinancialInstrument(
                InstrumentTypes.Equity,
                securityIdentifiers,
                "Standard Chartered",
                "CFI",
                "USD",
                "Standard Chartered Bank");

            var trade1 = new DealerOrder(
                security,
                null,
                "my-trade",
                tradeDates,
                tradeDates,
                tradeDates,
                tradeDates,
                tradeDates,
                tradeDates,
                DateTime.UtcNow,
                "trader-1",
                "trader-one",
                "sum-notes",
                "counter-party",
                OrderTypes.MARKET,
                OrderDirections.BUY,
                new Currency("GBP"),
                new Currency(null),
                OrderCleanDirty.CLEAN,
                12,
                "v1",
                "link-12345",
                "grp-1",
                new Money(100, "GBP"),
                new Money(100, "GBP"),
                1000,
                1000,
                null,
                null,
                OptionEuropeanAmerican.NONE);

            var trade2 = new DealerOrder(
                security,
                null,
                "my-trade-2",
                tradeDates,
                tradeDates,
                tradeDates,
                tradeDates,
                tradeDates,
                tradeDates,
                DateTime.UtcNow,
                "trader-2",
                "trader-two",
                "sum-notes",
                "counter-party",
                OrderTypes.MARKET,
                OrderDirections.BUY,
                new Currency("GBP"),
                new Currency("GBP"),
                OrderCleanDirty.CLEAN,
                15,
                "v1",
                "link-12345",
                "grp-1",
                new Money(100, "GBP"),
                new Money(100, "GBP"),
                1000,
                1000,
                null,
                null,
                OptionEuropeanAmerican.NONE);

            var order2 = new Order(
                security,
                exch,
                null,
                "order-1",
                DateTime.UtcNow,
                "order-v1",
                "order-v1-link",
                "order-group-v1",
                orderDates,
                orderDates,
                orderDates,
                orderDates,
                orderDates,
                orderDates,
                OrderTypes.MARKET,
                OrderDirections.BUY,
                new Currency("GBP"),
                new Currency("USD"),
                OrderCleanDirty.CLEAN,
                null,
                new Money(100, "GBP"),
                new Money(100, "GBP"),
                1000,
                1000,
                "trader-1",
                "trader one",
                "clearing-agent",
                "deal asap",
                new OrderBroker(null, string.Empty, "Mr Broker", DateTime.Now, true),
                null,
                null,
                OptionEuropeanAmerican.NONE,
                new[] { trade1, trade2 });

            return(order2);
        }
Exemplo n.º 9
0
        public async Task <ActionResult <DealerOrder> > AddDealerOrder(DealerOrder dealerOrder)
        {
            await _business.Insert(dealerOrder);

            return(CreatedAtAction("GetDealerOrder", new { id = dealerOrder.OrderId }, dealerOrder));
        }
 public async Task Update(DealerOrder dealerOrder)
 {
     _dbContext.Entry(dealerOrder).State = EntityState.Modified;
     await Save();
 }
 public async Task Insert(DealerOrder dealerOrder)
 {
     dealerOrder.OrderNumber = OrderNumberGenerator();
     _dbContext.DealerOrder.Add(dealerOrder);
     await Save();
 }
Exemplo n.º 12
0
        public void ToString_YieldsExpected_Value()
        {
            var placedDate    = new DateTime(2019, 1, 1, 1, 1, 1);
            var bookedDate    = new DateTime(2019, 1, 1, 1, 1, 1);
            var amendedDate   = new DateTime(2019, 1, 1, 1, 1, 1);
            var rejectedDate  = new DateTime(2019, 1, 1, 1, 1, 1);
            var cancelledDate = new DateTime(2019, 1, 1, 1, 1, 1);
            var filledDate    = new DateTime(2019, 1, 1, 1, 1, 1);

            var fi                   = new FinancialInstrument();
            var market               = new Market("market-id", "XLON", "London Stock Exchange", MarketTypes.STOCKEXCHANGE);
            var reddeerOrderId       = 124;
            var orderId              = "order-id";
            var createdDate          = new DateTime(2019, 09, 19, 1, 1, 1);
            var orderVersion         = "version-1";
            var orderVersionLinkId   = "version-link-id-1";
            var orderGroupId         = "order-group-id";
            var orderTypes           = OrderTypes.MARKET;
            var orderDirection       = OrderDirections.SHORT;
            var currency             = new Currency("GBP");
            var settlementCurrency   = new Currency("USD");
            var cleanDirty           = OrderCleanDirty.DIRTY;
            var accumInterest        = 1241.3m;
            var limitPrice           = new Money(99, "GBP");
            var averageFillPrice     = new Money(101, "GBP");
            var orderedVolume        = 1234m;
            var filledVolume         = 4321m;
            var traderId             = "abcdef";
            var traderName           = "Mr Trader";
            var clearingAgent        = "Goldman";
            var dealingInstruction   = "ASAP";
            var broker               = new OrderBroker("broker-1", "2", "Brokerage Inc", DateTime.UtcNow, true);
            var optionStrikePrice    = new Money(30, "USD");
            var optionExpirationDate = new DateTime(2019, 08, 19, 1, 1, 1);
            var optionEurAmer        = OptionEuropeanAmerican.AMERICAN;
            var trades               = new DealerOrder[0];

            var order = new Order(
                fi,
                market,
                reddeerOrderId,
                orderId,
                createdDate,
                orderVersion,
                orderVersionLinkId,
                orderGroupId,
                placedDate,
                bookedDate,
                amendedDate,
                rejectedDate,
                cancelledDate,
                filledDate,
                orderTypes,
                orderDirection,
                currency,
                settlementCurrency,
                cleanDirty,
                accumInterest,
                limitPrice,
                averageFillPrice,
                orderedVolume,
                filledVolume,
                traderId,
                traderName,
                clearingAgent,
                dealingInstruction,
                broker,
                optionStrikePrice,
                optionExpirationDate,
                optionEurAmer,
                trades);

            var result = order.ToString();

            Assert.AreEqual(" |London Stock Exchange | Cancelled | ordered-1234 | filled-4321 | (GBP) 101", result);
        }
Exemplo n.º 13
0
        public void Ctor_AssignsVariables_Correctly()
        {
            var placedDate    = new DateTime(2019, 1, 1, 1, 1, 1);
            var bookedDate    = new DateTime(2019, 1, 1, 1, 1, 1);
            var amendedDate   = new DateTime(2019, 1, 1, 1, 1, 1);
            var rejectedDate  = new DateTime(2019, 1, 1, 1, 1, 1);
            var cancelledDate = new DateTime(2019, 1, 1, 1, 1, 1);
            var filledDate    = new DateTime(2019, 1, 1, 1, 1, 1);

            var fi                   = new FinancialInstrument();
            var market               = new Market("market-id", "XLON", "London Stock Exchange", MarketTypes.STOCKEXCHANGE);
            var reddeerOrderId       = 124;
            var orderId              = "order-id";
            var createdDate          = new DateTime(2019, 09, 19, 1, 1, 1);
            var orderVersion         = "version-1";
            var orderVersionLinkId   = "version-link-id-1";
            var orderGroupId         = "order-group-id";
            var orderTypes           = OrderTypes.MARKET;
            var orderDirection       = OrderDirections.SHORT;
            var currency             = new Currency("GBP");
            var settlementCurrency   = new Currency("USD");
            var cleanDirty           = OrderCleanDirty.DIRTY;
            var accumInterest        = 1241.3m;
            var limitPrice           = new Money(99, "GBP");
            var averageFillPrice     = new Money(101, "GBP");
            var orderedVolume        = 1234m;
            var filledVolume         = 4321m;
            var traderId             = "abcdef";
            var traderName           = "Mr Trader";
            var clearingAgent        = "Goldman";
            var dealingInstruction   = "ASAP";
            var broker               = new OrderBroker("broker-1", "2", "Brokerage Inc", DateTime.UtcNow, true);
            var optionStrikePrice    = new Money(30, "USD");
            var optionExpirationDate = new DateTime(2019, 08, 19, 1, 1, 1);
            var optionEurAmer        = OptionEuropeanAmerican.AMERICAN;
            var trades               = new DealerOrder[0];

            var order = new Order(
                fi,
                market,
                reddeerOrderId,
                orderId,
                createdDate,
                orderVersion,
                orderVersionLinkId,
                orderGroupId,
                placedDate,
                bookedDate,
                amendedDate,
                rejectedDate,
                cancelledDate,
                filledDate,
                orderTypes,
                orderDirection,
                currency,
                settlementCurrency,
                cleanDirty,
                accumInterest,
                limitPrice,
                averageFillPrice,
                orderedVolume,
                filledVolume,
                traderId,
                traderName,
                clearingAgent,
                dealingInstruction,
                broker,
                optionStrikePrice,
                optionExpirationDate,
                optionEurAmer,
                trades);

            Assert.AreEqual(fi, order.Instrument);
            Assert.AreEqual(market, order.Market);
            Assert.AreEqual(reddeerOrderId, order.ReddeerOrderId);
            Assert.AreEqual(orderId, order.OrderId);
            Assert.AreEqual(orderVersion, order.OrderVersion);
            Assert.AreEqual(orderVersionLinkId, order.OrderVersionLinkId);
            Assert.AreEqual(orderGroupId, order.OrderGroupId);
            Assert.AreEqual(optionStrikePrice, order.OrderOptionStrikePrice);
            Assert.AreEqual(optionExpirationDate, order.OrderOptionExpirationDate);
            Assert.AreEqual(optionEurAmer, order.OrderOptionEuropeanAmerican);
            Assert.AreEqual(createdDate, order.CreatedDate);
            Assert.AreEqual(orderTypes, order.OrderType);
            Assert.AreEqual(orderDirection, order.OrderDirection);
            Assert.AreEqual(currency, order.OrderCurrency);
            Assert.AreEqual(settlementCurrency, order.OrderSettlementCurrency);
            Assert.AreEqual(cleanDirty, order.OrderCleanDirty);
            Assert.AreEqual(accumInterest, order.OrderAccumulatedInterest);
            Assert.AreEqual(limitPrice, order.OrderLimitPrice);
            Assert.AreEqual(averageFillPrice, order.OrderAverageFillPrice);
            Assert.AreEqual(traderId, order.OrderTraderId);
            Assert.AreEqual(traderName, order.OrderTraderName);
            Assert.AreEqual(clearingAgent, order.OrderClearingAgent);
            Assert.AreEqual(dealingInstruction, order.OrderDealingInstructions);
            Assert.AreEqual(broker, order.OrderBroker);
            Assert.AreEqual(trades, order.DealerOrders);
            Assert.AreEqual(orderedVolume, order.OrderOrderedVolume);
            Assert.AreEqual(filledVolume, order.OrderFilledVolume);
            Assert.AreEqual(string.Empty, order.OrderFund);
            Assert.AreEqual(string.Empty, order.OrderStrategy);
            Assert.AreEqual(string.Empty, order.OrderClientAccountAttributionId);
            Assert.AreEqual(false, order.IsInputBatch);
            Assert.AreEqual(0, order.BatchSize);
            Assert.AreEqual(null, order.InputBatchId);
        }