Ejemplo n.º 1
0
        /// <summary>
        /// View Exchange Completed 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="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 <MyTrades> FetchMyTrades(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limit = 20, Dictionary <string, object> args = null)
        {
            var _result = new MyTrades(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("currency_pair", _market.result.symbol);
                    _params.Add("status", "filled");
                    _params.Add("offset", 0);
                    _params.Add("limit", limit);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiGet1Async("/user/orders", _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 <KMyTradeItem> >(_json_value.Content);
                    {
                        var _trades = _json_data
                                      .Where(t => t.timestamp >= since)
                                      .OrderByDescending(t => t.timestamp)
                                      .Take(limit);

                        foreach (var _t in _trades)
                        {
                            if (_t.price == 0)
                            {
                                _t.price = _t.avg_price;
                            }

                            _t.amount = _t.quantity * _t.price;
                            _result.result.Add(_t);
                        }
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get all trades for the specified wallet.
        /// </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>();
                {
                    //var _till_time = CUnixTime.Now;
                    //var _from_time = (since > 0) ? since / 1000 : _till_time - _timestamp * limits;     // 가져올 갯수 만큼 timeframe * limits 간격으로 데이터 양 계산

                    //_params.Add("rangeStart", CUnixTime.ConvertToUtcTime(_from_time).ToString("o"));    // ISO 8601 datetime string with seconds
                    //_params.Add("rangeEnd", CUnixTime.ConvertToUtcTime(_till_time).ToString("o"));

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiGet1Async($"/v1/wallets/{__wallet_id}/trades", _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 <TMyTrades>(_json_value.Content);
                    {
                        var _trades = _json_data.result
                                      .Where(t => t.symbol == _market.result.symbol && t.timestamp >= since)
                                      .OrderByDescending(t => t.timestamp)
                                      .Take(limits);

                        foreach (var _t in _trades)
                        {
                            _t.amount = _t.quantity * _t.price;
                            _result.result.Add(_t);
                        }
                    }

                    _result.marketId = _market.result.marketId;
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 체결 완료 리스트 조회
        /// </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);
                    if (since == 0)
                    {
                        since = CUnixTime.NowMilli - (_timestamp * 1000) * limits;
                    }
                    _params.Add("since", since);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/v1/trade_history.do", _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 <OMyTradeItem> >(_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);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </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 <MyTrades> FetchMyTrades(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.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("state", 1);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/api/v1/trade/orderInfos", _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 <BMyTrades>(_json_value.Content);
                    {
                        var _trades = _json_data.result
                                      .Where(t => t.timestamp >= since)
                                      .OrderByDescending(t => t.timestamp)
                                      .Take(limits);

                        foreach (var _t in _trades)
                        {
                            _t.amount  = _t.quantity * _t.price;
                            _t.tradeId = _t.timestamp.ToString(); // tradeId 제공 안함

                            _result.result.Add(_t);
                        }
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns your trade history for a given market.
        /// </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> FetchMyTrades(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.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("command", "returnTradeHistory");
                    _params.Add("currencyPair", _market.result.symbol);
                    _params.Add("start", since / 1000);
                    _params.Add("end", CUnixTime.Now);
                    _params.Add("limit", limits);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("", _params);

#if RAWJSON
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = tradeClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _trades = tradeClient.DeserializeObject <Dictionary <string, List <PMyTradeItem> > >(_json_value.Content);
                    {
                        foreach (var _t in _trades)
                        {
                            foreach (var _trade in _t.Value)
                            {
                                _trade.amount = _trade.quantity * _trade.price;
                                _result.result.Add(_trade);
                            }
                        }
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get trades history
        /// </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 _params = tradeClient.MergeParamsAndArgs(args);

                var _json_value = await tradeClient.CallApiPost1Async("/0/private/TradesHistory", _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 <KResponse <KMyTrades> >(_json_value.Content);
                    {
                        var _trades = _json_data.result.trades
                                      .OrderByDescending(o => o.Value.timestamp);

                        foreach (var _t in _trades)
                        {
                            _t.Value.tradeId = _t.Key;
                            _t.Value.amount  = _t.Value.quantity * _t.Value.price;

                            _result.result.Add(_t.Value);
                        }
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get trades for a specific account and symbol.
        /// </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> FetchMyTrades(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.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("currency", _market.result.symbol);
                    _params.Add("offset", 0);
                    _params.Add("count", limits);
                    _params.Add("searchGb", 0);     // 0 : 전체, 1 : 구매완료, 2 : 판매완료, 3 : 출금중, 4 : 입금, 5 : 출금, 9 : KRW입금중

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/info/user_transactions", _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 <BMyTrades>(_json_value.Content);
                    if (_json_data.success == true)
                    {
                        var _orders = _json_data.result
                                      .Where(o => o.timestamp >= since && (o.sideType == SideType.Ask || o.sideType == SideType.Bid))
                                      .OrderByDescending(t => t.timestamp)
                                      .Take(limits);

                        foreach (var _o in _orders)
                        {
                            _o.symbol = _market.result.symbol;

                            _o.amount = Math.Abs(_o.amount);
                            if (_o.quantity != 0.0m)
                            {
                                _o.price = _o.amount / _o.quantity;
                            }

                            _result.result.Add(_o);
                        }
                    }
                    else
                    {
                        _json_result.SetResult(_json_data);
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get trades for a specific account and symbol.
        /// </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)
            {
                okexClient.ExchangeInfo.ApiCallWait(TradeType.Trade);

                var _timeframe = okexClient.ExchangeInfo.GetTimeframe(timeframe);
                var _timestamp = okexClient.ExchangeInfo.GetTimestamp(timeframe);

                var _params = new Dictionary <string, object>();
                {
                    _params.Add("symbol", _market.result.symbol);
                    _params.Add("status", 1); // query type: 0 for unfilled (open) orders, 1 for filled orders
                    _params.Add("current_page", 1);
                    _params.Add("page_length", 200);

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _end_point = okexClient.CheckFuturesUrl(_market.result, "/order_history.do", "/future_order_history.do", _params);

                var _json_value = await okexClient.CallApiPost1Async(_end_point.endPoint, _end_point.args);

#if RAWJSON
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = okexClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _json_data = okexClient.DeserializeObject <OMyTrades>(_json_value.Content);
                    if (_json_data.success == true)
                    {
                        var _trades = _json_data.result
                                      .Where(t => t.timestamp >= since)
                                      .OrderByDescending(t => t.timestamp)
                                      .Take(limits);

                        foreach (var _t in _trades)
                        {
                            _t.tradeId = _t.timestamp.ToString(); // tradeId 제공 안함
                            _t.amount  = _t.price * _t.quantity;

                            _result.result.Add(_t);
                        }
                    }
                    else
                    {
                        _json_result.SetResult(_json_data);
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Get a list of executed trade
        /// </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 <MyTrades> FetchMyTrades(string base_name, string quote_name, string timeframe = "1d", long since = 0, int limit = 20, Dictionary <string, object> args = null)
        {
            var _result = new MyTrades(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>();
                {
                    if (since > 0)
                    {
                        _params.Add("from", since);
                        _params.Add("to", CUnixTime.NowMilli);
                    }

                    tradeClient.MergeParamsAndArgs(_params, args);
                }

                var _json_value = await tradeClient.CallApiPost1Async("/money/trade/list", _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 <AMyTrades>(_json_value.Content);
                    if (_json_data.success == true)
                    {
                        var _trades = _json_data.result
                                      .Where(t => t.timestamp >= since)
                                      .OrderByDescending(t => t.timestamp)
                                      .Take(limit);

                        foreach (var _t in _trades)
                        {
                            _t.price = (_t.amount / _t.quantity).Normalize();
                            _result.result.Add(_t);
                        }
                    }
                    else
                    {
                        _json_result.SetFailure(_json_data.message);
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Order_V2 - My Complete 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 <MyTrades> FetchMyTrades(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.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("currency", _market.result.symbol);

                    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.CallApiPost1Async("/v2/order/complete_orders", _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 <CMyTrades>(_json_value.Content);
                    {
                        var _trades = _json_data.result
                                      .Where(t => t.timestamp >= since)
                                      .OrderByDescending(t => t.timestamp)
                                      .Take(limits);

                        foreach (var _t in _trades)
                        {
                            _t.amount = _t.quantity * _t.price;

                            _result.result.Add(_t);
                        }
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Get trades for a specific account and symbol.
        /// </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 <MyTrades> FetchMyTrades(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.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 = tradeClient.MergeParamsAndArgs(
                    new Dictionary <string, object>
                {
                    { "offset", 0 },
                    { "limit", limits },
                    { "sort", "desc" }
                },
                    args
                    );

                var _json_value = await tradeClient.CallApiPost1Async($"/v2/user_transactions/{_market.result.symbol}/", _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 <JArray>(_json_value.Content);
                    foreach (var _j in _json_data)
                    {
                        var _t = tradeClient.DeserializeObject <BMyTradeItem>(_j.ToString());
                        if (_t.type != 2)
                        {
                            continue;
                        }

                        var _base_id  = _market.result.baseId;
                        var _quote_id = _market.result.quoteId;

                        _t.symbol = _market.result.symbol;

                        _t.price    = _j[$"{_base_id}_{_quote_id}"].Value <decimal>();
                        _t.quantity = _j[_base_id].Value <decimal>();
                        _t.amount   = _j[_quote_id].Value <decimal>();

                        _t.sideType = _t.amount < 0 ? SideType.Ask : SideType.Bid;

                        _result.result.Add(_t);
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_market);
            }

            return(_result);
        }