protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            if (ReadCache("GetSymbols", out List <ExchangeMarket> cachedMarkets))
            {
                return(cachedMarkets);
            }

            var markets = new List <ExchangeMarket>();

            JToken allPairs = await MakeJsonRequestAsync <JToken>("/public/symbols", BaseUrl);

            foreach (JToken pair in allPairs)
            {
                var market = new ExchangeMarket
                {
                    IsActive   = true,
                    MarketName = NormalizeSymbol(pair["name"].ToStringInvariant()),
                };
                market.MarketCurrency = pair["base_currency"].ToStringInvariant();
                market.BaseCurrency   = pair["quote_currency"].ToStringInvariant();
                int pricePrecision = pair["price_decimal"].ConvertInvariant <int>();
                market.PriceStepSize = (decimal)Math.Pow(0.1, pricePrecision);
                int amountPrecision = pair["amount_decimal"].ConvertInvariant <int>();
                market.QuantityStepSize = (decimal)Math.Pow(0.1, pricePrecision);
                markets.Add(market);
            }

            WriteCache("GetSymbols", TimeSpan.FromMinutes(60.0), markets);
            return(markets);
        }
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            if (ReadCache("GetSymbols", out List <ExchangeMarket> cachedMarkets))
            {
                return(cachedMarkets);
            }

            var markets = new List <ExchangeMarket>();

            JToken allPairs = await MakeJsonRequestAsync <JToken>("/public/symbol", BaseUrl);

            foreach (JToken pair in allPairs)
            {
                var market = new ExchangeMarket
                {
                    IsActive   = true,
                    MarketName = pair["id"].ToStringInvariant()
                };
                market.MarketCurrency   = pair["baseCurrency"].ToStringInvariant();
                market.BaseCurrency     = pair["quoteCurrency"].ToStringInvariant();
                market.QuantityStepSize = pair["quantityIncrement"].ConvertInvariant <decimal>();
                market.PriceStepSize    = pair["tickSize"].ConvertInvariant <decimal>();
                markets.Add(market);
            }

            WriteCache("GetSymbols", TimeSpan.FromMinutes(60.0), markets);
            return(markets);
        }
        /// <summary>
        /// Get exchange symbols including available metadata such as min trade size and whether the market is active
        /// </summary>
        /// <returns>Collection of ExchangeMarkets</returns>
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            var    markets = new List <ExchangeMarket>();
            JToken array   = await MakeJsonRequestAsync <JToken>("/public/getmarkets");

            // StepSize is 8 decimal places for both price and amount on everything at Bittrex
            const decimal StepSize = 0.00000001m;

            foreach (JToken token in array)
            {
                var market = new ExchangeMarket
                {
                    BaseCurrency     = token["BaseCurrency"].ToStringUpperInvariant(),
                    IsActive         = token["IsActive"].ConvertInvariant <bool>(),
                    MarketCurrency   = token["MarketCurrency"].ToStringUpperInvariant(),
                    MarketName       = token["MarketName"].ToStringUpperInvariant(),
                    MinTradeSize     = token["MinTradeSize"].ConvertInvariant <decimal>(),
                    MinPrice         = StepSize,
                    PriceStepSize    = StepSize,
                    QuantityStepSize = StepSize,
                    MinNotional      = 0.0005m
                };

                markets.Add(market);
            }

            return(markets);
        }
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            /*
             * {"code":0,"data":[{"baseCurrency":1,"collect":"0","isMarginOpen":false,"listDisplay": 0,
             * "marginRiskPreRatio": 0,
             * "marginRiskRatio": 0,
             * "marketFrom": 103,
             * "maxMarginLeverage": 0,
             * "maxPriceDigit": 8,
             * "maxSizeDigit": 6,
             * "minTradeSize": 0.00100000,
             * "online": 1,
             * "productId": 12,
             * "quoteCurrency": 0,
             * "quoteIncrement": 1E-8,
             * "quotePrecision": 4,
             * "sort": 10013,
             * "symbol": "ltc_btc"
             * },
             */
            if (ReadCache("GetSymbolsMetadata", out List <ExchangeMarket> markets))
            {
                return(markets);
            }

            markets = new List <ExchangeMarket>();
            JToken allSymbols = await MakeJsonRequestAsync <JToken>("/markets/products", BaseUrlV2);

            foreach (JToken symbol in allSymbols)
            {
                var      marketName = symbol["symbol"].ToStringLowerInvariant();
                string[] pieces     = marketName.Split('_');
                var      market     = new ExchangeMarket
                {
                    MarketName     = marketName,
                    IsActive       = symbol["online"].ConvertInvariant <bool>(),
                    BaseCurrency   = pieces[1],
                    MarketCurrency = pieces[0],
                };
                //交易量精度maxSizeDigit
                var maxSizeDigit     = symbol["maxSizeDigit"].ConvertInvariant <double>();
                var quantityStepSize = Math.Pow(10, -maxSizeDigit);
                market.QuantityStepSize = quantityStepSize.ConvertInvariant <decimal>();
                //价格精度maxPriceDigit
                var maxPriceDigit = symbol["maxPriceDigit"].ConvertInvariant <double>();
                var priceStepSize = Math.Pow(10, -maxPriceDigit);
                market.PriceStepSize = priceStepSize.ConvertInvariant <decimal>();
                //最小交易量限制
                market.MinTradeSize = symbol["minTradeSize"].ConvertInvariant <decimal>();

                markets.Add(market);
            }

            WriteCache("GetSymbolsMetadata", TimeSpan.FromMinutes(60.0), markets);

            return(markets);
        }
