protected override async Task OnGetHistoricalTradesAsync(Func <IEnumerable <ExchangeTrade>, bool> callback, string marketSymbol, DateTime?startDate = null, DateTime?endDate = null)
        {
            /*
             * [{
             *  "time": "2014-11-07T22:19:28.578544Z",
             *  "trade_id": 74,
             *  "price": "10.00000000",
             *  "size": "0.01000000",
             *  "side": "buy"
             * }, {
             *  "time": "2014-11-07T01:08:43.642366Z",
             *  "trade_id": 73,
             *  "price": "100.00000000",
             *  "size": "0.01000000",
             *  "side": "sell"
             * }]
             */

            ExchangeHistoricalTradeHelper state = new ExchangeHistoricalTradeHelper(this)
            {
                Callback      = callback,
                EndDate       = endDate,
                ParseFunction = (JToken token) => token.ParseTrade("size", "price", "side", "time", TimestampType.Iso8601, "trade_id"),
                StartDate     = startDate,
                MarketSymbol  = marketSymbol,
                Url           = "/products/[marketSymbol]/trades",
                UrlFunction   = (ExchangeHistoricalTradeHelper _state) =>
                {
                    return(_state.Url + (string.IsNullOrWhiteSpace(cursorBefore) ? string.Empty : "?before=" + cursorBefore.ToStringInvariant()));
                }
            };
            await state.ProcessHistoricalTrades();
        }
        protected override async Task OnGetHistoricalTradesAsync(Func <IEnumerable <ExchangeTrade>, bool> callback, string marketSymbol, DateTime?startDate = null, DateTime?endDate = null)
        {
            /* [ {
            *  "a": 26129,         // Aggregate tradeId
            *       "p": "0.01633102",  // Price
            *       "q": "4.70443515",  // Quantity
            *       "f": 27781,         // First tradeId
            *       "l": 27781,         // Last tradeId
            *       "T": 1498793709153, // Timestamp
            *       "m": true,          // Was the buyer the maker?
            *       "M": true           // Was the trade the best price match?
            *  } ] */

            ExchangeHistoricalTradeHelper state = new ExchangeHistoricalTradeHelper(this)
            {
                Callback          = callback,
                EndDate           = endDate,
                ParseFunction     = (JToken token) => token.ParseTrade("q", "p", "m", "T", TimestampType.UnixMilliseconds, "a", "false"),
                StartDate         = startDate,
                MarketSymbol      = marketSymbol,
                TimestampFunction = (DateTime dt) => ((long)CryptoUtility.UnixTimestampFromDateTimeMilliseconds(dt)).ToStringInvariant(),
                Url = "/aggTrades?symbol=[marketSymbol]&startTime={0}&endTime={1}",
            };
            await state.ProcessHistoricalTrades();
        }
