コード例 #1
0
        //If basicInfoOnly flag is set to true, RecentTrades & OrderBook (top 20) won't be loaded
        //This can be used to reduce unnecessary memory usage
        private static CryptsyMarketInfo ReadFromJObject(JObject o, bool basicInfoOnly = false)
        {
            var marketInfo = new CryptsyMarketInfo()
            {
                MarketId              = o.Value <Int64>("marketid"),
                Label                 = o.Value <string>("label"),
                PrimaryCurrencyCode   = o.Value <string>("primarycode"),
                PrimaryCurrencyName   = o.Value <string>("primaryname"),
                SecondaryCurrencyCode = o.Value <string>("secondarycode"),
                SecondaryCurrencyName = o.Value <string>("secondaryname"),
                Volume                = o.Value <decimal>("volume"),
                //CreationTimeUTC = TimeZoneInfo.ConvertTime(o.Value<DateTime>("created"), TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"), TimeZoneInfo.Utc)
            };

            if (!basicInfoOnly)
            {
                marketInfo.RecentTrades = new List <CryptsyTrade>();
                marketInfo.OrderBook    = new Exchange.Cryptsy.CryptsyOrderBook();

                foreach (var t in o["recenttrades"])
                {
                    CryptsyTrade trade = CryptsyTrade.ReadFromJObject(t as JObject);
                    marketInfo.RecentTrades.Add(trade);
                    marketInfo.LastTrade = trade;
                }

                //orderbook is returnd as array of markets (with only the requested market)
                marketInfo.OrderBook = Cryptsy.CryptsyOrderBook.ReadFromJObject(o, marketInfo.MarketId);
            }

            return(marketInfo);
        }
コード例 #2
0
        public static CryptsyTrade ReadFromJObject(JObject o)
        {
            if (o == null)
            {
                return(null);
            }

            /*
             * Method: mytrades (authenticated)
             * Present properties: tradeid, tradetype, datetime, tradeprice, quantity, total, fee, initiate_ordertype, order_id
             *
             * Method: markettrades (authenticated)
             * Present properties: tradeid, datetime, tradeprice, quantity, total, initiate_ordertype
             *
             * Method: singlemarketdata (public)
             * Present properties: id, time, price, quantity, total
             *
             */

            var trade = new CryptsyTrade
            {
                TradeId     = o.Value <Int64?>("id") ?? o.Value <Int64>("tradeid"),
                DateTimeUtc = TimeZoneInfo.ConvertTime(o.Value <DateTime?>("time") ?? o.Value <DateTime>("datetime"), TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"), TimeZoneInfo.Utc),
                UnitPrice   = o.Value <decimal>("tradeprice"),
                Quantity    = o.Value <decimal>("quantity"),
                Total       = o.Value <decimal>("total"),
                Fee         = o.Value <decimal?>("fee") ?? 0,

                //If not present: UNKNOWN; if present: Buy or Sell
                InitiateOrderType = o.Value <String>("initiate_ordertype") == null ? CryptsyOrderType.Na : (o.Value <String>("initiate_ordertype").ToLower() == "buy" ? CryptsyOrderType.Buy : CryptsyOrderType.Sell),
                TradeType         = o.Value <String>("tradetype") == null ? CryptsyOrderType.Na : (o.Value <String>("tradetype").ToLower() == "buy" ? CryptsyOrderType.Buy : CryptsyOrderType.Sell),
                OrderId           = o.Value <Int64?>("order_id") ?? -1
            };

            try
            {
                trade.MarketId = o.Value <int?>("marketid");
            }
            catch
            {
                // ignored
            }

            return(trade);
        }