示例#1
0
        public async Task SendMessage(ProtoMessage message)
        {
            CheckIsDisposed();

            try
            {
                var messageByte = message.ToByteArray();

                var length = BitConverter.GetBytes(messageByte.Length).Reverse().ToArray();

                LastSentMessageTime = DateTime.Now;

                await Write(messageByte, length);
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception ex)
            {
                if (!Streams.SenderExceptionStream.Observers.Any())
                {
                    throw;
                }

                Streams.OnSenderException(ex);
            }
        }
示例#2
0
        private void Transmit(ProtoMessage msg)
        {
            var msgByteArray = msg.ToByteArray();

            byte[] length = BitConverter.GetBytes(msgByteArray.Length).Reverse().ToArray();
            _apiSocket.Write(length);
            _apiSocket.Write(msgByteArray);
        }
示例#3
0
        private void Transmit(ProtoMessage msg, bool log = true)
        {
            if (log)
            {
                txtMessages.Text += "Send: " + OpenApiMessagesPresentation.ToString(msg);
                txtMessages.Text += Environment.NewLine;
            }
            var msgByteArray = msg.ToByteArray();

            byte[] length = BitConverter.GetBytes(msgByteArray.Length).Reverse().ToArray();
            _apiSocket.Write(length);
            _apiSocket.Write(msgByteArray);
        }
示例#4
0
        private void Transmit()
        {
            while (!isShutdown)
            {
                if (_trasmitQueue.Count() > 0)
                {
                    //get the next message to submit
                    ProtoMessage msg = _trasmitQueue.Dequeue();

                    //Sends the Proto message
                    var    msgByteArray = msg.ToByteArray();
                    byte[] length       = BitConverter.GetBytes(msgByteArray.Length).Reverse().ToArray();
                    _apiSocket.Write(length);
                    _apiSocket.Write(msgByteArray);


                    switch ((ProtoOAPayloadType)msg.PayloadType)
                    {
                    case ProtoOAPayloadType.PROTO_OA_APPLICATION_AUTH_REQ:
                        MessageHandler?.Invoke("Authorising App.");
                        break;

                    case ProtoOAPayloadType.PROTO_OA_ACCOUNT_AUTH_REQ:
                        var accAuth = ProtoOAAccountAuthReq.CreateBuilder().MergeFrom(msg.Payload).Build();
                        MessageHandler?.Invoke("Authorising account " + Users[accAuth.AccessToken].AccountId);
                        break;

                    case ProtoOAPayloadType.PROTO_OA_SUBSCRIBE_SPOTS_REQ:
                        var spotReq = ProtoOASubscribeSpotsReq.CreateBuilder().MergeFrom(msg.Payload).Build();
                        //get the associated user
                        UserConfig config = Users.Where(x => x.Value.AccountId == spotReq.CtidTraderAccountId).Select(x => x.Value).FirstOrDefault();
                        //get the associated symbol
                        Symbol symbol = config.Symbols.Where(x => x.Id == spotReq.GetSymbolId(0)).FirstOrDefault();
                        //Notify the spot request has been sent
                        SymbolTickRequestHandler?.Invoke(symbol);
                        break;
                    }
                }
                else if (!_heartbeatTimer.Enabled)
                {
                    //start the heartbeat timer
                    _heartbeatTimer.Enabled = true;
                    _heartbeatTimer.Start();
                }

                //Wait 2.01 seconds between each message as to not exceed the 30 messages per minute restriction
                Thread.Sleep(2010);
            }
        }
示例#5
0
        public async Task SendMessage(ProtoMessage message)
        {
            try
            {
                var messageByte = message.ToByteArray();

                var length = BitConverter.GetBytes(messageByte.Length);

                Array.Reverse(length);

                LastSentMessageTime = DateTime.Now;

                await Write(messageByte, length);
            }
            catch (Exception ex)
            {
                OnError(ex);
            }
        }
示例#6
0
        public void SendMessage(ProtoMessage message)
        {
            Debug.WriteLine("request type: {0}", message.MsgCase);
            Debug.WriteLine(message);
            byte[] bufferForMessage = message.ToByteArray();
            int    messageLength    = bufferForMessage.Length;

            byte[] bufferForLength = BitConverter.GetBytes(messageLength);

            byte[] temp = new byte[4];
            for (int i = 0; i < 4; i++)
            {
                temp[3 - i] = bufferForLength[i];
            }
            bufferForLength = temp;
            byte[] package = new byte[bufferForLength.Length + bufferForMessage.Length];
            Debug.WriteLine(messageLength);
            Debug.WriteLine(bufferForLength.Length);
            System.Buffer.BlockCopy(bufferForLength, 0, package, 0, bufferForLength.Length);
            System.Buffer.BlockCopy(bufferForMessage, 0, package, bufferForLength.Length, bufferForMessage.Length);
            client.BeginSend(package, 0, package.Length, 0, new AsyncCallback(sendCallBack), client);
        }