Пример #5
0
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            //https://poloniex.com/public?command=returnOrderBook&currencyPair=all&depth=0

            /*
             *       "BTC_CLAM": {
             * "asks": [],
             * "bids": [],
             * "isFrozen": "0",
             * "seq": 37268918
             * }, ...
             */

            var markets = new List <ExchangeMarket>();
            Dictionary <string, JToken> lookup = await MakeJsonRequestAsync <Dictionary <string, JToken> >("/public?command=returnOrderBook&currencyPair=all&depth=0");

            // StepSize is 8 decimal places for both price and amount on everything at Polo
            const decimal StepSize     = 0.00000001m;
            const decimal minTradeSize = 0.0001m;

            foreach (var kvp in lookup)
            {
                var market = new ExchangeMarket {
                    MarketName = kvp.Key, IsActive = false
                };

                string isFrozen = kvp.Value["isFrozen"].ToStringInvariant();
                if (string.Equals(isFrozen, "0"))
                {
                    market.IsActive = true;
                }

                string[] pairs = kvp.Key.Split('_');
                if (pairs.Length == 2)
                {
                    market.BaseCurrency     = pairs[0];
                    market.MarketCurrency   = pairs[1];
                    market.PriceStepSize    = StepSize;
                    market.QuantityStepSize = StepSize;
                    market.MinPrice         = StepSize;
                    market.MinTradeSize     = minTradeSize;
                }

                markets.Add(market);
            }

            return(markets);
        }
