示例#1
0
        /// <summary>
        /// Gets the order book for a symbol
        /// </summary>
        /// <param name="symbol">The symbol to retrieve depth data for</param>
        /// <param name="mergeDepth">The depth of merging, based on 8 decimals. 1 mergeDepth will merge the last decimals of all order in the book, 7 will merge the last 7 decimals of all orders together</param>
        /// <param name="limit">The limit of results returned</param>
        /// <param name="ct">Cancellation token</param>
        /// <returns>Order book for a symbol</returns>
        public async Task <WebCallResult <CoinExOrderBook> > GetOrderBookAsync(string symbol, int mergeDepth, int?limit = null, CancellationToken ct = default)
        {
            symbol.ValidateCoinExSymbol();
            mergeDepth.ValidateIntBetween(nameof(mergeDepth), 0, 8);
            limit?.ValidateIntValues(nameof(limit), 5, 10, 20);

            var parameters = new Dictionary <string, object>
            {
                { "market", symbol },
                { "merge", CoinExHelpers.MergeDepthIntToString(mergeDepth) }
            };

            parameters.AddOptionalParameter("limit", limit);

            return(await Execute <CoinExOrderBook>(GetUrl(MarketDepthEndpoint), HttpMethod.Get, ct, parameters).ConfigureAwait(false));
        }
示例#2
0
        /// <summary>
        /// Gets the depth data for a market
        /// </summary>
        /// <param name="market">The market to retrieve depth data for</param>
        /// <param name="mergeDepth">The depth of merging, based on 8 decimals. 1 mergeDepth will merge the last decimals of all order in the book, 7 will merge the last 7 decimals of all orders together</param>
        /// <param name="limit">The limit of results returned</param>
        /// <returns>Depth data for a market</returns>
        public async Task <WebCallResult <CoinExMarketDepth> > GetMarketDepthAsync(string market, int mergeDepth, int?limit = null)
        {
            if (mergeDepth < 0 || mergeDepth > 8)
            {
                return(WebCallResult <CoinExMarketDepth> .CreateErrorResult(new ArgumentError("Merge depth needs to be between 0 - 8")));
            }

            if (limit.HasValue && limit != 5 && limit != 10 && limit != 20)
            {
                return(WebCallResult <CoinExMarketDepth> .CreateErrorResult(new ArgumentError("Limit should be 5 / 10 / 20")));
            }

            var parameters = new Dictionary <string, object>
            {
                { "market", market },
                { "merge", CoinExHelpers.MergeDepthIntToString(mergeDepth) }
            };

            parameters.AddOptionalParameter("limit", limit);

            return(await Execute <CoinExMarketDepth>(GetUrl(MarketDepthEndpoint), parameters : parameters).ConfigureAwait(false));
        }
示例#3
0
        /// <summary>
        /// Subscribe to market depth updates for a market
        /// </summary>
        /// <param name="market">The market to receive updates for</param>
        /// <param name="limit">The limit of results to receive in a update</param>
        /// <param name="mergeDepth">The depth of merging, based on 8 decimals. 1 mergeDepth will merge the last decimals of all order in the book, 7 will merge the last 7 decimals of all orders together</param>
        /// <param name="onMessage">Datahandler, receives Param 1[string]: the market name, Param 2[bool]: whether this is a full update, or an update based on the last send data, Param 3[CoinExSocketMarketDepth]: the update data</param>
        /// <returns>A stream subscription. This stream subscription can be used to be notified when the socket is closed and can close this specific stream
        /// using the <see cref="UnsubscribeFromStream(CoinExStreamSubscription)"/> method</returns>
        public async Task <CallResult <CoinExStreamSubscription> > SubscribeToMarketDepthUpdatesAsync(string market, int limit, int mergeDepth, Action <string, bool, CoinExSocketMarketDepth> onMessage)
        {
            if (mergeDepth < 0 || mergeDepth > 8)
            {
                return(new CallResult <CoinExStreamSubscription>(null, new ArgumentError("Merge depth needs to be between 0 - 8")));
            }

            if (limit != 5 && limit != 10 && limit != 20)
            {
                return(new CallResult <CoinExStreamSubscription>(null, new ArgumentError("Limit should be 5 / 10 / 20")));
            }

            var sub = new CoinExDepthSubscription()
            {
                Handler = onMessage, Market = market
            };

            return(await Subscribe(sub, new CoinExSocketRequest(DepthSubject, SubscribeAction, market, limit, CoinExHelpers.MergeDepthIntToString(mergeDepth))).ConfigureAwait(false));
        }
