Esempio n. 1
0
        private static void RunRioClient()
        {
            var configuration = new ClientConfiguration();

            using (var client = CreateClient(configuration))
            {
                client.Connected    += OnClientConnected;
                client.Disconnected += OnClientDisconnected;

                using (client.Subscribe <OrderAckMessage>(OnMessageReceived))
                {
                    var address = Dns.GetHostAddresses(Environment.MachineName).FirstOrDefault(x => x.AddressFamily == AddressFamily.InterNetwork);

                    //  address = IPAddress.Parse("10.0.0.1");
                    //   address = IPAddress.Parse("142.44.202.9");
                    var endPoint = new IPEndPoint(address, _port);
                    client.Connect(endPoint);

                    var instance = new PlaceOrderMessage();

                    var sw = Stopwatch.StartNew();
                    for (var i = 0; i < _messageCount; i++)
                    {
                        instance.Id           = i;
                        instance.InstrumentId = i;
                        instance.Price        = i;
                        instance.Quantity     = i;
                        instance.Side         = (OrderSide)(i % 2);
                        client.Send(instance);
                    }

                    Console.WriteLine($"{_messageCount:N0} in {sw.Elapsed} ({_messageCount / sw.Elapsed.TotalSeconds:N0}m/s)");
                }
            }
        }
 /// <summary>
 /// Create place order message from order base.
 /// </summary>
 /// <param name="placeOrderMessage">Target message. <see cref="PlaceOrderMessage"/></param>
 /// <param name="order">Original order. <see cref="OrderBase"/></param>
 /// <returns></returns>
 static internal PlaceOrderMessage FromOrderBase(this PlaceOrderMessage placeOrderMessage, OrderBase order)
 {
     placeOrderMessage.OrderType = order.Type;
     placeOrderMessage.Side      = order.Side;
     placeOrderMessage.Duration  = order.Duration;
     placeOrderMessage.Leverage  = 1; // Ignored by server.
     placeOrderMessage.Price     = DWConverter.ToProtoDecimal(order.Price);
     placeOrderMessage.Quantity  = DWConverter.ToProtoDecimal(order.Quantity);
     return(placeOrderMessage);
 }
Esempio n. 3
0
        private static void OnMessageReceived(int clientId, PlaceOrderMessage placeOrderMessage)
        {
            if (_receivedMessageCount == 0)
            {
                _sw.Start();
            }

            var stepcount = 100 * 1000;

            if (++_receivedMessageCount % stepcount == 0)
            {
                Console.WriteLine($"{_receivedMessageCount:N0} in {_sw.Elapsed} ({stepcount / _sw.Elapsed.TotalSeconds:N0}m/s)");
                _sw.Restart();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// The method of sending a message to place a limit or market order on the exchange.
        /// </summary>
        /// <param name="order">Sending order. <see cref="OrderBase"/></param>
        /// <returns>True if success else false.</returns>
        public bool PlaceOrder(OrderBase order)
        {
            PlaceOrderMessage placeOrderMessage = new PlaceOrderMessage().FromOrderBase(order);

            return(SendMessage(placeOrderMessage, (uint)order.TargetSymbol.MarketId, order.ClientId));
        }