/// <summary> /// Get all balance-affecting executions. This includes each trade, insurance charge, and settlement. /// </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 <MyTrades> FetchMyTradesAsync(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new MyTrades(base_name, quote_name); var _market = await publicApi.LoadMarketAsync(_result.marketId); if (_market.success == true) { tradeClient.ExchangeInfo.ApiCallWait(TradeType.Trade); var _timeframe = tradeClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = tradeClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("symbol", _market.result.symbol); _params.Add("count", limits); _params.Add("reverse", true); if (since > 0) { _params.Add("startTime", CUnixTime.ConvertToUtcTimeMilli(since).ToString("yyyy-MM-dd HH:mm")); } tradeClient.MergeParamsAndArgs(_params, args); } var _json_value = await tradeClient.CallApiGet1Async("/api/v1/execution/tradeHistory", _params); #if RAWJSON _result.rawJson = _json_value.Content; #endif var _json_result = tradeClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = tradeClient.DeserializeObject <List <BMyTradeItem> >(_json_value.Content); { var _trades = _json_data .Where(t => t.timestamp >= since) .OrderByDescending(t => t.timestamp) .Take(limits); foreach (var _t in _trades) { _t.amount = _t.price * _t.quantity; _result.result.Add(_t); } } } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }
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); }
/// <summary> /// Funding History for the specified wallet. /// </summary> /// <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">You can set the maximum number of transactions you want to get with this parameter</param> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async ValueTask <Transfers> FetchAllTransfers(string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new Transfers(); var _markets = await publicApi.LoadMarkets(); if (_markets.success == true) { privateClient.ExchangeInfo.ApiCallWait(TradeType.Private); var _params = new Dictionary <string, object>(); { _params.Add("offset", 0); _params.Add("limit", limits); _params.Add("sort", "desc"); privateClient.MergeParamsAndArgs(_params, args); } var _json_value = await privateClient.CallApiPost1Async("/v2/user_transactions/", _params); #if RAWJSON _result.rawJson = _json_value.Content; #endif var _json_result = privateClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = privateClient.DeserializeObject <List <JObject> >(_json_value.Content); foreach (var _t in _json_data) { var _type = _t["type"].Value <int>(); if (_type != 0 && _type != 1) { continue; } var _currency = ""; var _amount = 0.0m; foreach (var _c in _markets.CurrencyNames) { var _token = _t.SelectToken(_c.Key); if (_token == null) { continue; } _amount = _token.Value <decimal>(); if (_amount != 0.0m) { _currency = _c.Value; break; } } if (String.IsNullOrEmpty(_currency) == true) { continue; } var _transaction_id = _t["id"].Value <string>(); var _transfer_id = _t["order_id"].Value <string>(); var _transaction_type = (_type == 0) ? TransactionType.Deposit : TransactionType.Withdraw; var _to_address = ""; var _from_address = ""; if (_type == 0) { _transaction_type = TransactionType.Deposit; _from_address = "undefined"; } else { _transaction_type = TransactionType.Withdraw; _to_address = "undefined"; } var _fee = _t["fee"].Value <decimal>(); var _timestamp = CUnixTime.ConvertToUnixTimeMilli(_t["datetime"].Value <string>()); _result.result.Add(new BTransferItem { transactionId = _transaction_id, transferId = _transfer_id, transactionType = _transaction_type, transferType = TransferType.Done, fromAddress = _from_address, toAddress = _to_address, currency = _currency, amount = _amount, fee = _fee, timestamp = _timestamp, isCompleted = true }); } } _result.SetResult(_json_result); } else { _result.SetResult(_markets); } 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> /// Get your orders. /// </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 <MyOrders> FetchMyOrders(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limits = 20, Dictionary <string, object> args = null) { var _result = new MyOrders(base_name, quote_name); var _market = await publicApi.LoadMarket(_result.marketId); if (_market.success == true) { tradeClient.ExchangeInfo.ApiCallWait(TradeType.Trade); var _timeframe = tradeClient.ExchangeInfo.GetTimeframe(timeframe); var _timestamp = tradeClient.ExchangeInfo.GetTimestamp(timeframe); var _params = new Dictionary <string, object>(); { _params.Add("symbol", _market.result.symbol); _params.Add("count", limits); if (since > 0) { _params.Add("startTime", CUnixTime.ConvertToUtcTimeMilli(since).ToString("yyyy-MM-dd HH:mm")); } _params.Add("reverse", true); if (args != null) { foreach (var _a in args) { if (_params.ContainsKey(_a.Key) == true) { _params.Remove(_a.Key); } _params.Add(_a.Key, _a.Value); } } } var _json_value = await tradeClient.CallApiGet1Async("/api/v1/order", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = tradeClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _json_data = tradeClient.DeserializeObject <List <BMyOrderItem> >(_json_value.Content); { var _orders = _json_data .Where(o => o.symbol == _market.result.symbol && o.timestamp >= since) .OrderByDescending(o => o.timestamp) .Take(limits); foreach (var _o in _orders) { _o.amount = _o.price * _o.quantity; _result.result.Add(_o); } } } _result.SetResult(_json_result); } else { _result.SetResult(_market); } return(_result); }