Пример #1
0
        /// <summary>
        /// This method is invoked by KrakenJsonConverter to map the fields of the "result" portion of KrakenResponse
        /// </summary>
        /// <param name="jo"></param>
        /// <returns></returns>
        public TradeData MapFields(JObject jo)
        {
            var jp   = jo.Properties().First();
            var data = jp.Value.ToObject <object[][]>();

            var td = new TradeData();

            td.PairName = jp.Name;

            var entries = new List <Trade>();

            foreach (var trade in data)
            {
                var entry = new Trade();
                entry.Price         = decimal.Parse(trade[0].ToString());
                entry.Volume        = decimal.Parse(trade[1].ToString());
                entry.Time          = FromUnixTime.Create(double.Parse(trade[2].ToString()));
                entry.TradeType     = EnumHelper.GetValueFromDesc <TradeType>(trade[3].ToString());
                entry.MarketOrLimit = EnumHelper.GetValueFromDesc <MarketOrLimit>(trade[4].ToString());
                entry.Miscellaneous = trade[5].ToString();
                entries.Add(entry);
            }
            td.Trades = entries;
            return(td);
        }
Пример #2
0
        public OHLCData MapFields(JObject jo)
        {
            var jp   = jo.Properties().First(c => c.Name.ToLower() != "last");
            var last = jo.Properties().First(c => c.Name == "last");
            var data = jp.Value.ToObject <object[][]>();

            var ohlcData = new OHLCData();

            ohlcData.PairName = jp.Name;
            ohlcData.Last     = last.Value.ToObject <long>();

            var entries = new List <OHLCDataEntry>();

            foreach (var item in data)
            {
                var entry = new OHLCDataEntry();
                entry.Time   = FromUnixTime.Create(double.Parse(item[0].ToString()));
                entry.Open   = decimal.Parse(item[1].ToString());
                entry.High   = decimal.Parse(item[2].ToString());
                entry.Low    = decimal.Parse(item[3].ToString());
                entry.Close  = decimal.Parse(item[4].ToString());
                entry.Vwap   = decimal.Parse(item[5].ToString());
                entry.Volume = decimal.Parse(item[6].ToString());
                entry.Count  = long.Parse(item[7].ToString());
                entries.Add(entry);
            }
            ohlcData.Data = entries;

            return(ohlcData);
        }
Пример #3
0
        private IEnumerable <OrderInfo> GenerateOrderInfo(Dictionary <string, Dictionary <string, object> > data)
        {
            foreach (var entry in data)
            {
                var info = new OrderInfo();

                var refId   = entry.Value["refid"];
                var userref = entry.Value["userref"];
                info.TransactionId = entry.Key;
                info.ReferenceId   = refId != null?refId.ToString() : null;

                info.UserReferenceId = userref != null?userref.ToString() : null;

                info.Status         = EnumHelper.GetValueFromDesc <OrderStatus>(entry.Value["status"].ToString());
                info.OpenTime       = FromUnixTime.Create(double.Parse(entry.Value["opentm"].ToString()));
                info.StartTime      = FromUnixTime.Create(double.Parse(entry.Value["starttm"].ToString()));
                info.ExpireTime     = FromUnixTime.Create(double.Parse(entry.Value["expiretm"].ToString()));
                info.Volume         = decimal.Parse(entry.Value["vol"].ToString());
                info.VolumeExecuted = decimal.Parse(entry.Value["vol_exec"].ToString());
                info.Cost           = decimal.Parse(entry.Value["cost"].ToString());
                info.Fee            = decimal.Parse(entry.Value["fee"].ToString());
                info.Price          = decimal.Parse(entry.Value["price"].ToString());
                info.StopPrice      = entry.Value.ContainsKey("stopprice")
                    ? decimal.Parse(entry.Value["stopprice"].ToString()) : 0;
                info.LimitPrice = entry.Value.ContainsKey("limitprice")
                    ? decimal.Parse(entry.Value["limitprice"].ToString()) : 0;
                info.Misc = entry.Value["misc"].ToString();

                info.Trades = new List <string>();
                if (entry.Value.ContainsKey("trades"))
                {
                    var tObj = entry.Value["trades"] as JToken;
                    info.Trades = tObj.ToObject <string[]>();
                }

                info.CloseTime = entry.Value.ContainsKey("closetm") ? (Nullable <DateTime>)FromUnixTime.Create(double.Parse(entry.Value["closetm"].ToString())) : null;
                info.Reason    = entry.Value.ContainsKey("reason") && entry.Value["reason"] != null
                    ? entry.Value["reason"].ToString() : null;

                var jObj = entry.Value["descr"] as JObject;
                info.DescriptionInfo = jObj.ToObject <OrderDesc>();

                yield return(info);
            }
        }
Пример #4
0
        public OrderBookData MapFields(JObject jo)
        {
            var jp   = jo.Properties().First();
            var data = jp.Value.ToObject <Dictionary <string, object[][]> >();
            var asks = data["asks"];
            var bids = data["bids"];
            var obd  = new OrderBookData();

            obd.PairName = jp.Name;

            var askEntries = new List <OrderBookEntry>();

            foreach (var askEntry in asks)
            {
                var item = new OrderBookEntry();
                item.Price     = decimal.Parse(askEntry[0].ToString());
                item.Volume    = decimal.Parse(askEntry[1].ToString());
                item.TimeStamp = FromUnixTime.Create(double.Parse(askEntry[2].ToString()));
                askEntries.Add(item);
            }

            obd.Asks = askEntries;

            var bidEntries = new List <OrderBookEntry>();

            foreach (var bidEntry in bids)
            {
                var item = new OrderBookEntry();
                item.Price     = decimal.Parse(bidEntry[0].ToString());
                item.Volume    = decimal.Parse(bidEntry[1].ToString());
                item.TimeStamp = FromUnixTime.Create(double.Parse(bidEntry[2].ToString()));
                bidEntries.Add(item);
            }

            obd.Bids = bidEntries;

            return(obd);
        }
Пример #5
0
        public SpreadData MapFields(JObject jo)
        {
            var jp   = jo.Properties().First();
            var data = jp.Value.ToObject <object[][]>();

            var td = new SpreadData();

            td.PairName = jp.Name;

            var entries = new List <SpreadEntry>();

            foreach (var trade in data)
            {
                var entry = new SpreadEntry();
                entry.Time = FromUnixTime.Create(double.Parse(trade[0].ToString()));
                entry.Bid  = decimal.Parse(trade[0].ToString());
                entry.Ask  = decimal.Parse(trade[1].ToString());

                entries.Add(entry);
            }
            td.Data = entries;
            return(td);
        }