コード例 #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
ファイル: Clone.cs プロジェクト: valmac/FastBinaryEncoding
        public void CopyStructs()
        {
            // 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));

            // Clone the account
            proto.Account account2 = account1.Clone();

            // Clear the source account
            account1 = proto.Account.Default;

            Assert.True(account2.id == 1);
            Assert.True(account2.name == "Test");
            Assert.True(account2.state.HasFlags(proto.State.good));
            Assert.True(account2.wallet.currency == "USD");
            Assert.True(account2.wallet.amount == 1000.0);
            Assert.True(account2.asset.HasValue);
            Assert.True(account2.asset.Value.currency == "EUR");
            Assert.True(account2.asset.Value.amount == 100.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 == proto.OrderSide.buy);
            Assert.True(account2.orders[0].type == proto.OrderType.market);
            Assert.True(account2.orders[0].price == 1.23456);
            Assert.True(account2.orders[0].volume == 1000.0);
            Assert.True(account2.orders[1].id == 2);
            Assert.True(account2.orders[1].symbol == "EURUSD");
            Assert.True(account2.orders[1].side == proto.OrderSide.sell);
            Assert.True(account2.orders[1].type == proto.OrderType.limit);
            Assert.True(account2.orders[1].price == 1.0);
            Assert.True(account2.orders[1].volume == 100.0);
            Assert.True(account2.orders[2].id == 3);
            Assert.True(account2.orders[2].symbol == "EURUSD");
            Assert.True(account2.orders[2].side == proto.OrderSide.buy);
            Assert.True(account2.orders[2].type == proto.OrderType.stop);
            Assert.True(account2.orders[2].price == 1.5);
            Assert.True(account2.orders[2].volume == 10.0);
        }
コード例 #3
0
        public SerializationJson()
        {
            // 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 JSON string
            _json = _account.ToJson();

            // Deserialize the account from the JSON string
            _account = proto.Account.FromJson(_json);
        }
コード例 #4
0
        public SendReceive()
        {
            // 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));

            _sender1 = new MySender1();
            _sender1.Send(_account);

            _sender2 = new MySender2();
            _sender2.Send(_account);

            _receiver = new MyReceiver();
            _receiver.Receive(_sender2.Buffer);
        }
コード例 #5
0
 protected override void OnReceive(proto.Account value)
 {
     _account = true;
 }
コード例 #6
0
 protected override void OnReceive(proto.Account value)
 {
 }
コード例 #7
0
 public void Deserialize()
 {
     // Deserialize the account from the JSON string
     _account = proto.Account.FromJson(_json);
 }