コード例 #1
0
ファイル: Parser.cs プロジェクト: kwood/ExchangeApi
 public IMessageIn Visit(OrderOpen msg)
 {
     msg.OrderId       = (string)_data["order_id"];
     msg.Price         = (decimal)_data["price"];
     msg.RemainingSize = (decimal)_data["remaining_size"];
     return(msg);
 }
コード例 #2
0
ファイル: OrderBookBuilder.cs プロジェクト: kwood/ExchangeApi
            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);
            }
コード例 #3
0
ファイル: Parser.cs プロジェクト: kwood/ExchangeApi
        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));
        }