/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limit">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async Task<OHLCVs> FetchOHLCVs(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limit = 20, Dictionary<string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarket(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary<string, object>(); { _params.Add("interval", _timeframe); var _tiil_time = CUnixTime.NowMilli; var _from_time = (since > 0) ? since : _tiil_time - _timestamp * 1000; _params.Add("start", _from_time); _params.Add("end", _tiil_time); publicClient.MergeParamsAndArgs(_params, args); } var _json_value = await publicClient.CallApiGet1Async($"/trading-pairs/{_market.result.symbol}/candles", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject<List<JArray>>(_json_value.Content); _result.result.AddRange( _json_data .Select(x => new OHLCVItem { timestamp = x[0].Value<long>(), openPrice = x[3].Value<decimal>(), highPrice = x[2].Value<decimal>(), lowPrice = x[1].Value<decimal>(), closePrice = x[4].Value<decimal>(), volume = x[5].Value<decimal>() }) .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limit) ); } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return _result; }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="resolution">time frame interval (ex): 1m,3m,5m,15m,30m,1h,2h,3h,4h,6h,12h,1d,3d,1w,2w,1M</param> /// <param name="from_time"></param> /// <param name="till_time"></param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public async Task <OHLCVs> FetchUdfHistory(string base_name, string quote_name, string resolution = "1d", long from_time = 0, long till_time = 0, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarket(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _params = new Dictionary <string, object>(); { _params.Add("symbol", _market.result.symbol); _params.Add("resolution", resolution); _params.Add("from", from_time); _params.Add("to", till_time); publicClient.MergeParamsAndArgs(_params, args); } var _json_value = await publicClient.CallApiGet1Async("/api/udf/history", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject <BUdfHistory>(_json_value.Content); if (_json_data.s == "ok") { for (var _offset = 0; _offset < _json_data.t.Count; _offset++) { _result.result.Add(new OHLCVItem { timestamp = _json_data.t[_offset] * 1000, openPrice = _json_data.o[_offset], highPrice = _json_data.h[_offset], lowPrice = _json_data.l[_offset], closePrice = _json_data.c[_offset], amount = 0, volume = _json_data.v[_offset] }); } } else { _json_result.SetFailure(); } } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async Task <OHLCVs> FetchOHLCVs(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarket(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("market", _market.result.symbol); _params.Add("type", _timeframe); _params.Add("size", limits); if (since > 0) { _params.Add("since", since); } publicClient.MergeParamsAndArgs(_params, args); } var _json_value = await publicClient.CallApiGet1Async("/v1/kline", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _ohlcvs = publicClient.DeserializeObject <ZOHLCVs>(_json_value.Content); if (_ohlcvs.success == true) { _result.result.AddRange( _ohlcvs.result .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } else { _json_result.SetFailure(_ohlcvs.message); } } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async ValueTask <OHLCVs> FetchOHLCVsAsync(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarketAsync(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("marketName", _market.result.symbol); _params.Add("tickInterval", _timeframe); // timeframe must be in [“oneMin”, “fiveMin”, “thirtyMin”, “hour”, “day”] if (since > 0) { _params.Add("_", since); // Probably _ is a timestamp. } publicClient.MergeParamsAndArgs(_params, args); } var _json_value = await publicClient.CallApiGet1Async("/v2.0/pub/market/GetTicks", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _ohlcvs = publicClient.DeserializeObject <BOHLCVs>(_json_value.Content); if (_ohlcvs.success == true) { _result.result.AddRange( _ohlcvs.result .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } else { _json_result.SetFailure(_ohlcvs.message); } } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d" /// <list type="timeframe"> /// <item><description>Minute(1m, 3m, 5m, 10m, 15m, 30m, 60m, 240m)</description></item> /// <item><description>Day(1d)</description></item> /// <item><description>Week(1w)</description></item> /// <item><description>Month(1M)</description></item> /// </list> /// </param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns>OHLCVs</returns> public override async ValueTask <OHLCVs> FetchOHLCVsAsync(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarketAsync(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("market", _market.result.symbol); _params.Add("count", limits); publicClient.MergeParamsAndArgs(_params, args); } var _end_point = _timeframe == "minutes" ? $"/candles/{_timeframe}/{Convert.ToInt32(timeframe.Substring(0, timeframe.Length - 1))}" : $"/candles/{_timeframe}"; var _json_value = await publicClient.CallApiGet1Async(_end_point, _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject <List <UOHLCVItem> >(_json_value.Content); { _result.result.AddRange( _json_data .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async Task <OHLCVs> FetchOHLCVs(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarket(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _params = new Dictionary <string, object>(); { var _limit = limits <= 1 ? 1 : limits <= 1000 ? limits : 1000; if (since == 0) { since = CUnixTime.NowMilli - (_timestamp * 1000) * _limit; // 가져올 갯수 만큼 timeframe * limits 간격으로 데이터 양 계산 } _params.Add("sort", "1"); // if = 1 it sorts results returned with old > new _params.Add("limit", _limit); _params.Add("start", since); publicClient.MergeParamsAndArgs(_params, args); } var _section = "hist"; // Section(string) REQUIRED Available values: "last", "hist" var _json_value = await publicClient.CallApiGet1Async($"/v2/candles/trade:{_timeframe}:t{_market.result.symbol.ToUpper()}/{_section}", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject <List <JArray> >(_json_value.Content); _result.result.AddRange( _json_data .Select(x => new OHLCVItem { timestamp = x[0].Value <long>(), openPrice = x[1].Value <decimal>(), highPrice = x[3].Value <decimal>(), lowPrice = x[4].Value <decimal>(), closePrice = x[2].Value <decimal>(), volume = x[5].Value <decimal>() }) .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async Task <OHLCVs> FetchOHLCVs(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarket(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _params = publicClient.MergeParamsAndArgs(args); var _yesterday = CUnixTime.UtcNow.AddDays(-1).ToString("yyyyMMdd"); var _dataframe = $"data{_timeframe}"; var _json_value = await publicClient.CallApiGet1Async($"/ohlcv/hd/{_yesterday}/{_market.result.symbol}", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject <Dictionary <string, JToken> >(_json_value.Content); if (_json_data.ContainsKey(_dataframe) == true) { var _candles = publicClient.DeserializeObject <JArray>(_json_data[_dataframe].ToString()); _result.result.AddRange( _candles .Select(x => new OHLCVItem { timestamp = x[0].Value <long>() * 1000, openPrice = x[1].Value <decimal>(), highPrice = x[2].Value <decimal>(), lowPrice = x[3].Value <decimal>(), closePrice = x[4].Value <decimal>(), volume = x[5].Value <decimal>() }) .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } else { _json_result.SetFailure($"not exist '{_timeframe}' timeframe", ErrorCode.NotFoundData); } } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async ValueTask <OHLCVs> FetchOHLCVsAsync(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarketAsync(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("command", "returnChartData"); _params.Add("currencyPair", _market.result.symbol); _params.Add("period", _timeframe); var _till_time = CUnixTime.Now; var _from_time = (since > 0) ? since / 1000 : _till_time - _timestamp * limits; // 가져올 갯수 만큼 timeframe * limits 간격으로 데이터 양 계산 _params.Add("start", _from_time); _params.Add("end", _till_time); publicClient.MergeParamsAndArgs(_params, args); } var _json_value = await publicClient.CallApiGet1Async("", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject <List <JObject> >(_json_value.Content); _result.result.AddRange( _json_data .Select(x => new OHLCVItem { timestamp = x["date"].Value <long>() * 1000, openPrice = x["open"].Value <decimal>(), highPrice = x["high"].Value <decimal>(), lowPrice = x["low"].Value <decimal>(), closePrice = x["close"].Value <decimal>(), volume = x["quoteVolume"].Value <decimal>() }) .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async ValueTask <OHLCVs> FetchOHLCVs(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarket(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary <string, object>(); { var _limits = limits <= 1 ? 1 : limits <= 500 ? limits : 500; _params.Add("symbol", _market.result.symbol); _params.Add("binSize", _timeframe); _params.Add("count", _limits); _params.Add("partial", false); _params.Add("reverse", true); publicClient.MergeParamsAndArgs(_params, args); } var _json_value = await publicClient.CallApiGet1Async("/api/v1/trade/bucketed", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject <List <BTickerItem> >(_json_value.Content); _result.result.AddRange( _json_data .Select(x => new OHLCVItem { timestamp = x.timestamp, openPrice = x.openPrice, highPrice = x.highPrice, lowPrice = x.lowPrice, closePrice = x.closePrice, amount = x.quoteVolume, volume = x.baseVolume }) .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange: contract_type(this_week, next_week, month, quarter)</param> /// <returns></returns> public override async ValueTask <OHLCVs> FetchOHLCVs(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarket(_result.marketId); if (_market.success == true) { okexapiClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timeframe = okexapiClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = okexapiClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("symbol", _market.result.symbol); _params.Add("type", _timeframe); _params.Add("size", limits); if (since > 0) { _params.Add("since", since); } okexapiClient.MergeParamsAndArgs(_params, args); } var _end_point = okexapiClient.CheckFuturesUrl(_market.result, "/kline.do", "/future_kline.do", _params); var _json_value = await okexapiClient.CallApiGet1Async(_end_point.endPoint, _end_point.args); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = okexapiClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = okexapiClient.DeserializeObject <List <JArray> >(_json_value.Content); _result.result.AddRange( _json_data .Select(x => new OHLCVItem { timestamp = x[0].Value <long>(), openPrice = x[1].Value <decimal>(), highPrice = x[2].Value <decimal>(), lowPrice = x[3].Value <decimal>(), closePrice = x[4].Value <decimal>(), volume = x[5].Value <decimal>() }) .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async ValueTask <OHLCVs> FetchOHLCVsAsync(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarketAsync(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("granularity", _timestamp); var _till_time = CUnixTime.Now; var _from_time = (since > 0) ? since / 1000 : _till_time - _timestamp * limits; // 가져올 갯수 만큼 timeframe * limits 간격으로 데이터 양 계산 _params.Add("start", CUnixTime.ConvertToUtcTime(_from_time).ToString("o")); // ISO 8601 datetime string with seconds _params.Add("end", CUnixTime.ConvertToUtcTime(_till_time).ToString("o")); publicClient.MergeParamsAndArgs(_params, args); } var _json_value = await publicClient.CallApiGet1Async($"/products/{_market.result.symbol}/candles", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject <JArray>(_json_value.Content); _result.result.AddRange( _json_data .Select(x => new OHLCVItem { timestamp = x[0].Value <long>() * 1000, openPrice = x[3].Value <decimal>(), highPrice = x[2].Value <decimal>(), lowPrice = x[1].Value <decimal>(), closePrice = x[4].Value <decimal>(), volume = x[5].Value <decimal>() }) .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async ValueTask <OHLCVs> FetchOHLCVs(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarket(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("symbol", _market.result.symbol); _params.Add("resolution", 0.5); if (since > 0 && limits > 0) { _params.Add("from", since); _params.Add("to", since + limits * _timestamp); // 가져올 갯수 만큼 timeframe * limits 간격으로 데이터 양 계산 } _params.Add("strTime", CUnixTime.NowMilli); publicClient.MergeParamsAndArgs(_params, args); } var _json_value = await publicWeb.CallApiGet1Async($"/resources/chart/{_market.result.symbol}_xcoinTrade_{_timeframe}.json", _params); #if RAWJSON _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject <JArray>(_json_value.Content); { _result.result.AddRange( _json_data .Select(x => new BOHLCVItem { timestamp = x[0].Value <long>(), openPrice = x[1].Value <decimal>(), highPrice = x[3].Value <decimal>(), lowPrice = x[4].Value <decimal>(), closePrice = x[2].Value <decimal>(), volume = x[5].Value <decimal>() }) .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
/// <summary> /// Fetch array of symbol name and OHLCVs data /// </summary> /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param> /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param> /// <param name="timeframe">time frame interval (optional): default "1d"</param> /// <param name="since">return committed data since given time (milli-seconds) (optional): default 0</param> /// <param name="limits">maximum number of items (optional): default 20</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async ValueTask <OHLCVs> FetchOHLCVsAsync(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new OHLCVs(base_name, quote_name); var _market = await this.LoadMarketAsync(_result.marketId); if (_market.success == true) { publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); var _timeframe = publicClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = publicClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("pair", _market.result.symbol); _params.Add("interval", _timeframe); if (since > 0) { _params.Add("since", since / 1000); } publicClient.MergeParamsAndArgs(_params, args); } var _json_value = await publicClient.CallApiGet1Async("/0/public/OHLC", _params); #if RAWJSON _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = publicClient.DeserializeObject <JObject>(_json_value.Content); var _json_ohlcvs = JArray.FromObject((_json_data["result"] as JObject)[_market.result.symbol]); _result.result.AddRange( _json_ohlcvs .Select(x => new OHLCVItem { timestamp = x[0].Value <long>() * 1000, openPrice = x[1].Value <decimal>(), highPrice = x[2].Value <decimal>(), lowPrice = x[3].Value <decimal>(), closePrice = x[4].Value <decimal>(), volume = x[6].Value <decimal>() }) .Where(o => o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits) ); } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }