Пример #1
0
        public static void Main()
        {
            // Create a new account with some orders
            var account = proto.Account.Default;

            account.id              = 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.AccountModel();

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

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

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

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

            // Show account content
            Console.WriteLine();
            Console.WriteLine(account);
        }
Пример #2
0
        public Serialization()
        {
            // 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.AccountModel();
            _writer.Serialize(_account);
            Debug.Assert(_writer.Verify());

            // Deserialize the account from the FBE stream
            _reader = new FBE.proto.AccountModel();
            _reader.Attach(_writer.Buffer);
            Debug.Assert(_reader.Verify());
            _reader.Deserialize(out _account);
        }
Пример #3
0
        public void Serialize()
        {
            // Reset FBE stream
            _writer.Reset();

            // Serialize the account to the FBE stream
            _writer.Serialize(_account);
        }
Пример #4
0
        public void ExtendingOldNew()
        {
            // Create a new account with some orders
            var account1 = proto.Account.Default;

            account1.id              = 1;
            account1.name            = "Test";
            account1.state           = proto.State.good;
            account1.wallet.currency = "USD";
            account1.wallet.amount   = 1000.0;
            account1.asset           = new proto.Balance("EUR", 100.0);
            account1.orders.Add(new proto.Order(1, "EURUSD", proto.OrderSide.buy, proto.OrderType.market, 1.23456, 1000.0));
            account1.orders.Add(new proto.Order(2, "EURUSD", proto.OrderSide.sell, proto.OrderType.limit, 1.0, 100.0));
            account1.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.AccountModel();

            Assert.True(writer.model.FBEOffset == 4);
            long serialized = writer.Serialize(account1);

            Assert.True(serialized == writer.Buffer.Size);
            Assert.True(writer.Verify());
            writer.Next(serialized);
            Assert.True(writer.model.FBEOffset == (4 + writer.Buffer.Size));

            // Check the serialized FBE size
            Assert.True(writer.Buffer.Size == 252);

            // Deserialize the account from the FBE stream
            var reader = new FBE.protoex.AccountModel();

            Assert.True(reader.model.FBEOffset == 4);
            reader.Attach(writer.Buffer);
            Assert.True(reader.Verify());
            long deserialized = reader.Deserialize(out var account2);

            Assert.True(deserialized == reader.Buffer.Size);
            reader.Next(deserialized);
            Assert.True(reader.model.FBEOffset == (4 + reader.Buffer.Size));

            Assert.True(account2.id == 1);
            Assert.True(account2.name == "Test");
            Assert.True(account2.state == protoex.StateEx.good);
            Assert.True(account2.wallet.parent.currency == "USD");
            Assert.True(account2.wallet.parent.amount == 1000.0);
            Assert.True(account2.wallet.locked == 0.0);
            Assert.True(account2.asset.HasValue);
            Assert.True(account2.asset.Value.parent.currency == "EUR");
            Assert.True(account2.asset.Value.parent.amount == 100.0);
            Assert.True(account2.asset.Value.locked == 0.0);
            Assert.True(account2.orders.Count == 3);
            Assert.True(account2.orders[0].id == 1);
            Assert.True(account2.orders[0].symbol == "EURUSD");
            Assert.True(account2.orders[0].side == protoex.OrderSide.buy);
            Assert.True(account2.orders[0].type == protoex.OrderType.market);
            Assert.True(account2.orders[0].price == 1.23456);
            Assert.True(account2.orders[0].volume == 1000.0);
            Assert.True(account2.orders[0].tp == 10.0);
            Assert.True(account2.orders[0].sl == -10.0);
            Assert.True(account2.orders[1].id == 2);
            Assert.True(account2.orders[1].symbol == "EURUSD");
            Assert.True(account2.orders[1].side == protoex.OrderSide.sell);
            Assert.True(account2.orders[1].type == protoex.OrderType.limit);
            Assert.True(account2.orders[1].price == 1.0);
            Assert.True(account2.orders[1].volume == 100.0);
            Assert.True(account2.orders[1].tp == 10.0);
            Assert.True(account2.orders[1].sl == -10.0);
            Assert.True(account2.orders[2].id == 3);
            Assert.True(account2.orders[2].symbol == "EURUSD");
            Assert.True(account2.orders[2].side == protoex.OrderSide.buy);
            Assert.True(account2.orders[2].type == protoex.OrderType.stop);
            Assert.True(account2.orders[2].price == 1.5);
            Assert.True(account2.orders[2].volume == 10.0);
            Assert.True(account2.orders[2].tp == 10.0);
            Assert.True(account2.orders[2].sl == -10.0);
        }