/// <summary> /// Fetch symbols, market ids and exchanger's information /// </summary> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async Task <Markets> FetchMarkets(Dictionary <string, object> args = null) { var _result = new Markets(); publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); { var _params = publicClient.MergeParamsAndArgs(args); var _json_value = await publicClient.CallApiGet1Async("/exchangeInfo", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _exchange_info = publicClient.DeserializeObject <JObject>(_json_value.Content); var _symbols = _exchange_info["symbols"].ToObject <JArray>(); foreach (var _market in _symbols) { var _symbol = _market["symbol"].ToString(); if (_symbol == "123456") // "123456" is a "test symbol/market" { continue; } var _base_id = _market["baseAsset"].ToString(); var _quote_id = _market["quoteAsset"].ToString(); var _base_name = publicClient.ExchangeInfo.GetCommonCurrencyName(_base_id); var _quote_name = publicClient.ExchangeInfo.GetCommonCurrencyName(_quote_id); var _market_id = _base_name + "/" + _quote_name; var _precision = new MarketPrecision { quantity = _market["baseAssetPrecision"].Value <int>(), price = _market["quotePrecision"].Value <int>(), amount = _market["quotePrecision"].Value <int>() }; var _lot = (decimal)(-1.0 * Math.Log10(_precision.quantity)); var _active = _market["status"].ToString().ToUpper() == "TRADING"; var _limits = new MarketLimits { quantity = new MarketMinMax { min = (decimal)Math.Pow(10, -_precision.quantity), max = decimal.MaxValue }, price = new MarketMinMax { min = (decimal)Math.Pow(10, -_precision.price), max = decimal.MaxValue }, amount = new MarketMinMax { min = _lot, max = decimal.MaxValue } }; var _entry = new MarketItem { marketId = _market_id, symbol = _symbol, baseId = _base_id, quoteId = _quote_id, baseName = _base_name, quoteName = _quote_name, lot = _lot, active = _active, precision = _precision, limits = _limits }; var _filters = _market["filters"]; { var _price_filter = _filters.SingleOrDefault(f => f["filterType"].ToString() == "PRICE_FILTER"); if (_price_filter != null) { _entry.precision.price = Numerical.PrecisionFromString(_price_filter["tickSize"].ToString()); _entry.limits.price.min = _price_filter["minPrice"].Value <decimal>(); _entry.limits.price.max = _price_filter["maxPrice"].Value <decimal>(); } var _lot_size = _filters.SingleOrDefault(f => f["filterType"].ToString() == "LOT_SIZE"); if (_lot_size != null) { _entry.precision.quantity = Numerical.PrecisionFromString(_lot_size["stepSize"].ToString()); _entry.limits.quantity.min = _lot_size["minQty"].Value <decimal>(); _entry.limits.quantity.max = _lot_size["maxQty"].Value <decimal>(); } var _min_notional = _filters.SingleOrDefault(f => f["filterType"].ToString() == "MIN_NOTIONAL"); if (_min_notional != null) { _entry.limits.amount.min = _min_notional["minNotional"].Value <decimal>(); } } _result.result.Add(_entry.marketId, _entry); } } _result.SetResult(_json_result); } return(_result); }
/// <summary> /// Fetch symbols, market ids and exchanger's information /// </summary> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async ValueTask <Markets> FetchMarkets(Dictionary <string, object> args = null) { var _result = new Markets(); publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); { var _params = publicClient.MergeParamsAndArgs(args); var _json_value = await publicClient.CallApiGet1Async("/api/v1/instrument/active", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _markets = publicClient.DeserializeObject <List <BMarketItem> >(_json_value.Content); foreach (var _m in _markets) { _m.active = _m.state != "Unlisted"; if (_m.active == false) { continue; } var _base_id = _m.underlying; var _quote_id = _m.quoteCurrency; var _base_name = publicClient.ExchangeInfo.GetCommonCurrencyName(_base_id); var _quote_name = publicClient.ExchangeInfo.GetCommonCurrencyName(_quote_id); var _market_id = _base_name + "/" + _quote_name; var _order_base = _base_name; var _order_quote = _quote_name; var _base_quote = _base_id + _quote_id; if (_m.symbol == _base_quote) { _m.swap = true; _m.type = "swap"; } else { var _symbols = _m.symbol.Split('_'); if (_symbols.Length > 1) { _market_id = _symbols[0] + "/" + _symbols[1]; _order_base = _symbols[0]; _order_quote = _symbols[1]; } else { _market_id = _m.symbol.Substring(0, 3) + "/" + _m.symbol.Substring(3); _order_base = _m.symbol.Substring(0, 3); _order_quote = _m.symbol.Substring(3); } if (_m.symbol.IndexOf("B_") >= 0) { _m.prediction = true; _m.type = "prediction"; } else { _m.future = true; _m.type = "future"; } } _m.marketId = _market_id; _m.baseId = (_base_name != "BTC") ? _base_id : _m.settlCurrency; _m.quoteId = (_quote_name != "BTC") ? _quote_id : _m.settlCurrency; _m.orderBase = _order_base; _m.orderQuote = _order_quote; _m.baseName = _base_name; _m.quoteName = _quote_name; _m.lot = _m.lotSize; _m.precision = new MarketPrecision() { quantity = Numerical.PrecisionFromString(Numerical.TruncateToString(_m.lotSize, 16)), price = Numerical.PrecisionFromString(Numerical.TruncateToString(_m.tickSize, 16)), amount = Numerical.PrecisionFromString(Numerical.TruncateToString(_m.tickSize, 16)) }; var _lot_size = _m.lotSize; var _max_order_qty = _m.maxOrderQty; var _tick_size = _m.tickSize; var _max_price = _m.maxPrice; _m.limits = new MarketLimits { quantity = new MarketMinMax { min = _lot_size, max = _max_order_qty }, price = new MarketMinMax { min = _tick_size, max = _max_price }, amount = new MarketMinMax { min = _lot_size * _tick_size, max = _max_order_qty * _max_price } }; if (_m.initMargin != 0) { _m.maxLeverage = (int)(1 / _m.initMargin); } _result.result.Add(_m.marketId, _m); } } _result.SetResult(_json_result); } return(_result); }
/// <summary> /// Fetch symbols, market ids and exchanger's information /// </summary> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async Task <Markets> FetchMarkets(Dictionary <string, object> args = null) { var _result = new Markets(); publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); { var _params = publicClient.MergeParamsAndArgs(args); var _json_value = await publicClient.CallApiGet1Async("/currency_limits", _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 <JObject>(_json_value.Content); var _pairs = _json_data["data"]["pairs"]; foreach (var _market in _pairs) { var _base_id = _market["symbol1"].ToString(); var _quote_id = _market["symbol2"].ToString(); var _symbol = _base_id + "/" + _quote_id; var _base_name = publicClient.ExchangeInfo.GetCommonCurrencyName(_base_id); var _quote_name = publicClient.ExchangeInfo.GetCommonCurrencyName(_quote_id); var _market_id = _base_name + "/" + _quote_name; var _lot = _market["minLotSize"].Value <decimal>(); var _maxLot = (_market["maxLotSize"].HasValues) ? _market["maxLotSize"].Value <decimal>() : decimal.MaxValue; var _precision = new MarketPrecision { quantity = (int)(-1 * Math.Log10((double)_lot)), price = Numerical.PrecisionFromString(_market["minPrice"].Value <string>()), amount = Numerical.PrecisionFromString(_market["minPrice"].Value <string>()) }; var _limits = new MarketLimits { quantity = new MarketMinMax { min = _market["minLotSize"].Value <decimal>(), max = _maxLot }, price = new MarketMinMax { min = _market["minPrice"].Value <decimal>(), max = _market["maxPrice"].Value <decimal>() }, amount = new MarketMinMax { min = _market["minLotSizeS2"].Value <decimal>(), max = decimal.MaxValue } }; var _entry = new MarketItem { marketId = _market_id, symbol = _symbol, baseId = _base_id, quoteId = _quote_id, baseName = _base_name, quoteName = _quote_name, lot = _lot, active = true, precision = _precision, limits = _limits }; _result.result.Add(_entry.marketId, _entry); } } _result.SetResult(_json_result); } return(_result); }
/// <summary> /// Fetch symbols, market ids and exchanger's information /// </summary> /// <param name="args">Add additional attributes for each exchange</param> /// <returns></returns> public override async ValueTask <Markets> FetchMarketsAsync(Dictionary <string, object> args = null) { var _result = new Markets(); publicClient.ExchangeInfo.ApiCallWait(TradeType.Public); { var _params = publicClient.MergeParamsAndArgs(args); var _json_value = await publicClient.CallApiGet1Async("/products", _params); #if DEBUG _result.rawJson = _json_value.Content; #endif var _json_result = publicClient.GetResponseMessage(_json_value.Response); if (_json_result.success == true) { var _products = publicClient.DeserializeObject <List <JObject> >(_json_value.Content); foreach (var _market in _products) { var _symbol = _market["id"].ToString(); var _base_id = _market["base_currency"].ToString(); var _quote_id = _market["quote_currency"].ToString(); var _base_name = publicClient.ExchangeInfo.GetCommonCurrencyName(_base_id); var _quote_name = publicClient.ExchangeInfo.GetCommonCurrencyName(_quote_id); var _market_id = _base_name + "/" + _quote_name; var _precision = new MarketPrecision { quantity = 8, price = Numerical.PrecisionFromString(_market["quote_increment"].Value <string>()), amount = 0 }; var _lot = (decimal)Math.Pow(10, -(double)_precision.quantity); var _active = _market["status"].ToString() == "online"; var _limits = new MarketLimits { quantity = new MarketMinMax { min = _market["base_min_size"].Value <decimal>(), max = _market["base_max_size"].Value <decimal>() }, price = new MarketMinMax { min = _market["quote_increment"].Value <decimal>(), max = decimal.MaxValue }, amount = new MarketMinMax { min = _market["min_market_funds"].Value <decimal>(), max = _market["max_market_funds"].Value <decimal>() } }; var _entry = new MarketItem { marketId = _market_id, symbol = _symbol, baseId = _base_id, quoteId = _quote_id, baseName = _base_name, quoteName = _quote_name, lot = _lot, active = _active, precision = _precision, limits = _limits }; _result.result.Add(_entry.marketId, _entry); } } _result.SetResult(_json_result); } return(_result); }