예제 #1
0
            public object Visit(WebSocket.OrderMatch msg)
            {
                Condition.Requires(msg, "msg").IsNotNull();
                Condition.Requires(msg.MakerOrderId, "msg.MakerOrderId").IsNotNullOrEmpty();
                Condition.Requires(msg.Price, "msg.Price").IsGreaterThan(0m);
                Condition.Requires(msg.Size, "msg.Size").IsGreaterThan(0m);

                Level level;

                if (!_book.TryGetValue(msg.Price, out level))
                {
                    throw new ArgumentException("OrderMatch with price on empty level: " + msg);
                }
                Condition.Requires(level.TotalSize).IsGreaterOrEqual(0m);
                Condition.Requires(level.OrderIds).IsNotEmpty();

                if (!level.OrderIds.Contains(msg.MakerOrderId))
                {
                    throw new ArgumentException("OrderMatch for an order with unknown id: " + msg);
                }
                if (msg.Size > level.TotalSize)
                {
                    throw new ArgumentException("OrderMatch with the size exceeding total level size: " + msg);
                }
                level.TotalSize -= msg.Size;
                _delta.Add(new PriceLevel()
                {
                    Price = msg.Price, SizeDelta = -msg.Size
                });
                _trade.Price = msg.Price;
                _trade.Size  = msg.Size;
                return(null);
            }
예제 #2
0
파일: Parser.cs 프로젝트: kwood/ExchangeApi
 public IMessageIn Visit(OrderMatch msg)
 {
     msg.TradeId      = (long)_data["trade_id"];
     msg.MakerOrderId = (string)_data["maker_order_id"];
     msg.TakerOrderId = (string)_data["taker_order_id"];
     msg.Price        = (decimal)_data["price"];
     msg.Size         = (decimal)_data["size"];
     return(msg);
 }
예제 #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));
        }