public BinaryObj ToBytes()
        {
            var buffer = BinaryObjPool.Checkout(BinaryObj.PresetType.Transaction);

            buffer.bw.Write((short)0);
            buffer.bw.Write(this.dt.ToBinary());
            //if (this.s.Length > SymbolMaxSize) throw new Exception(string.Format("Symbol exceed max length:{0}", SymbolMaxSize));
            //buffer.bw.Write(this.s);
            buffer.bw.Write(this.p.ToString());
            buffer.bw.Write(this.v);
            if (this.bt.Length > BuyOrderIdMaxSize)
            {
                throw new Exception(string.Format("Buy Order ID exceed max length:{0}", BuyOrderIdMaxSize));
            }
            buffer.bw.Write(this.bt);
            if (this.st.Length > SellOrderIdMaxSize)
            {
                throw new Exception(string.Format("Sell Order ID exceed max length:{0}", SellOrderIdMaxSize));
            }
            buffer.bw.Write(this.st);
            if (this.id.Length > TxIdMaxSize)
            {
                throw new Exception(string.Format("Tx ID exceed max length:{0}", TxIdMaxSize));
            }
            buffer.bw.Write(this.id);
            buffer.bw.Write((byte)this.init);
            buffer.lenBw.Write((short)buffer.ms.Position);
            buffer.length = (int)buffer.ms.Position;
            Array.Copy(buffer.lenInBytes, 0, buffer.bytes, 0, 2);
            return(buffer);
        }
Exemple #2
0
        public BinaryObj ToBytes()
        {
            BinaryObj buffer = BinaryObjPool.Checkout(BinaryObj.PresetType.RequestToMatching);

            buffer.bw.Write((short)0);
            buffer.bw.Write((byte)this.type);
            buffer.bw.Write(this.dt.ToBinary());
            buffer.bw.Write((byte)this.order.et);
            buffer.bw.Write((byte)this.order.t);
            //if (this.order.s.Length > OrderSymbolMaxSize) throw new Exception(string.Format("Symbol exceed max length:{0}", OrderSymbolMaxSize));
            //buffer.bw.Write(this.order.s);
            string price = this.order.p.ToString();

            //if (price.Length > OrderPriceMaxSize) throw new Exception(string.Format("Price exceed max length:{0}", OrderPriceMaxSize));
            buffer.bw.Write(price);
            buffer.bw.Write(this.order.v);
            if (this.order.u.Length > OrderReqIdMaxSize)
            {
                throw new Exception(string.Format("User ID exceed max length:{0}", OrderReqIdMaxSize));
            }
            buffer.bw.Write(this.order.u);
            if (this.order.id.Length > OrderIdMaxSize)
            {
                throw new Exception(string.Format("Order ID exceed max length:{0}", OrderIdMaxSize));
            }
            buffer.bw.Write(this.order.id);
            buffer.bw.Write(this.order.fv);
            buffer.lenBw.Write((short)buffer.ms.Position);
            buffer.length = (int)buffer.ms.Position;
            Array.Copy(buffer.lenInBytes, 0, buffer.bytes, 0, 2);
            return(buffer);
        }
        /// <summary>
        /// Thread safe
        /// </summary>
        /// <returns></returns>
        public static BinaryObj ConstructRejectBuffer()
        {
            BinaryObj buffer = BinaryObjPool.Checkout(BinaryObj.PresetType.ProcessOrderResult);

            try
            {
                buffer.bw.Write(false);
                buffer.bw.Write(DateTime.Now.ToBinary());
                buffer.bw.Write((byte)ErrorType.SystemBusy);
                buffer.bw.Write((long)0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            return(buffer);
        }