public void Monitor() { try { var eligibleSymbols = _exchange.Coins.Select(m => m.Symbol) .Union(_exchange.Coins.SelectMany(m => m.Coins).Select(m => m.Symbol)).Distinct().ToList(); var eligibleCombinedSymbols = new List <SymbolDto>(); foreach (var symbol1 in eligibleSymbols) { foreach (var symbol2 in eligibleSymbols.Where(m => m != symbol1)) { eligibleCombinedSymbols.Add(new SymbolDto($"{symbol1}{symbol2}", symbol1, symbol2)); } } var tickers = _apiService.Get <ResponseDto <List <TickerDto> > >(_apiService.PublicUrl, "/LiveTickers").tickers; tickers = tickers.Where(m => eligibleCombinedSymbols.Select(n => n.Combined).Contains(m.currencyPair)).ToList(); foreach (var ticker in tickers) { var symbolDto = eligibleCombinedSymbols.FirstOrDefault(m => m.Combined == ticker.currencyPair); if (symbolDto != null) { var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(ticker).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.TrustDex, symbolDto.From, symbolDto.To, pricingItem); } } } catch (Exception ex) { Colorful.Console.WriteLine($"Gatecoin Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }
public void Monitor() { try { var eligibleSymbols = _exchange.Coins.Select(m => m.Symbol) .Union(_exchange.Coins.SelectMany(m => m.Coins).Select(m => m.Symbol)).Distinct().ToList(); var response = _apiService.Get <JArray>(_apiService.PublicUrl, "/return_ticket.php"); var tickers = new BuilderFactory().CreateCollection <JToken, TickerDto>(response).Build(); tickers = tickers.Where(m => m.active && eligibleSymbols.Contains(m.fromSymbol) && eligibleSymbols.Contains(m.toSymbol) && !SymbolConstants.FiatCurrency.Contains(m.fromSymbol) && !SymbolConstants.FiatCurrency.Contains(m.toSymbol)).ToList(); foreach (var ticker in tickers) { var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(ticker).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.TrustDex, ticker.fromSymbol, ticker.toSymbol, pricingItem); } } catch (Exception ex) { Colorful.Console.WriteLine($"TrustDex Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }
internal T Create <T>() where T : IBuilder { T builder = _factory.Create <T>(); builder.BuilderFactoryConvention.UseFactory(_factory); return(builder); }
public void Monitor() { try { foreach (var coin in _exchange.Coins) { foreach (var childCoin in coin.Coins) { try { var ticker = _apiService.Get <ResponseDto <List <TickerDto> > >(_apiService.PublicUrl, $"/getticker?market={coin.Symbol}_{childCoin.Symbol}").result.First(); var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(ticker).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.Bleutrade, coin.Symbol, childCoin.Symbol, pricingItem); } catch (Exception e) { //Colorful.Console.WriteLine(e, Color.Red); } Task.Delay(500).Wait(); } } } catch (Exception ex) { Colorful.Console.WriteLine($"Bleutrade Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }
public void Monitor() { try { var tickers = _apiService.Get <Dictionary <string, TickerDto> >(_apiService.PublicUrl, "/ticker"); foreach (var ticker in tickers) { ticker.Value.from_symbol = ticker.Key.Split("_")[0]; ticker.Value.to_symbol = ticker.Key.Split("_")[1]; } var products = tickers.Select(m => m.Value).ToList(); var validProducts = products.Where(m => !SymbolConstants.FiatCurrency.Contains(m.from_symbol) && !SymbolConstants.FiatCurrency.Contains(m.to_symbol)).ToList(); foreach (var product in validProducts) { var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(product).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.Exmo, product.from_symbol, product.to_symbol, pricingItem); } } catch (Exception ex) { Colorful.Console.WriteLine($"Exmo Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }
public void Monitor() { //try //{ // var socket = new ClientWebSocket(); // var task = socket.ConnectAsync(new Uri("wss://api.poloniex.com"), CancellationToken.None); // task.Wait(); // var readThread = new Thread(() => MessageRecived(socket)) { IsBackground = true }; // readThread.Start(); // var json = "{\"type\":\"subscribe\",\"channels\":[{\"name\":\"ticker\", \"product_ids\": [" + BuildProductIdString() + "]}]}"; // var bytes = Encoding.UTF8.GetBytes(json); // var subscriptionMessageBuffer = new ArraySegment<byte>(bytes); // socket.SendAsync(subscriptionMessageBuffer, WebSocketMessageType.Text, true, CancellationToken.None); //} //catch (Exception ex) //{ //} //while (true) //{ // Thread.Sleep(60000); //foreach (var coin in _exchange.Coins) //{ // foreach (var childCoin in coin.Coins) // { // } //} //} //PricingService.Instance.GetCurrentPrice(_exchange.Name, coin.Symbol, childCoin.Symbol); try { var response = _apiService.Get <Dictionary <string, TickerDto> >(_apiService.PublicUrl, "?command=returnTicker"); foreach (var key in response.Keys) { response[key].FromSymbol = key.Split("_")[1]; response[key].ToSymbol = key.Split("_")[0]; } var products = response.Values.Where(m => m.IsFrozenBool == false).ToList(); foreach (var product in products) { if (product != null) { var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(product).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.Poloniex, product.FromSymbol, product.ToSymbol, pricingItem); } } } catch (Exception ex) { Colorful.Console.WriteLine($"Poloniex Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }
public IEnumerable <TOTYPE> Build() { var toList = new List <TOTYPE>(); if (_sourcetypes != null) { foreach (var fromtype in _sourcetypes) { toList.Add(_builderFactory.Create <FROMTYPE, TOTYPE>(fromtype).Build()); } } return(toList); }
public void ListenToCryptoCompareTicker(List <Exchange> exchanges) { var subParams = BuildCryptoTickerSubscriptionParameters(exchanges); var subParamsString = string.Join(",", subParams); var subscribeParam = $@"{{ subs: [{subParamsString}]}}"; _cryptoCompareSocket = IO.Socket("wss://streamer.cryptocompare.com"); _cryptoCompareSocket.On(Socket.EVENT_CONNECT, () => { _cryptoCompareSocket.Emit("SubAdd", JObject.Parse(subscribeParam)); }); _cryptoCompareSocket.On("m", (data) => { if (data != null && !string.IsNullOrEmpty(data.ToString())) { var dataArray = data.ToString().Split('~'); if (dataArray.Length >= 7 && dataArray[0] == "2") { //File.AppendAllLines(@"C:\temp\socketdata.txt", new List<string> { data.ToString() }, Encoding.UTF8); //var previousData = PricingService.Instance.GetCurrentPricingAsStringArray(currentTicker.Market, currentTicker.FromSymbol, currentTicker.ToSymbol); //todo: keep previous record per exchange in ram so we can keep it up to date and use the values that are missing from the update records. var key = $"{dataArray[1]}_{dataArray[2]}_{dataArray[3]}"; var previousData = _currentCryptoCompareRows.ContainsKey(key) ? _currentCryptoCompareRows[key] : null; var wrappedData = new SocketDataWrapperDto(dataArray, previousData); var currentTicker = _builderFactory.Create <SocketDataWrapperDto, TickerDto>(wrappedData).Build(); //Console.WriteLine(JsonConvert.SerializeObject(currentTicker)); var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(currentTicker).Build(); //TODO: This used to be PricingService.Instance.UpdatePricingForMinute so this might not work correctly; UpdatePricingForMinute(currentTicker.Market, currentTicker.FromSymbol, currentTicker.ToSymbol, pricingItem); _currentCryptoCompareRows[key] = wrappedData.PreviousData != null ? wrappedData.PreviousData : wrappedData.Data; } } }); }
public List <Exchange> GetConfiguredExchanges() { var result = new List <Exchange>(); var configuredApis = GetApiConfigurations(); if (configuredApis == null || !configuredApis.Any()) { throw new Exception("There must be at least two configured APIs in the api.json file."); } foreach (var api in configuredApis.Where(m => m.Configured)) { result.Add(_builderFactory.Create <ApiConfigurationData, Exchange>(api).Build()); } return(result); }
public void Monitor() { try { var markets = _apiService.Get <Dictionary <string, MarketDto> >(_apiService.PublicUrl, "/").Select(m => m.Value).ToList(); foreach (var market in markets) { var pricingItem = _builderFactory.Create <MarketDto, PricingItem>(market).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.BXinth, market.secondary_currency, market.primary_currency, pricingItem); } } catch (Exception ex) { Colorful.Console.WriteLine($"BXinth Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }
private void OnMessage(string message, WebSocketWrapper wrapper) { var item = JsonConvert.DeserializeObject <ResponseDto <TickerDto> >(message); if (item.Method == "ticker" && !string.IsNullOrEmpty(item.Params.Ask) && !string.IsNullOrEmpty(item.Params.Bid)) { var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(item.Params).Build(); if (_symbolLookup.ContainsKey(item.Params.Symbol)) { var symbolPair = _symbolLookup[item.Params.Symbol].Split(","); var fromSymbol = symbolPair[0]; var toSymbol = symbolPair[1]; _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.HitBtc, fromSymbol, toSymbol, pricingItem); } } }
private void OnMessage(string message, WebSocketWrapper wrapper) { if (string.IsNullOrEmpty(message)) { return; } var items = JsonConvert.DeserializeObject <TickerChannelDto>(message); if (items.Type == "ticker") { var pricingItem = _builderFactory.Create <TickerChannelDto, PricingItem>(items).Build(); var fromSymbol = items.Product_Id.Split("-")[0]; var toSymbol = items.Product_Id.Split("-")[1]; _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.Coinbase, fromSymbol, toSymbol, pricingItem); } }
public void Monitor() { try { //Should probably also use the getticker endpoint as the data is not cached as long and more up-to-date. var response = _apiService.Get <ResponseDto <List <MarketSummaryDto> > >(_apiService.PublicUrl, "/public/getmarketsummaries"); var products = response.Result.OrderByDescending(m => m.BaseVolume).ThenByDescending(m => m.Volume).ToList(); foreach (var product in products) { var pricingItem = _builderFactory.Create <MarketSummaryDto, PricingItem>(product).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.BitTrex, product.MarketCurrency, product.BaseCurrency, pricingItem); } } catch (Exception ex) { Colorful.Console.WriteLine($"Bittrex Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }
private void OnMessage(string message, WebSocketWrapper wrapper) { if (!string.IsNullOrEmpty(message) && message.Contains("\"e\":\"24hrTicker\"")) { try { var items = JsonConvert.DeserializeObject <TickerDto>(message); var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(items).Build(); var fromSymbol = _channels[items.Symbol.ToUpper()].Split(",")[0]; var toSymbol = _channels[items.Symbol.ToUpper()].Split(",")[1]; _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(_apiService.Name, fromSymbol, toSymbol, pricingItem); } catch (Exception ex) { Colorful.Console.WriteLine($"Binance OnMessage(): {ex.Message}", Color.Red); } } }
public void Monitor() { try { foreach (var coin in _exchange.Coins) { foreach (var childCoin in coin.Coins) { var ticker = _apiService.Get <TickerDto>(_apiService.PublicUrl, $"/v1/pubticker/{coin.Symbol.ToLower()}{childCoin.Symbol.ToLower()}"); var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(ticker).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.Gemini, coin.Symbol, childCoin.Symbol, pricingItem); } } } catch (Exception ex) { Colorful.Console.WriteLine($"Gemini Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }
public void Monitor() { try { foreach (var coin in _exchange.Coins) { foreach (var childCoin in coin.Coins) { var product = _apiService.Get <TickerDto>(_apiService.PublicUrl, $"/products/{coin.Symbol}-{childCoin.Symbol}/ticker"); if (product != null) { var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(product).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.Abucoins, coin.Symbol, childCoin.Symbol, pricingItem); } } } } catch (Exception ex) { Colorful.Console.WriteLine($"Abucoins Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }
public void Monitor() { try { var response = _apiService.Get <List <TickerDto> >(_apiService.PublicUrl, "/tickers"); var symbolList = _exchange.Coins.Select(n => n.Symbol) .Union(_exchange.Coins.SelectMany(n => n.Coins).Select(n => n.Symbol)).ToList(); var products = response .OrderByDescending(m => m.Volume24Hour) .Where(m => symbolList.Contains(m.FromSymbol) && symbolList.Contains(m.ToSymbol)).ToList(); foreach (var product in products) { var pricingItem = _builderFactory.Create <TickerDto, PricingItem>(product).Build(); _serviceProvider.GetRequiredService <IPricingService>().UpdatePricingForMinute(ExchangeConstants.WavesDex, product.FromSymbol, product.ToSymbol, pricingItem); } } catch (Exception ex) { Colorful.Console.WriteLine($"WavesDex Monitor(): {ex.Message}\r\n{ex.StackTrace}", Color.Red); } }