Exemple #1
0
        public PublicTransactionData(string transaction_date, string type, string units_traded, string price, string total)
        {
            if (CUnixTime.IsDateTimeFormat(transaction_date) == true)
            {
                var _tdate = CUnixTime.ConvertToUtcTime(transaction_date + "+09:00");
                this.transaction_date = CUnixTime.ConvertToUnixTimeMilli(_tdate);
            }
            else
            {
                this.transaction_date = Convert.ToInt64(transaction_date);
            }

            this.type         = type;
            this.units_traded = Convert.ToDecimal(units_traded);
            this.price        = decimal.Parse(price, NumberStyles.Float);
            this.total        = decimal.Parse(total, NumberStyles.Float);
        }
Exemple #2
0
        /// <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);
        }