Пример #6
0
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            if (ReadCache("GetSymbols", out List <ExchangeMarket> cachedMarkets))
            {
                return(cachedMarkets);
            }

            var markets = new List <ExchangeMarket>();

            JToken allPairs = await MakeJsonRequestAsync <JToken>("/symbols_details", BaseUrlV1);

            Match m;

            foreach (JToken pair in allPairs)
            {
                var market = new ExchangeMarket
                {
                    IsActive     = true,
                    MarketName   = NormalizeSymbol(pair["pair"].ToStringInvariant()),
                    MinTradeSize = pair["minimum_order_size"].ConvertInvariant <decimal>()
                };
                m = Regex.Match(market.MarketName, "^(BTC|USD|ETH|GBP|JPY|EUR|EOS)");
                if (m.Success)
                {
                    market.MarketCurrency = m.Value;
                    market.BaseCurrency   = market.MarketName.Substring(m.Length);
                }
                else
                {
                    m = Regex.Match(market.MarketName, "(BTC|USD|ETH|GBP|JPY|EUR|EOS)$");
                    if (m.Success)
                    {
                        market.MarketCurrency = market.MarketName.Substring(0, m.Index);
                        market.BaseCurrency   = m.Value;
                    }
                    else
                    {
                        throw new System.IO.InvalidDataException("Unexpected market name: " + market.MarketName);
                    }
                }
                int pricePrecision = pair["price_precision"].ConvertInvariant <int>();
                market.PriceStepSize = (decimal)Math.Pow(0.1, pricePrecision);
                markets.Add(market);
            }

            WriteCache("GetSymbols", TimeSpan.FromMinutes(60.0), markets);
            return(markets);
        }
Пример #7
0
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            List <ExchangeMarket> markets = new List <ExchangeMarket>();
            // [ { "coinType": "KCS", "trading": true, "lastDealPrice": 4500,"buy": 4120, "sell": 4500, "coinTypePair": "BTC", "sort": 0,"feeRate": 0.001,"volValue": 324866889, "high": 6890, "datetime": 1506051488000, "vol": 5363831663913, "low": 4500, "changeRate": -0.3431 }, ... ]
            JToken token = await MakeJsonRequestAsync <JToken>("/market/open/symbols");

            foreach (JToken symbol in token)
            {
                ExchangeMarket market = new ExchangeMarket()
                {
                    IsActive       = symbol["trading"].ConvertInvariant <bool>(),
                    MarketCurrency = symbol["coinType"].ToStringInvariant(),
                    BaseCurrency   = symbol["coinTypePair"].ToStringInvariant(),
                };
                market.MarketName = market.MarketCurrency + "-" + market.BaseCurrency;
                markets.Add(market);
            }
            return(markets);
        }
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            var    markets  = new List <ExchangeMarket>();
            JToken products = await MakeJsonRequestAsync <JToken>("/products");

            foreach (JToken product in products)
            {
                var market = new ExchangeMarket
                {
                    MarketName     = product["id"].ToStringUpperInvariant(),
                    BaseCurrency   = product["quote_currency"].ToStringUpperInvariant(),
                    MarketCurrency = product["base_currency"].ToStringUpperInvariant(),
                    IsActive       = string.Equals(product["status"].ToStringInvariant(), "online", StringComparison.OrdinalIgnoreCase),
                    MinTradeSize   = product["base_min_size"].ConvertInvariant <decimal>(),
                    PriceStepSize  = product["quote_increment"].ConvertInvariant <decimal>()
                };
                markets.Add(market);
            }

            return(markets);
        }
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            List <ExchangeMarket> markets = new List <ExchangeMarket>();
            // {"success": true,"minBtcVolume": 0.0005,"restrictions": [{"currencyPair": "BTC/USD","priceScale": 5}, ... ]}
            JToken token = await MakeJsonRequestAsync <JToken>("/exchange/restrictions");

            foreach (JToken market in token["restrictions"])
            {
                var split          = market["currencyPair"].ToStringInvariant().Split('/');
                var exchangeMarket = new ExchangeMarket
                {
                    MarketName     = market["currencyPair"].ToStringInvariant(),
                    BaseCurrency   = split[1],
                    MarketCurrency = split[0],
                    IsActive       = true,
                    MinTradeSize   = (decimal)market["minLimitQuantity"],
                    PriceStepSize  = (decimal?)(1 / Math.Pow(10, (int)market["priceScale"]))
                };

                markets.Add(exchangeMarket);
            }
            return(markets);
        }
Пример #10
0
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            /*
             * {
             *  "status"
             * :
             *  "ok", "data"
             * :
             *  [{
             *      "base-currency": "btc",
             *      "quote-currency": "usdt",
             *      "price-precision": 2,
             *      "amount-precision": 4,
             *      "symbol-partition": "main"
             *  }, {
             *      "base-currency": "bch",
             *      "quote-currency": "usdt",
             *      "price-precision": 2,
             *      "amount-precision": 4,
             *      "symbol-partition": "main"
             *  },
             *
             */
            if (ReadCache("GetSymbolsMetadata", out List <ExchangeMarket> markets))
            {
                return(markets);
            }

            markets = new List <ExchangeMarket>();
            JToken allSymbols = await MakeJsonRequestAsync <JToken>("/common/symbols", BaseUrlV1, null);

            //List<HuoBiTradeCoinLimitModel> cacheLimits = IOCacheHelper.Deserialize<List<HuoBiTradeCoinLimitModel>>("HB_TradeCoin_Limits.json") ?? new List<HuoBiTradeCoinLimitModel>();
            foreach (var symbol in allSymbols)
            {
                var    marketCurrency   = symbol["base-currency"].ToStringLowerInvariant();
                var    baseCurrency     = symbol["quote-currency"].ToStringLowerInvariant();
                var    price_precision  = symbol["price-precision"].ConvertInvariant <double>();
                var    priceStepSize    = Math.Pow(10, -price_precision);
                var    amount_precision = symbol["amount-precision"].ConvertInvariant <double>();
                var    quantityStepSize = Math.Pow(10, -amount_precision);
                string symStr           = $"{marketCurrency.ToLower()}{baseCurrency.ToLower()}";
                //HuoBiTradeCoinLimitModel orderRule = cacheLimits?.FirstOrDefault(q => q.data.symbol.Equals(symStr));
                // if (orderRule == null)
                //{
                //    orderRule = await MakeJsonRequestAsync<HuoBiTradeCoinLimitModel>($"/common/exchange?symbol={symStr}", BaseUrlV1, null);
                //    cacheLimits.Add(orderRule);
                //    Console.WriteLine($"{symbol["symbol"]}限制条件Get!");
                //}
                //limitOrder
                var limitOrder = new ExchangeMarket()
                {
                    OrderType        = MarketOrderType.LimitBuy | MarketOrderType.LimitSell,
                    MarketCurrency   = marketCurrency,
                    BaseCurrency     = baseCurrency,
                    MarketName       = marketCurrency + baseCurrency,
                    IsActive         = true,
                    PriceStepSize    = priceStepSize.ConvertInvariant <decimal>(),
                    QuantityStepSize = quantityStepSize.ConvertInvariant <decimal>(),
                    //MinTradeSize = orderRule.data.limit_order_must_greater_than.ConvertInvariant<decimal>(),
                    //MaxTradeSize = orderRule.data.limit_order_must_less_than.ConvertInvariant<decimal>()
                };
                //var marketBuy = new ExchangeMarket()
                //{
                //    OrderType = MarketOrderType.MarketBuy,
                //    MarketCurrency = marketCurrency,
                //    BaseCurrency = baseCurrency,
                //    MarketName = marketCurrency + baseCurrency,
                //    IsActive = true,
                //    PriceStepSize = null,
                //    QuantityStepSize = null,
                //    MinTradeSize = orderRule.data.market_buy_order_must_greater_than.ConvertInvariant<decimal>(),
                //    MaxTradeSize = orderRule.data.market_buy_order_must_less_than.ConvertInvariant<decimal>()
                //};
                //var marketSell = new ExchangeMarket()
                //{
                //    OrderType = MarketOrderType.MarketSell,
                //    MarketCurrency = marketCurrency,
                //    BaseCurrency = baseCurrency,
                //    MarketName = marketCurrency + baseCurrency,
                //    IsActive = true,
                //    PriceStepSize = null,
                //    QuantityStepSize = quantityStepSize.ConvertInvariant<decimal>(),
                //    MinTradeSize = orderRule.data.market_sell_order_must_greater_than.ConvertInvariant<decimal>(),
                //    MaxTradeSize = orderRule.data.market_sell_order_must_less_than.ConvertInvariant<decimal>()
                //};
                markets.Add(limitOrder);
                //markets.Add(marketBuy);
                //markets.Add(marketSell);
            }
            //IOCacheHelper.SerializeToFile(cacheLimits, "HB_TradeCoin_Limits.json");
            WriteCache("GetSymbolsMetadata", TimeSpan.FromMinutes(60.0), markets);

            return(markets);
        }
        protected override async Task <IEnumerable <ExchangeMarket> > OnGetSymbolsMetadataAsync()
        {
            /*
             *         {
             * "symbol": "QTUMETH",
             * "status": "TRADING",
             * "baseAsset": "QTUM",
             * "baseAssetPrecision": 8,
             * "quoteAsset": "ETH",
             * "quotePrecision": 8,
             * "orderTypes": [
             *  "LIMIT",
             *  "LIMIT_MAKER",
             *  "MARKET",
             *  "STOP_LOSS_LIMIT",
             *  "TAKE_PROFIT_LIMIT"
             * ],
             * "icebergAllowed": true,
             * "filters": [
             *  {
             *      "filterType": "PRICE_FILTER",
             *      "minPrice": "0.00000100",
             *      "maxPrice": "100000.00000000",
             *      "tickSize": "0.00000100"
             *  },
             *  {
             *      "filterType": "LOT_SIZE",
             *      "minQty": "0.01000000",
             *      "maxQty": "90000000.00000000",
             *      "stepSize": "0.01000000"
             *  },
             *  {
             *      "filterType": "MIN_NOTIONAL",
             *      "minNotional": "0.01000000"
             *  }
             * ]
             * },
             */

            var    markets = new List <ExchangeMarket>();
            JToken obj     = await MakeJsonRequestAsync <JToken>("/exchangeInfo");

            JToken allSymbols = obj["symbols"];

            foreach (JToken symbol in allSymbols)
            {
                var market = new ExchangeMarket
                {
                    MarketName     = symbol["symbol"].ToStringUpperInvariant(),
                    IsActive       = ParseMarketStatus(symbol["status"].ToStringUpperInvariant()),
                    BaseCurrency   = symbol["quoteAsset"].ToStringUpperInvariant(),
                    MarketCurrency = symbol["baseAsset"].ToStringUpperInvariant()
                };

                // "LOT_SIZE"
                JToken filters       = symbol["filters"];
                JToken lotSizeFilter = filters?.FirstOrDefault(x => string.Equals(x["filterType"].ToStringUpperInvariant(), "LOT_SIZE"));
                if (lotSizeFilter != null)
                {
                    market.MaxTradeSize     = lotSizeFilter["maxQty"].ConvertInvariant <decimal>();
                    market.MinTradeSize     = lotSizeFilter["minQty"].ConvertInvariant <decimal>();
                    market.QuantityStepSize = lotSizeFilter["stepSize"].ConvertInvariant <decimal>();
                }

                // PRICE_FILTER
                JToken priceFilter = filters?.FirstOrDefault(x => string.Equals(x["filterType"].ToStringUpperInvariant(), "PRICE_FILTER"));
                if (priceFilter != null)
                {
                    market.MaxPrice      = priceFilter["maxPrice"].ConvertInvariant <decimal>();
                    market.MinPrice      = priceFilter["minPrice"].ConvertInvariant <decimal>();
                    market.PriceStepSize = priceFilter["tickSize"].ConvertInvariant <decimal>();
                }

                // PRICE_FILTER
                JToken notionalFilter = filters?.FirstOrDefault(x => string.Equals(x["filterType"].ToStringUpperInvariant(), "MIN_NOTIONAL"));
                if (notionalFilter != null)
                {
                    market.MinNotional = notionalFilter["minNotional"].ConvertInvariant <decimal>();
                }
                markets.Add(market);
            }

            return(markets);
        }