示例#4
0
        /// <summary>
        /// Get a market depth overview
        /// </summary>
        /// <param name="market">The market to get depth for</param>
        /// <param name="limit">The limit of results returned</param>
        /// <param name="mergeDepth">The depth of merging, based on 8 decimals. 1 mergeDepth will merge the last decimals of all order in the book, 7 will merge the last 7 decimals of all orders together</param>
        /// <returns>Depth overview for a market</returns>
        public async Task <CallResult <CoinExSocketMarketDepth> > GetMarketDepthAsync(string market, int limit, int mergeDepth)
        {
            if (mergeDepth < 0 || mergeDepth > 8)
            {
                return(new CallResult <CoinExSocketMarketDepth>(null, new ArgumentError("Merge depth needs to be between 0 - 8")));
            }

            if (limit != 5 && limit != 10 && limit != 20)
            {
                return(new CallResult <CoinExSocketMarketDepth>(null, new ArgumentError("Limit should be 5 / 10 / 20")));
            }

            return(await QueryNewSocket <CoinExSocketMarketDepth>(new CoinExSocketRequest(DepthSubject, QueryAction, market, limit, CoinExHelpers.MergeDepthIntToString(mergeDepth)), false).ConfigureAwait(false));
        }
示例#5
0
        /// <summary>
        /// Subscribe to market depth updates for a market
        /// </summary>
        /// <param name="market">The market to receive updates for</param>
        /// <param name="limit">The limit of results to receive in a update</param>
        /// <param name="mergeDepth">The depth of merging, based on 8 decimals. 1 mergeDepth will merge the last decimals of all order in the book, 7 will merge the last 7 decimals of all orders together</param>
        /// <param name="onMessage">Data handler, receives Param 1[string]: the market name, Param 2[bool]: whether this is a full update, or an update based on the last send data, Param 3[CoinExSocketMarketDepth]: the update data</param>
        /// <returns>A stream subscription. This stream subscription can be used to be notified when the socket is disconnected/reconnected</returns>
        public async Task <CallResult <UpdateSubscription> > SubscribeToMarketDepthUpdatesAsync(string market, int limit, int mergeDepth, Action <string, bool, CoinExSocketMarketDepth> onMessage)
        {
            if (mergeDepth < 0 || mergeDepth > 8)
            {
                return(new CallResult <UpdateSubscription>(null, new ArgumentError("Merge depth needs to be between 0 - 8")));
            }

            if (limit != 5 && limit != 10 && limit != 20)
            {
                return(new CallResult <UpdateSubscription>(null, new ArgumentError("Limit should be 5 / 10 / 20")));
            }

            var internalHandler = new Action <JToken[]>(data =>
            {
                if (data.Length != 3)
                {
                    log.Write(LogVerbosity.Warning, $"Received unexpected data format for depth update. Expected 3 objects, received {data.Length}. Data: " + data.ToString());
                    return;
                }

                var fullUpdate = (bool)data[0];
                var desResult  = Deserialize <CoinExSocketMarketDepth>(data[1], false);
                if (!desResult.Success)
                {
                    log.Write(LogVerbosity.Warning, "Received invalid depth update: " + desResult.Error);
                    return;
                }

                onMessage(market, fullUpdate, desResult.Data);
            });

            return(await Subscribe(new CoinExSocketRequest(NextId(), DepthSubject, SubscribeAction, market, limit, CoinExHelpers.MergeDepthIntToString(mergeDepth)), null, false, internalHandler).ConfigureAwait(false));
        }