Beispiel #1
0
        private async Task <CallResult <bool> > Authenticate(SocketSubscription subscription)
        {
            if (authProvider == null)
            {
                return(new CallResult <bool>(false, new NoApiCredentialsError()));
            }

            var request = new CoinExSocketRequest(ServerSubject, AuthenticateAction, true, GetAuthParameters())
            {
                Id = NextId()
            };

            var waitTask = subscription.WaitForEvent(AuthenticationEvent, request.Id.ToString(), subResponseTimeout);

            Send(subscription.Socket, request);
            var authResult = await waitTask.ConfigureAwait(false);

            if (!authResult.Success)
            {
                var closeTask = subscription.Close();
                return(new CallResult <bool>(false, authResult.Error));
            }

            return(new CallResult <bool>(true, null));
        }
        private async Task <CallResult <bool> > Authenticate(SocketSubscription subscription)
        {
            if (authProvider == null)
            {
                return(new CallResult <bool>(false, new NoApiCredentialsError()));
            }

            var authParams  = authProvider.AddAuthenticationToParameters(baseAddressAuthenticated, Constants.GetMethod, new Dictionary <string, object>(), true);
            var authObjects = new HuobiAuthenticationRequest
            {
                AccessKeyId      = authProvider.Credentials.Key.GetString(),
                Operation        = "auth",
                SignatureMethod  = (string)authParams["SignatureMethod"],
                SignatureVersion = authParams["SignatureVersion"].ToString(),
                Timestamp        = (string)authParams["Timestamp"],
                Signature        = (string)authParams["Signature"]
            };

            Send(subscription.Socket, authObjects);

            var authResult = await subscription.WaitForEvent(AuthenticationEvent, socketResponseTimeout).ConfigureAwait(false);

            if (!authResult.Success)
            {
                await subscription.Close().ConfigureAwait(false);

                return(new CallResult <bool>(false, authResult.Error));
            }

            return(new CallResult <bool>(true, null));
        }
        protected override bool SocketReconnect(SocketSubscription subscription, TimeSpan disconnectedTime)
        {
            var request = (HuobiRequest)subscription.Request;

            if (request.Signed)
            {
                if (!Authenticate(subscription).Result.Success)
                {
                    return(false);
                }
            }

            Send(subscription.Socket, request);

            return(subscription.WaitForEvent(SubscriptionEvent, socketResponseTimeout).Result.Success);
        }
Beispiel #4
0
        private async Task <CallResult <UpdateSubscription> > Subscribe(SocketSubscription subscription, CoinExSocketRequest request)
        {
            request.Id = NextId();
            var waitTask = subscription.WaitForEvent(SubscriptionEvent, request.Id.ToString(), subResponseTimeout);

            Send(subscription.Socket, request);

            var subResult = await waitTask.ConfigureAwait(false);

            if (!subResult.Success)
            {
                await subscription.Close().ConfigureAwait(false);

                return(new CallResult <UpdateSubscription>(null, subResult.Error));
            }

            subscription.Request = request;
            subscription.Socket.ShouldReconnect = true;
            return(new CallResult <UpdateSubscription>(new UpdateSubscription(subscription), null));
        }