Пример #1
0
        /// <summary>
        /// Depth-Five: Back to the previous five entries of depth data,This data is snapshot data per 100 milliseconds.For every 100 milliseconds, we will snapshot and push 5 entries of market depth data of the current order book.
        /// Depth-All: After subscription, 400 entries of market depth data of the order book will first be pushed. Subsequently every 100 milliseconds we will snapshot and push entries that have changed during this time.
        /// </summary>
        /// <param name="symbol">Trading pair symbol</param>
        /// <param name="depth">Order Book Depth</param>
        /// <param name="onData">The handler for updates</param>
        /// <returns></returns>
        public async Task <CallResult <UpdateSubscription> > Spot_SubscribeToTrades_Async(string symbol, OkexSpotOrderBookDepth depth, Action <OkexSpotOrderBook> onData)
        {
            symbol = symbol.ValidateSymbol();
            symbol = symbol.ToUpper(OkexGlobals.OkexCultureInfo);
            var internalHandler = new Action <OkexSocketOrderBookUpdate>(data =>
            {
                foreach (var d in data.Data)
                {
                    d.Symbol   = symbol;
                    d.DataType = depth == OkexSpotOrderBookDepth.Depth5 ? OkexSpotOrderBookDataType.DepthTop5 : data.DataType;
                    onData(d);
                }
            });

            var channel = "depth";

            if (depth == OkexSpotOrderBookDepth.Depth5)
            {
                channel = "depth5";
            }
            else if (depth == OkexSpotOrderBookDepth.Depth400)
            {
                channel = "depth";
            }
            else if (depth == OkexSpotOrderBookDepth.TickByTick)
            {
                channel = "depth_l2_tbt";
            }
            var request = new OkexSocketRequest(OkexSocketOperation.Subscribe, $"spot/{channel}:{symbol}");

            return(await Subscribe(request, null, false, internalHandler).ConfigureAwait(false));
        }
Пример #2
0
 /// <summary>
 /// Depth-Five: Back to the previous five entries of depth data,This data is snapshot data per 100 milliseconds.For every 100 milliseconds, we will snapshot and push 5 entries of market depth data of the current order book.
 /// Depth-All: After subscription, 400 entries of market depth data of the order book will first be pushed. Subsequently every 100 milliseconds we will snapshot and push entries that have changed during this time.
 /// </summary>
 /// <param name="symbol">Trading pair symbol</param>
 /// <param name="depth">Order Book Depth</param>
 /// <param name="onData">The handler for updates</param>
 /// <returns></returns>
 public CallResult <UpdateSubscription> Spot_SubscribeToOrderBook(string symbol, OkexSpotOrderBookDepth depth, Action <OkexSpotOrderBook> onData) => Spot_SubscribeToTrades_Async(symbol, depth, onData).Result;