Example #3
0
 protected internal override async Task OnGetHistoricalTradesAsync(Func <IEnumerable <ExchangeTrade>, bool> callback, string symbol, DateTime?startDate = null, DateTime?endDate = null)
 {
     ExchangeHistoricalTradeHelper state = new ExchangeHistoricalTradeHelper(this)
     {
         Callback             = callback,
         DirectionIsBackwards = false,
         EndDate       = endDate,
         ParseFunction = (JToken token) =>
         {
             return(new ExchangeTrade
             {
                 Amount = token["amount"].ConvertInvariant <decimal>(),
                 Price = token["price"].ConvertInvariant <decimal>(),
                 Timestamp = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(token["timestampms"].ConvertInvariant <long>()),
                 Id = token["tid"].ConvertInvariant <long>(),
                 IsBuy = token["type"].ToStringInvariant() == "buy"
             });
         },
         StartDate         = startDate,
         Symbol            = symbol,
         TimestampFunction = (DateTime dt) => ((long)CryptoUtility.UnixTimestampFromDateTimeMilliseconds(dt)).ToStringInvariant(),
         Url = "/trades/[symbol]?limit_trades=100&timestamp={0}"
     };
     await state.ProcessHistoricalTrades();
 }
 protected override async Task OnGetHistoricalTradesAsync(Func <IEnumerable <ExchangeTrade>, bool> callback, string marketSymbol, DateTime?startDate = null, DateTime?endDate = null)
 {
     ExchangeHistoricalTradeHelper state = new ExchangeHistoricalTradeHelper(this)
     {
         Callback             = callback,
         DirectionIsBackwards = false,
         EndDate           = endDate,
         ParseFunction     = (JToken token) => token.ParseTrade("amount", "price", "type", "timestampms", TimestampType.UnixMilliseconds, idKey: "tid"),
         StartDate         = startDate,
         MarketSymbol      = marketSymbol,
         TimestampFunction = (DateTime dt) => ((long)CryptoUtility.UnixTimestampFromDateTimeMilliseconds(dt)).ToStringInvariant(),
         Url = "/trades/[marketSymbol]?limit_trades=100&timestamp={0}"
     };
     await state.ProcessHistoricalTrades();
 }
 protected override async Task OnGetHistoricalTradesAsync(Func <IEnumerable <ExchangeTrade>, bool> callback, string marketSymbol, DateTime?startDate = null, DateTime?endDate = null, int?limit = null)
 {
     // [{"globalTradeID":245321705,"tradeID":11501281,"date":"2017-10-20 17:39:17","type":"buy","rate":"0.01022188","amount":"0.00954454","total":"0.00009756"},...]
     ExchangeHistoricalTradeHelper state = new ExchangeHistoricalTradeHelper(this)
     {
         Callback = callback,
         EndDate  = endDate,
         MillisecondGranularity = false,
         ParseFunction          = (JToken token) => token.ParseTrade("amount", "rate", "type", "date", TimestampType.Iso8601, "globalTradeID"),
         StartDate         = startDate,
         MarketSymbol      = marketSymbol,
         TimestampFunction = (DateTime dt) => ((long)CryptoUtility.UnixTimestampFromDateTimeSeconds(dt)).ToStringInvariant(),
         Url = "/public?command=returnTradeHistory&currencyPair=[marketSymbol]&start={0}&end={1}"
     };
     await state.ProcessHistoricalTrades();
 }
        protected override async Task OnGetHistoricalTradesAsync(Func <IEnumerable <ExchangeTrade>, bool> callback, string symbol, DateTime?startDate = null, DateTime?endDate = null)
        {
            /*
             * [{
             *  "time": "2014-11-07T22:19:28.578544Z",
             *  "trade_id": 74,
             *  "price": "10.00000000",
             *  "size": "0.01000000",
             *  "side": "buy"
             * }, {
             *  "time": "2014-11-07T01:08:43.642366Z",
             *  "trade_id": 73,
             *  "price": "100.00000000",
             *  "size": "0.01000000",
             *  "side": "sell"
             * }]
             */

            ExchangeHistoricalTradeHelper state = new ExchangeHistoricalTradeHelper(this)
            {
                Callback      = callback,
                EndDate       = endDate,
                ParseFunction = (JToken token) =>
                {
                    return(new ExchangeTrade
                    {
                        Amount = token["size"].ConvertInvariant <decimal>(),
                        Id = token["trade_id"].ConvertInvariant <long>(),
                        IsBuy = token["side"].ToStringInvariant() == "buy",
                        Price = token["price"].ConvertInvariant <decimal>(),
                        Timestamp = token["time"].ToDateTimeInvariant()
                    });
                },
                StartDate   = startDate,
                Symbol      = symbol,
                Url         = "/products/[symbol]/trades",
                UrlFunction = (ExchangeHistoricalTradeHelper _state) =>
                {
                    return(_state.Url + (string.IsNullOrWhiteSpace(cursorBefore) ? string.Empty : "?before=" + cursorBefore.ToStringInvariant()));
                }
            };
            await state.ProcessHistoricalTrades();
        }
        protected override async Task OnGetHistoricalTradesAsync(Func <IEnumerable <ExchangeTrade>, bool> callback, string symbol, DateTime?startDate = null, DateTime?endDate = null)
        {
            /* [ {
            *  "a": 26129,         // Aggregate tradeId
            *       "p": "0.01633102",  // Price
            *       "q": "4.70443515",  // Quantity
            *       "f": 27781,         // First tradeId
            *       "l": 27781,         // Last tradeId
            *       "T": 1498793709153, // Timestamp
            *       "m": true,          // Was the buyer the maker?
            *       "M": true           // Was the trade the best price match?
            *  } ] */

            ExchangeHistoricalTradeHelper state = new ExchangeHistoricalTradeHelper(this)
            {
                Callback      = callback,
                EndDate       = endDate,
                ParseFunction = (JToken token) =>
                {
                    DateTime timestamp = CryptoUtility.UnixTimeStampToDateTimeMilliseconds(token["T"].ConvertInvariant <long>());
                    return(new ExchangeTrade
                    {
                        Amount = token["q"].ConvertInvariant <decimal>(),
                        Price = token["p"].ConvertInvariant <decimal>(),
                        Timestamp = timestamp,
                        Id = token["a"].ConvertInvariant <long>(),
                        IsBuy = token["m"].ConvertInvariant <bool>()
                    });
                },
                StartDate         = startDate,
                Symbol            = symbol,
                TimestampFunction = (DateTime dt) => ((long)CryptoUtility.UnixTimestampFromDateTimeMilliseconds(dt)).ToStringInvariant(),
                Url = "/aggTrades?symbol=[symbol]&startTime={0}&endTime={1}",
            };
            await state.ProcessHistoricalTrades();
        }