Example #1
0
 public IMessageIn Visit(OrderOpen msg)
 {
     msg.OrderId       = (string)_data["order_id"];
     msg.Price         = (decimal)_data["price"];
     msg.RemainingSize = (decimal)_data["remaining_size"];
     return(msg);
 }
Example #2
0
            public object Visit(WebSocket.OrderOpen msg)
            {
                Condition.Requires(msg, "msg").IsNotNull();
                Condition.Requires(msg.OrderId, "msg.OrderId").IsNotNullOrEmpty();
                Condition.Requires(msg.Price, "msg.Price").IsGreaterThan(0m);
                Condition.Requires(msg.RemainingSize, "msg.RemainingSize").IsGreaterThan(0m);

                Level level;

                if (_book.TryGetValue(msg.Price, out level))
                {
                    Condition.Requires(level.TotalSize).IsGreaterOrEqual(0m);
                    Condition.Requires(level.OrderIds).IsNotEmpty();
                }
                else
                {
                    level = new Level();
                    _book.Add(msg.Price, level);
                }

                if (!level.OrderIds.Add(msg.OrderId))
                {
                    throw new ArgumentException("Duplicate order ID: " + msg);
                }
                level.TotalSize += msg.RemainingSize;
                _delta.Add(new PriceLevel()
                {
                    Price = msg.Price, SizeDelta = msg.RemainingSize
                });
                return(null);
            }
Example #3
0
        public static IMessageIn Parse(string serialized)
        {
            var data = Json.ParseObject(serialized);

            Condition.Requires(data, "data").IsNotNull();
            string type = (string)data["type"];

            Condition.Requires(type, "type").IsNotNull();
            IMessageIn res = null;

            switch (type)
            {
            case "received":
                res = new OrderReceived();
                break;

            case "open":
                res = new OrderOpen();
                break;

            case "done":
                res = new OrderDone();
                break;

            case "match":
                res = new OrderMatch();
                break;

            case "change":
                res = new OrderChange();
                break;

            default:
                throw new ArgumentException("Unexpected message type: " + type);
            }
            var parser = new MessageParser(data);

            parser.ParseCommon(res);
            return(res.Visit(parser));
        }