Пример #1
0
        public SerializationFinal()
        {
            // Create a new account with some orders
            _account                 = proto.Account.Default;
            _account.uid             = 1;
            _account.name            = "Test";
            _account.state           = proto.State.good;
            _account.wallet.currency = "USD";
            _account.wallet.amount   = 1000.0;
            _account.asset           = new proto.Balance("EUR", 100.0);
            _account.orders.Add(new proto.Order(1, "EURUSD", proto.OrderSide.buy, proto.OrderType.market, 1.23456, 1000.0));
            _account.orders.Add(new proto.Order(2, "EURUSD", proto.OrderSide.sell, proto.OrderType.limit, 1.0, 100.0));
            _account.orders.Add(new proto.Order(3, "EURUSD", proto.OrderSide.buy, proto.OrderType.stop, 1.5, 10.0));

            // Serialize the account to the FBE stream
            _writer = new FBE.proto.AccountFinalModel();
            _writer.Serialize(_account);
            Debug.Assert(_writer.Verify());

            // Deserialize the account from the FBE stream
            _reader = new FBE.proto.AccountFinalModel();
            _reader.Attach(_writer.Buffer);
            Debug.Assert(_reader.Verify());
            _reader.Deserialize(out _account);
        }
Пример #2
0
        public static void Main()
        {
            // Create a new account with some orders
            var account = proto.Account.Default;

            account.uid             = 1;
            account.name            = "Test";
            account.state           = proto.State.good;
            account.wallet.currency = "USD";
            account.wallet.amount   = 1000.0;
            account.asset           = new proto.Balance("EUR", 100.0);
            account.orders.Add(new proto.Order(1, "EURUSD", proto.OrderSide.buy, proto.OrderType.market, 1.23456, 1000.0));
            account.orders.Add(new proto.Order(2, "EURUSD", proto.OrderSide.sell, proto.OrderType.limit, 1.0, 100.0));
            account.orders.Add(new proto.Order(3, "EURUSD", proto.OrderSide.buy, proto.OrderType.stop, 1.5, 10.0));

            // Serialize the account to the FBE stream
            var writer = new FBE.proto.AccountFinalModel();

            writer.Serialize(account);
            Debug.Assert(writer.Verify());

            // Show the serialized FBE size
            Console.WriteLine($"FBE final size: {writer.Buffer.Size}");

            // Deserialize the account from the FBE stream
            var reader = new FBE.proto.AccountFinalModel();

            reader.Attach(writer.Buffer);
            Debug.Assert(reader.Verify());
            reader.Deserialize(out account);

            // Show account content
            Console.WriteLine();
            Console.WriteLine(account);
        }