/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="symbol">Instrument symbol.</param> /// <param name="timeframe">Time interval to bucket by. Available options: [1m,5m,1h,1d].</param> /// <param name="limits">Number of results to fetch.</param> /// <returns></returns> public async ValueTask <OHLCVs> GetOHLCVs(string symbol, string timeframe = "1h", int limits = 24) { var _result = new OHLCVs(); var _params = new Dictionary <string, object>(); { var _resolution = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _duration = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _end_timestamp = (CUnixTime.NowMilli / _duration) * _duration; var _start_timestamp = _end_timestamp - (limits - 1) * _duration * 1000; _params.Add("instrument_name", symbol); _params.Add("resolution", _resolution); _params.Add("start_timestamp", _start_timestamp); _params.Add("end_timestamp", _end_timestamp); } var _response = await publicClient.CallApiGet2Async("/api/v2/public/get_tradingview_chart_data", _params); if (_response != null) { #if RAWJSON _result.rawJson = _response.Content; #endif if (_response.IsSuccessful == true) { var _tickers = publicClient.DeserializeObject <DRResults <DTickerItem> >(_response.Content); for (var i = 0; i < _tickers.result.ticks.Length; i++) { _result.result.Add( new OHLCVItem { timestamp = _tickers.result.ticks[i], openPrice = _tickers.result.open[i], highPrice = _tickers.result.high[i], lowPrice = _tickers.result.low[i], closePrice = _tickers.result.close[i], amount = _tickers.result.cost[i], vwap = 0, count = 0, volume = _tickers.result.volume[i] } ); } _result.SetSuccess(); } else { var _message = publicClient.GetResponseMessage(_response); _result.SetFailure(_message.message); } } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="symbol">Instrument symbol.</param> /// <param name="timeframe">Time interval to bucket by. Available options: [1m,5m,1h,1d].</param> /// <param name="limits">Number of results to fetch.</param> /// <returns></returns> public async ValueTask <OHLCVs> GetOHLCVs(string symbol, string timeframe = "1h", int limits = 12) { var _result = new OHLCVs(); var _params = new Dictionary <string, object>(); { _params.Add("symbol", symbol); _params.Add("binSize", timeframe); // Time interval to bucket by. Available options: [1m,5m,1h,1d]. _params.Add("count", limits); // Number of results to fetch. _params.Add("partial", false); // If true, will send in-progress (incomplete) bins for the current time period. _params.Add("reverse", true); // If true, will sort results newest first. } var _response = await publicClient.CallApiGet2Async("/api/v1/trade/bucketed", _params); if (_response != null) { #if RAWJSON _result.rawJson = _response.Content; #endif if (_response.IsSuccessful == true) { var _tickers = publicClient.DeserializeObject <List <BTickerItem> >(_response.Content); _result.result.AddRange( _tickers .Select(x => new OHLCVItem { timestamp = x.timestamp, openPrice = x.openPrice, highPrice = x.highPrice, lowPrice = x.lowPrice, closePrice = x.closePrice, amount = x.quoteVolume, vwap = x.vwap, count = x.trades, volume = x.baseVolume }) .OrderByDescending(o => o.timestamp) ); _result.SetSuccess(); } else { var _message = publicClient.GetResponseMessage(_response); _result.SetFailure(_message.message); } } return(_result); }