Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Order" /> class.
        /// </summary>
        /// <param name="orderId">The order identifier.</param>
        /// <param name="symbol">The order symbol.</param>
        /// <param name="side">The order side.</param>
        /// <param name="type">The order type.</param>
        /// <param name="quantity">The order quantity.</param>
        /// <param name="price">The order price (optional).</param>
        /// <param name="timeInForce">The order time in force.</param>
        /// <param name="expireTime">The order expire time (optional).</param>
        /// <param name="timestamp">The order timestamp.</param>
        /// <param name="initId">The order initialization event identifier.</param>
        /// <returns>A new order.</returns>
        public static Order Create(
            OrderId orderId,
            Symbol symbol,
            OrderSide side,
            OrderType type,
            Quantity quantity,
            Price?price,
            TimeInForce timeInForce,
            ZonedDateTime?expireTime,
            ZonedDateTime timestamp,
            Guid initId)
        {
            Debug.NotDefault(side, nameof(side));
            Debug.NotDefault(timestamp, nameof(timestamp));

            var initial = new OrderInitialized(
                orderId,
                symbol,
                side,
                type,
                quantity,
                price,
                timeInForce,
                expireTime,
                initId,
                timestamp);

            return(new Order(initial));
        }
Example #2
0
    public void Apply(OrderInitialized @event)
    {
        Version++;

        Id           = @event.OrderId;
        ClientId     = @event.ClientId;
        ProductItems = @event.ProductItems;
        Status       = OrderStatus.Initialized;
    }
Example #3
0
    private Order(Guid id, Guid clientId, IReadOnlyList <PricedProductItem> productItems, decimal totalPrice)
    {
        var @event = OrderInitialized.Create(
            id,
            clientId,
            productItems,
            totalPrice,
            DateTime.UtcNow
            );

        Enqueue(@event);
        Apply(@event);
    }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Order"/> class.
        /// </summary>
        /// <param name="initial">The initial order event.</param>
        public Order(OrderInitialized initial)
            : base(initial.OrderId, initial)
        {
            this.orderFiniteStateMachine = OrderFsmFactory.Create();
            this.executionIds            = new UniqueList <ExecutionId>();

            this.Symbol         = initial.Symbol;
            this.OrderSide      = initial.OrderSide;
            this.OrderType      = initial.OrderType;
            this.Quantity       = initial.Quantity;
            this.FilledQuantity = Quantity.Zero();
            this.Price          = initial.Price;
            this.TimeInForce    = initial.TimeInForce;
            this.ExpireTime     = this.ValidateExpireTime(initial.ExpireTime);
            this.IsBuy          = this.OrderSide == OrderSide.Buy;
            this.IsSell         = this.OrderSide == OrderSide.Sell;
            this.IsWorking      = false;
            this.IsCompleted    = false;

            this.CheckInitialization();
        }
        internal void CanSerializeAndDeserialize_OrderInitializedEvents()
        {
            // Arrange
            var order       = new StubOrderBuilder().BuildMarketOrder();
            var initialized = new OrderInitialized(
                order.Id,
                order.Symbol,
                order.OrderSide,
                order.OrderType,
                order.Quantity,
                order.Price,
                order.TimeInForce,
                order.ExpireTime,
                Guid.NewGuid(),
                StubZonedDateTime.UnixEpoch());

            // Act
            var packed   = this.serializer.Serialize(initialized);
            var unpacked = (OrderInitialized)this.serializer.Deserialize(packed);

            // Assert
            Assert.Equal(initialized, unpacked);
            this.Output.WriteLine(Convert.ToBase64String(packed));
        }
Example #6
0
 private void RaiseOrderInitialized(Order order)
 {
     OrderInitialized?.Invoke(order);
 }
Example #7
0
 private void Apply(OrderInitialized @event)
 {
     OrderId = @event.OrderId;
     Status  = OrderStatus.Started;
 }
Example #8
0
 private void When(OrderInitialized @event)
 {
     // Do nothing
 }
Example #9
0
 public Task Handle(OrderInitialized @event, CancellationToken cancellationToken)
 {
     return(commandBus.Send(RequestPayment.Create(@event.OrderId, @event.TotalPrice)));
 }