예제 #1
0
        public SerializedOrder UpdateOrder(SerializedOrder sord, int orderID)
        {
            Order ord = _db.Orders.Where(o => o.OrderID == orderID).FirstOrDefault();

            ord.ContractNumber = sord.ContractNumber;
            _db.SaveChanges();
            return(GetOrder(orderID));
        }
예제 #2
0
        /// <summary>
        /// Creates a new Order instance from a SerializedOrder instance
        /// </summary>
        /// <remarks>Used by the <see cref="SerializedOrderJsonConverter"/></remarks>
        public static Order FromSerialized(SerializedOrder serializedOrder)
        {
            var sid    = SecurityIdentifier.Parse(serializedOrder.Symbol);
            var symbol = new Symbol(sid, sid.Symbol);

            TimeInForce timeInForce = null;
            var         type        = System.Type.GetType($"QuantConnect.Orders.TimeInForces.{serializedOrder.TimeInForceType}", throwOnError: false, ignoreCase: true);

            if (type != null)
            {
                timeInForce = (TimeInForce)Activator.CreateInstance(type, true);
                if (timeInForce is GoodTilDateTimeInForce)
                {
                    var expiry = QuantConnect.Time.UnixTimeStampToDateTime(serializedOrder.TimeInForceExpiry.Value);
                    timeInForce = new GoodTilDateTimeInForce(expiry);
                }
            }

            var createdTime = QuantConnect.Time.UnixTimeStampToDateTime(serializedOrder.CreatedTime);

            var order = CreateOrder(serializedOrder.OrderId, serializedOrder.Type, symbol, serializedOrder.Quantity,
                                    DateTime.SpecifyKind(createdTime, DateTimeKind.Utc),
                                    serializedOrder.Tag,
                                    new OrderProperties {
                TimeInForce = timeInForce
            },
                                    serializedOrder.LimitPrice ?? 0,
                                    serializedOrder.StopPrice ?? 0,
                                    serializedOrder.TriggerPrice ?? 0);

            order.OrderSubmissionData = new OrderSubmissionData(serializedOrder.SubmissionBidPrice,
                                                                serializedOrder.SubmissionAskPrice,
                                                                serializedOrder.SubmissionLastPrice);

            order.BrokerId      = serializedOrder.BrokerId;
            order.ContingentId  = serializedOrder.ContingentId;
            order.Price         = serializedOrder.Price;
            order.PriceCurrency = serializedOrder.PriceCurrency;
            order.Status        = serializedOrder.Status;

            if (serializedOrder.LastFillTime.HasValue)
            {
                var time = QuantConnect.Time.UnixTimeStampToDateTime(serializedOrder.LastFillTime.Value);
                order.LastFillTime = DateTime.SpecifyKind(time, DateTimeKind.Utc);
            }
            if (serializedOrder.LastUpdateTime.HasValue)
            {
                var time = QuantConnect.Time.UnixTimeStampToDateTime(serializedOrder.LastUpdateTime.Value);
                order.LastUpdateTime = DateTime.SpecifyKind(time, DateTimeKind.Utc);
            }
            if (serializedOrder.CanceledTime.HasValue)
            {
                var time = QuantConnect.Time.UnixTimeStampToDateTime(serializedOrder.CanceledTime.Value);
                order.CanceledTime = DateTime.SpecifyKind(time, DateTimeKind.Utc);
            }

            return(order);
        }
예제 #3
0
        public SerializedOrder CreateOrder(SerializedOrder sord)
        {
            Order ord = _db.Orders.Create();

            ord.ContractNumber = sord.ContractNumber;
            _db.Orders.Add(ord);
            _db.SaveChanges();

            sord = _db.Orders.Where(o => o.OrderID == ord.OrderID).Select(SerializedOrder.GenerationLambda).FirstOrDefault();
            return(sord);
        }
예제 #4
0
        public Serialize(string productInfoArray, IRepository repository)
        {
            if (!String.IsNullOrEmpty(productInfoArray))
            {
                // split the array by the key letter
                string[] productInfo = productInfoArray.Split('|');
                for (int i = 0; i < productInfo.Length; i++)
                {
                    var info = productInfo[i].Split(",");

                    // set the parsed info to the corresponding values
                    int _storeId    = Int32.Parse(info[0]);
                    int _customerId = Int32.Parse(info[1]);
                    int ProductId   = Int32.Parse(info[2]);
                    int Quantity    = Int32.Parse(info[3]);

                    // get store information
                    var store = repository.GetProduct(_storeId, ProductId);

                    // get product inventory
                    var product = store.Inventory[0];
                    product.Quantity = Quantity;

                    // add item to the serialized order
                    SerializedOrder.addItem(product);
                    SerializedOrder.CustomerId = _customerId;

                    // set the property while we're at it.
                    if (i == 0)
                    {
                        StoreId    = _storeId;
                        CustomerId = _customerId;

                        SerializedOrder.StoreId    = StoreId;
                        SerializedOrder.CustomerId = CustomerId;
                    }
                }
            }
        }
예제 #5
0
 // PUT api/<controller>/5
 public SerializedOrder Put(int id, [FromBody] SerializedOrder value)
 {
     return(_repo.UpdateOrder(value, id));
 }
예제 #6
0
 // POST api/<controller>
 public SerializedOrder Post([FromBody] SerializedOrder value)
 {
     return(_repo.CreateOrder(value));
 }
예제 #7
0
        public SerializedOrder GetOrder(int orderID)
        {
            SerializedOrder sord = _db.Orders.Where(o => o.OrderID == orderID).Select(SerializedOrder.GenerationLambda).FirstOrDefault();

            return(sord);
        }