示例#1
0
        private void Process_Application_Auth_Res()
        {
            ProtoOAApplicationAuthRes args = Serializer.Deserialize <ProtoOAApplicationAuthRes>(_processorMemoryStream);

            Log.Info("ProtoOAApplicationAuthRes");

            Send(Get_Accounts_By_Access_Token_Req(_accessToken));

            OnApplicationAuthResReceived?.Invoke(args);
        }
 public ProtoOAApplicationAuthRes GetApplicationAuthorizationResponse(byte[] msg = null)
 {
     return(ProtoOAApplicationAuthRes.CreateBuilder().MergeFrom(GetPayload(msg)).Build());
 }
 public ProtoMessage CreateAssetClassListResponse(string clientMsgId = null)
 {
     return(CreateMessage((uint)ProtoOAPayloadType.PROTO_OA_ASSET_LIST_RES, ProtoOAApplicationAuthRes.CreateBuilder().Build().ToByteString(), clientMsgId));
 }
 public ProtoMessage CreateAppAuthorizationResponse(string clientMsgId = null)
 {
     return(CreateMessage((uint)ProtoOAPayloadType.PROTO_OA_APPLICATION_AUTH_RES, ProtoOAApplicationAuthRes.CreateBuilder().Build().ToByteString(), clientMsgId));
 }
        // listener thread
        private void Listen(SslStream sslStream, Queue messagesQueue)
        {
            isShutdown = false;
            while (!isShutdown)
            {
                Thread.Sleep(1);

                byte[] _length   = new byte[sizeof(int)];
                int    readBytes = 0;
                do
                {
                    Thread.Sleep(0);
                    readBytes += sslStream.Read(_length, readBytes, _length.Length - readBytes);
                } while (readBytes < _length.Length);

                int length = BitConverter.ToInt32(_length.Reverse().ToArray(), 0);
                if (length <= 0)
                {
                    continue;
                }

                if (length > MaxMessageSize)
                {
                    string exceptionMsg = "Message length " + length.ToString() + " is out of range (0 - " + MaxMessageSize.ToString() + ")";
                    throw new System.IndexOutOfRangeException();
                }

                byte[] _message = new byte[length];
                readBytes = 0;
                do
                {
                    Thread.Sleep(0);
                    readBytes += sslStream.Read(_message, readBytes, _message.Length - readBytes);
                } while (readBytes < length);
                var msgFactory   = new OpenApiMessagesFactory();
                var protoMessage = msgFactory.GetMessage(_message);
                messagesQueue.Enqueue("Received: " + OpenApiMessagesPresentation.ToString(protoMessage));
                switch ((ProtoOAPayloadType)protoMessage.PayloadType)
                {
                case ProtoOAPayloadType.PROTO_OA_APPLICATION_AUTH_RES:
                    ProtoOAApplicationAuthRes Res = msgFactory.GetApplicationAuthorizationResponse(_message);
                    Console.WriteLine(Res.ToString());
                    break;

                case ProtoOAPayloadType.PROTO_OA_EXECUTION_EVENT:
                    var _payload_msg = msgFactory.GetExecutionEvent(_message);
                    if (_payload_msg.HasOrder)
                    {
                        testOrderId = _payload_msg.Order.OrderId;
                    }
                    if (_payload_msg.HasPosition)
                    {
                        testPositionId = _payload_msg.Position.PositionId;
                    }
                    break;

                case ProtoOAPayloadType.PROTO_OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_RES:
                    var _accounts_list = ProtoOAGetAccountListByAccessTokenRes.CreateBuilder().MergeFrom(protoMessage.Payload).Build();
                    _accounts = _accounts_list.CtidTraderAccountList;

                    break;

                case ProtoOAPayloadType.PROTO_OA_TRADER_RES:
                    var trader = ProtoOATraderRes.CreateBuilder().MergeFrom(protoMessage.Payload).Build();
                    _traders.Add(trader.Trader);
                    break;

                case ProtoOAPayloadType.PROTO_OA_RECONCILE_RES:
                    var _reconcile_list = ProtoOAReconcileRes.CreateBuilder().MergeFrom(protoMessage.Payload).Build();
                    break;

                default:
                    break;
                }
                ;
            }
        }
示例#6
0
        private void OnApplicationAuthResponse(ProtoOAApplicationAuthRes e, string clientMsgId)
        {
            var streamMessage = new StreamMessage <ProtoOAApplicationAuthRes>(e, clientMsgId);

            _applicationAuthResponseStream.OnNext(streamMessage);
        }