Пример #1
0
        /// <summary>
        ///     Parse a JToken into a ticker
        /// </summary>
        /// <param name="token">Token</param>
        /// <param name="symbol"></param>
        /// <param name="formatter"></param>
        /// <returns>ExchangeTicker</returns>
        internal static ExchangeTicker ParseTicker(this JToken token, Symbol symbol, TickerFormatter formatter)
        {
            if (token == null || !token.HasValues)
            {
                return(null);
            }

            var last = token[formatter.LastKey].ConvertInvariant <decimal>();

            token.ParseVolumes(formatter.VolumeFormatter,
                               last,
                               out var baseCurrencyVolume,
                               out var quoteCurrencyVolume);

            DateTime date = token.ParseDatetime(formatter.TimestampFormatter);

            decimal?ask = null;
            decimal?bid = null;

            token.ParseAskBid(formatter.AskBidFormatter, ref ask, ref bid);

            var ticker = new ExchangeTicker
            {
                Symbol              = symbol,
                Ask                 = ask,
                Bid                 = bid,
                Id                  = token[formatter.IdKey] == null ? null : token[formatter.IdKey].ToStringInvariant(),
                Last                = last,
                BaseCurrencyVolume  = baseCurrencyVolume,
                QuoteCurrencyVolume = quoteCurrencyVolume,
                DateTime            = date
            };

            return(ticker);
        }
Пример #2
0
        private TickerFormatter GetTickerFormatter(FormatterTypeEnum type)
        {
            /* ALL
             *  {"open":0.008545,"close":0.008656,"low":0.008088,"high":0.009388,"amount":88056.1860,
             *  "count":16077,"vol":771.7975953754,"symbol":"ltcbtc"}
             */

            /*single
             *{"id":1499225271,"ts":1499225271000,"close":1885.0000,"open":1960.0000,"high":1985.0000,"low":1856.0000,
             * "amount":81486.2926,"count":42122,"vol":157052744.85708200,"ask":[1885.0000,21.8804],"bid":[1884.0000,1.6702]}
             */

            /*websocket
             *"amount":12224.2922,"open":9790.52,"close":10195.00,"high":10300.00,"ts":1494496390000,
             * "id":1494496390,"count":15195,"low":9657.00,"vol":121906001.754751
             */

            var result = new TickerFormatter
            {
                LastKey         = "close",
                VolumeFormatter = new VolumeFormatter
                {
                    BaseVolumeKey  = "amount",
                    QuoteVolumeKey = "vol"
                }
            };

            if (type != FormatterTypeEnum.All)
            {
                result.TimestampFormatter = new TimestampFormatter
                {
                    TimestampKey  = "ts",
                    TimestampType = CurrentTimestampType
                };

                result.IdKey = "id";

                if (type == FormatterTypeEnum.Signle)
                {
                    result.AskBidFormatter = new AskBidFormatter
                    {
                        AskKey = "ask",
                        BidKey = "bid"
                    };
                }
            }

            return(result);
        }