public static List <string> FilterByBaseCurency( this List <string> symbols, ExchangerEnum exchanger = ExchangerEnum.Bittrex, BaseCurrencyEnum currency = BaseCurrencyEnum.BTC) { return(symbols.Where(s => s.ToUpper().StartsWith(currency.ToString())).ToList()); }
public async Task <List <ExchangeSymbol> > GetExchangeSymbols(BaseCurrencyEnum currency = BaseCurrencyEnum.BTC) { var ignoreCoinSettings = this.options.Value.IgnoreCoinSettings; var cachedSymbols = this.memoryCache.Get <List <ExchangeSymbol> >(SymbolsKey); if (cachedSymbols != null) { return(cachedSymbols); } var binanceSymbols = (await this.binanceApi.GetSymbolsAsync()).ToList().FilterByBaseCurency(currency); var bittrexSymbols = this.enableOptions.Value.Binance ? (await this.bittrexApi.GetSymbolsAsync()).ToList().FilterByBaseCurency(ExchangerEnum.Bittrex, currency) : null; var kucoinSymbols = this.enableOptions.Value.Binance ? (await this.kucoinApi.GetSymbolsAsync()).ToList().FilterByBaseCurency(currency) : null; var cryptopiaSymbols = this.enableOptions.Value.Binance ? (await this.cryptopiaApi.GetSymbolsAsync()).ToList().FilterByBaseCurency(currency) : null; var okexSymbols = this.enableOptions.Value.Binance ? (await this.okexApi.GetSymbolsAsync()).ToList().FilterByBaseCurency(currency) : null; var gateSymbols = this.enableOptions.Value.Binance ? (await this.gateApi.GetSymbolsAsync()).ToList() : null; var huobiSymbols = this.enableOptions.Value.Binance ? (await this.huobiApi.GetSymbolsAsync()).ToList() : null; var globalSymbols = binanceSymbols.Select( x => new ExchangeSymbol { GlobalSymbol = SymbolHelper.ToGlobalSymbol(x, ExchangerEnum.Binance) }).ToList(); if (ignoreCoinSettings != null) { binanceSymbols = binanceSymbols.FilterByIgnoreCoins(ignoreCoinSettings, ExchangerEnum.Binance); bittrexSymbols = bittrexSymbols.FilterByIgnoreCoins(ignoreCoinSettings, ExchangerEnum.Bittrex); kucoinSymbols = kucoinSymbols.FilterByIgnoreCoins(ignoreCoinSettings, ExchangerEnum.KuCoin); cryptopiaSymbols = cryptopiaSymbols.FilterByIgnoreCoins(ignoreCoinSettings, ExchangerEnum.Cryptopia); okexSymbols = okexSymbols.FilterByIgnoreCoins(ignoreCoinSettings, ExchangerEnum.Okex); gateSymbols = gateSymbols.FilterByIgnoreCoins(ignoreCoinSettings, ExchangerEnum.Gate); huobiSymbols = huobiSymbols.FilterByIgnoreCoins(ignoreCoinSettings, ExchangerEnum.Huobi); } globalSymbols = globalSymbols.FillExchangerSymbols(ExchangerEnum.Binance, binanceSymbols); globalSymbols = globalSymbols.FillExchangerSymbols(ExchangerEnum.Bittrex, bittrexSymbols); globalSymbols = globalSymbols.FillExchangerSymbols(ExchangerEnum.KuCoin, kucoinSymbols); globalSymbols = globalSymbols.FillExchangerSymbols(ExchangerEnum.Cryptopia, cryptopiaSymbols); globalSymbols = globalSymbols.FillExchangerSymbols(ExchangerEnum.Okex, okexSymbols); globalSymbols = globalSymbols.FillExchangerSymbols(ExchangerEnum.Gate, gateSymbols); globalSymbols = globalSymbols.FillExchangerSymbols(ExchangerEnum.Huobi, huobiSymbols); this.memoryCache.Set(SymbolsKey, globalSymbols); return(globalSymbols); }
public static List <ExchangeSymbol> FilterByBaseCurency( this List <ExchangeSymbol> globalSymbols, BaseCurrencyEnum currency = BaseCurrencyEnum.BTC) { return(globalSymbols .Where( s => !string.IsNullOrEmpty(s.Bittrex) || !string.IsNullOrEmpty(s.HitBtc) || !string.IsNullOrEmpty(s.KuCoin)) .Where(s => s.GlobalSymbol.EndsWith(currency.ToString())).ToList()); }
/// <inheritdoc /> public async Task <IEnumerable <CoinInfo> > GetExchangerCoinInfoAsync( BaseCurrencyEnum currency = BaseCurrencyEnum.BTC) { var coins = this.memoryCache.Get <List <CoinInfo> >(CoinInfoKey); if (coins != null) { return(coins); } var binanceMarket = this.enableOptions.Value.Binance ? (await this.binanceApi.GetTickersAsync()).ToList() : null; var bittrexMarket = this.enableOptions.Value.Bittrex ? (await this.bittrexApi.GetTickersAsync()).ToList() : null; var kucoinMarket = this.enableOptions.Value.KuCoin ? (await this.kucoinApi.GetTickersAsync()).ToList() : null; var cryptopiaMarket = this.enableOptions.Value.Cryptopia ? (await this.cryptopiaApi.GetTickersAsync()).ToList() : null; var okexMarket = this.enableOptions.Value.Okex ? (await this.okexApi.GetTickersAsync()).ToList() : null; var gateMarket = this.enableOptions.Value.Gate ? (await this.gateApi.GetTickersAsync()).ToList() : null; var huobiMarket = this.enableOptions.Value.Huobi ? (await this.huobiApi.GetTickersAsync()).ToList() : null; var symbols = await GetExchangeSymbols(); coins = symbols.Select( x => new CoinInfo { ExchangeSymbol = x, Currency = BaseCurrencyEnum.BTC, ExchangePrices = new List <ExchangePrice>() }).ToList(); coins = coins.FillCoinPrices(ExchangerEnum.Binance, binanceMarket); coins = coins.FillCoinPrices(ExchangerEnum.Bittrex, bittrexMarket); coins = coins.FillCoinPrices(ExchangerEnum.KuCoin, kucoinMarket); coins = coins.FillCoinPrices(ExchangerEnum.Cryptopia, cryptopiaMarket); coins = coins.FillCoinPrices(ExchangerEnum.Okex, okexMarket); coins = coins.FillCoinPrices(ExchangerEnum.Gate, gateMarket); coins = coins.FillCoinPrices(ExchangerEnum.Huobi, huobiMarket); coins = coins.ToAnalizedExchangePrice(); coins = coins .OrderByDescending(opt => opt.ExchangePrices.Max(price => price.Percent)) .ToList(); this.memoryCache.Set(CoinInfoKey, coins); return(coins); }
/// <summary> /// Initializes a new instance of the <see cref="Instrument" /> class. /// </summary> /// <param name="quoteCurrency">The currency in which the instrument prices are quoted. (required).</param> /// <param name="kind">Instrument kind, `\"future\"` or `\"option\"` (required).</param> /// <param name="tickSize">specifies minimal price change and, as follows, the number of decimal places for instrument prices (required).</param> /// <param name="contractSize">Contract size for instrument (required).</param> /// <param name="isActive">Indicates if the instrument can currently be traded. (required).</param> /// <param name="optionType">The option type (only for options).</param> /// <param name="minTradeAmount">Minimum amount for trading. For perpetual and futures - in USD units, for options it is amount of corresponding cryptocurrency contracts, e.g., BTC or ETH. (required).</param> /// <param name="instrumentName">Unique instrument identifier (required).</param> /// <param name="settlementPeriod">The settlement period. (required).</param> /// <param name="strike">The strike value. (only for options).</param> /// <param name="baseCurrency">The underlying currency being traded. (required).</param> /// <param name="creationTimestamp">The time when the instrument was first created (milliseconds) (required).</param> /// <param name="expirationTimestamp">The time when the instrument will expire (milliseconds) (required).</param> public Instrument(QuoteCurrencyEnum quoteCurrency = default(QuoteCurrencyEnum), KindEnum kind = default(KindEnum), decimal?tickSize = default(decimal?), int?contractSize = default(int?), bool?isActive = default(bool?), OptionTypeEnum?optionType = default(OptionTypeEnum?), decimal?minTradeAmount = default(decimal?), string instrumentName = default(string), SettlementPeriodEnum settlementPeriod = default(SettlementPeriodEnum), decimal?strike = default(decimal?), BaseCurrencyEnum baseCurrency = default(BaseCurrencyEnum), int?creationTimestamp = default(int?), int?expirationTimestamp = default(int?)) { // to ensure "quoteCurrency" is required (not null) if (quoteCurrency == null) { throw new InvalidDataException("quoteCurrency is a required property for Instrument and cannot be null"); } else { this.QuoteCurrency = quoteCurrency; } // to ensure "kind" is required (not null) if (kind == null) { throw new InvalidDataException("kind is a required property for Instrument and cannot be null"); } else { this.Kind = kind; } // to ensure "tickSize" is required (not null) if (tickSize == null) { throw new InvalidDataException("tickSize is a required property for Instrument and cannot be null"); } else { this.TickSize = tickSize; } // to ensure "contractSize" is required (not null) if (contractSize == null) { throw new InvalidDataException("contractSize is a required property for Instrument and cannot be null"); } else { this.ContractSize = contractSize; } // to ensure "isActive" is required (not null) if (isActive == null) { throw new InvalidDataException("isActive is a required property for Instrument and cannot be null"); } else { this.IsActive = isActive; } // to ensure "minTradeAmount" is required (not null) if (minTradeAmount == null) { throw new InvalidDataException("minTradeAmount is a required property for Instrument and cannot be null"); } else { this.MinTradeAmount = minTradeAmount; } // to ensure "instrumentName" is required (not null) if (instrumentName == null) { throw new InvalidDataException("instrumentName is a required property for Instrument and cannot be null"); } else { this.InstrumentName = instrumentName; } // to ensure "settlementPeriod" is required (not null) if (settlementPeriod == null) { throw new InvalidDataException("settlementPeriod is a required property for Instrument and cannot be null"); } else { this.SettlementPeriod = settlementPeriod; } // to ensure "baseCurrency" is required (not null) if (baseCurrency == null) { throw new InvalidDataException("baseCurrency is a required property for Instrument and cannot be null"); } else { this.BaseCurrency = baseCurrency; } // to ensure "creationTimestamp" is required (not null) if (creationTimestamp == null) { throw new InvalidDataException("creationTimestamp is a required property for Instrument and cannot be null"); } else { this.CreationTimestamp = creationTimestamp; } // to ensure "expirationTimestamp" is required (not null) if (expirationTimestamp == null) { throw new InvalidDataException("expirationTimestamp is a required property for Instrument and cannot be null"); } else { this.ExpirationTimestamp = expirationTimestamp; } this.OptionType = optionType; this.Strike = strike; }
public static List <string> FilterByBaseCurency( this List <string> symbols, BaseCurrencyEnum currency = BaseCurrencyEnum.BTC) { return(symbols.Where(s => s.ToUpper().EndsWith(currency.ToString())).ToList()); }