Esempio n. 1
0
        /// <summary>
        /// Subscribe to updates of account balances
        /// </summary>
        /// <returns></returns>
        public async Task <CallResult <UpdateSubscription> > SubscribeToAccountUpdatesAsync(Action <HuobiAccountUpdate> onAccountUpdate)
        {
            var request         = new HuobiAuthenticatedSubscribeRequest("accounts.update#1");
            var internalHandler = new Action <JToken>(data =>
            {
                DeserializeAndInvoke(data, onAccountUpdate);
            });

            return(await Subscribe(request, null, true, internalHandler).ConfigureAwait(false));
        }
Esempio n. 2
0
        /// <summary>
        /// Subscribe to updates of orders
        /// </summary>
        /// <param name="symbol">Subscribe on a specific symbol</param>
        /// <param name="onOrderSubmitted">Event handler for the order submitted event</param>
        /// <param name="onOrderMatched">Event handler for the order matched event</param>
        /// <param name="onOrderCancellation">Event handler for the order cancelled event</param>
        /// <param name="onConditionalOrderTriggerFailure">Event handler for the conditional order trigger failed event</param>
        /// <param name="onConditionalOrderCancelled">Event handler for the condition order cancelled event</param>
        /// <returns></returns>
        public async Task <CallResult <UpdateSubscription> > SubscribeToOrderUpdatesAsync(
            string?symbol = null,
            Action <HuobiSubmittedOrderUpdate>?onOrderSubmitted    = null,
            Action <HuobiMatchedOrderUpdate>?onOrderMatched        = null,
            Action <HuobiCancelledOrderUpdate>?onOrderCancellation = null,
            Action <HuobiTriggerFailureOrderUpdate>?onConditionalOrderTriggerFailure = null,
            Action <HuobiOrderUpdate>?onConditionalOrderCancelled = null)
        {
            symbol = symbol?.ValidateHuobiSymbol();
            var request         = new HuobiAuthenticatedSubscribeRequest($"orders#{symbol ?? "*"}");
            var internalHandler = new Action <JToken>(data =>
            {
                var eventType = (string)data["data"]["eventType"];
                if (eventType == "trigger")
                {
                    DeserializeAndInvoke(data, onConditionalOrderTriggerFailure);
                }

                else if (eventType == "deletion")
                {
                    DeserializeAndInvoke(data, onConditionalOrderCancelled);
                }

                else if (eventType == "creation")
                {
                    DeserializeAndInvoke(data, onOrderSubmitted);
                }

                else if (eventType == "trade")
                {
                    DeserializeAndInvoke(data, onOrderMatched);
                }

                else if (eventType == "cancellation")
                {
                    DeserializeAndInvoke(data, onOrderCancellation);
                }
                else
                {
                    log.Write(LogVerbosity.Warning, "Unknown order event type: " + eventType);
                }
            });

            return(await Subscribe(request, null, true, internalHandler).ConfigureAwait(false));
        }
Esempio n. 3
0
        /// <summary>
        /// Subscribe to updates of orders
        /// </summary>
        /// <param name="symbol">Subscribe on a specific symbol</param>
        /// <param name="onOrderSubmitted">Event handler for the order submitted event</param>
        /// <param name="onOrderMatched">Event handler for the order matched event</param>
        /// <param name="onOrderCancellation">Event handler for the order cancelled event</param>
        /// <param name="onConditionalOrderTriggerFailure">Event handler for the conditional order trigger failed event</param>
        /// <param name="onConditionalOrderCancelled">Event handler for the condition order cancelled event</param>
        /// <returns></returns>
        public async Task <CallResult <UpdateSubscription> > SubscribeToOrderUpdatesAsync(
            string?symbol = null,
            Action <DataEvent <HuobiSubmittedOrderUpdate> >?onOrderSubmitted    = null,
            Action <DataEvent <HuobiMatchedOrderUpdate> >?onOrderMatched        = null,
            Action <DataEvent <HuobiCancelledOrderUpdate> >?onOrderCancellation = null,
            Action <DataEvent <HuobiTriggerFailureOrderUpdate> >?onConditionalOrderTriggerFailure = null,
            Action <DataEvent <HuobiOrderUpdate> >?onConditionalOrderCancelled = null)
        {
            symbol = symbol?.ValidateHuobiSymbol();
            var request         = new HuobiAuthenticatedSubscribeRequest($"orders#{symbol ?? "*"}");
            var internalHandler = new Action <DataEvent <JToken> >(data =>
            {
                if (data.Data["data"] == null || data.Data["data"] !["eventType"] == null)
                {
                    log.Write(LogLevel.Warning, "Invalid order update data: " + data);
                    return;
                }

                var eventType = data.Data["data"] !["eventType"]?.ToString();
Esempio n. 4
0
        /// <summary>
        /// Subscribe to detailed order matched/cancelled updates
        /// </summary>
        /// <param name="symbol">Subscribe to a specific symbol</param>
        /// <param name="onOrderMatch">Event handler for the order matched event</param>
        /// <param name="onOrderCancel">Event handler for the order cancelled event</param>
        /// <returns></returns>
        public async Task <CallResult <UpdateSubscription> > SubscribeToOrderDetailsUpdatesAsync(string?symbol = null, Action <HuobiTradeUpdate>?onOrderMatch = null, Action <HuobiOrderCancellationUpdate>?onOrderCancel = null)
        {
            var request         = new HuobiAuthenticatedSubscribeRequest($"trade.clearing#{symbol ?? "*"}#1");
            var internalHandler = new Action <JToken>(data =>
            {
                var eventType = (string)data["data"]["eventType"];
                if (eventType == "trade")
                {
                    DeserializeAndInvoke(data, onOrderMatch);
                }
                else if (eventType == "cancellation")
                {
                    DeserializeAndInvoke(data, onOrderCancel);
                }
                else
                {
                    log.Write(LogVerbosity.Warning, "Unknown order details event type: " + eventType);
                }
            });

            return(await Subscribe(request, null, true, internalHandler).ConfigureAwait(false));
        }