protected async Task <T> Get <T>( string resource) where T : new() { await throttle.WaitTillReady(); T result = await restClient.AsyncDownload <T>(resource, method : method); throttle.SetLastUpdateTime(); return(result); }
async Task Refresh() { List <CoinMarketCapTickerJson> resultList = await restClient.AsyncDownload <List <CoinMarketCapTickerJson> >("v1/ticker/?limit=0"); if (resultList == null) { // Parsing error, it may work on the next refresh log.Error("Refresh failed"); return; } for (int i = 0; i < resultList.Count; i++) { CoinMarketCapTickerJson ticker = resultList[i]; Debug.Assert(ticker != null); Coin coin = Coin.CreateFromName(ticker.name); if (coin == null) { // Blacklisted continue; } DateTime lastUpdated; if (long.TryParse(ticker.last_updated, out long secondsSince)) { lastUpdated = DateTimeOffset.FromUnixTimeSeconds(secondsSince).DateTime; } else { lastUpdated = default(DateTime); } tickerLowerToCoin[ticker.symbol.ToLowerInvariant()] = coin; coin.coinMarketCapData = new Data.MarketCap( ticker.symbol, int.Parse(ticker.rank), ticker.price_btc.ToNullableDecimal(), ticker.price_usd.ToNullableDecimal(), ticker._24h_volume_usd.ToNullableDecimal(), ticker.market_cap_usd.ToNullableDecimal(), ticker.available_supply.ToNullableDecimal(), ticker.total_supply.ToNullableDecimal(), ticker.max_supply.ToNullableDecimal(), ticker.percent_change_1h.ToNullableDecimal(), ticker.percent_change_24h.ToNullableDecimal(), ticker.percent_change_7d.ToNullableDecimal(), lastUpdated); } }
public async Task Refresh() { List <CoinMarketCapTickerJson> resultList = await restClient.AsyncDownload <List <CoinMarketCapTickerJson> >("v1/ticker/?limit=0"); for (int i = 0; i < resultList.Count; i++) { CoinMarketCapTickerJson ticker = resultList[i]; Coin coin = Coin.CreateFromName2(ticker.name); if (coin == null) { // Blacklisted continue; } coin.coinMarketCapData = ticker; } }
protected async Task <T> Get <T>( string resource, object jsonObject = null) where T : new() { Debug.Assert(string.IsNullOrWhiteSpace(resource) == false); await throttle.WaitTillReady(); T result = await restClient.AsyncDownload <T>(resource, method : method, jsonObject : jsonObject, cancellationToken : CrypnosticController.instance.cancellationTokenSource.Token); throttle.SetLastUpdateTime(); // <- kinda overkill return(result); }
protected override async Task RefreshTickers() { await throttle.WaitTillReady(); (HttpStatusCode status, string jsContent) = await wwwClient.AsyncDownload("page/statics/js/lib/commonFun.js"); if (status != HttpStatusCode.OK) { log.Error(status); // TODO retry return; } string nameListJs = jsContent.GetBetween("all_name={", "}"); string[] nameList = nameListJs.Split(','); for (int i = 0; i < nameList.Length; i++) { string tickerToName = nameList[i]; string ticker = tickerToName.GetBefore(":"); string name = tickerToName.GetBetween("\"", "\""); Coin coin = await CreateFromName(name); // Is this possible to determine? bool isInactive = false; await AddTicker(coin, ticker, isInactive); } string marketListJs = jsContent.GetBetween("alias_arr={", "}"); string[] marketTickerList = marketListJs.Split(','); for (int i = 0; i < marketTickerList.Length; i++) { string marketToName = marketTickerList[i]; string ticker = marketToName.GetBefore(":"); Coin coin = Coin.FromTicker(ticker, exchangeName); if (coin != null) { marketList.Add(ticker.ToLowerInvariant()); } } }
public override async Task LoadTickerNames() { await throttle.WaitTillReady(); string jsContent = await client.AsyncDownload("page/statics/js/lib/commonFun.js"); string nameListJs = jsContent.GetBetween("all_name={", "}"); string[] nameList = nameListJs.Split(','); for (int i = 0; i < nameList.Length; i++) { string tickerToName = nameList[i]; string ticker = tickerToName.GetBefore(":"); string name = tickerToName.GetBetween("\"", "\""); Coin coin = CreateFromName(name); // Is this possible to determine? bool isInactive = false; AddTicker(ticker, coin, isInactive); } string marketListJs = jsContent.GetBetween("alias_arr={", "}"); string[] marketTickerList = marketListJs.Split(','); for (int i = 0; i < marketTickerList.Length; i++) { string marketToName = marketTickerList[i]; string ticker = marketToName.GetBefore(":"); Coin coin = Coin.FromTicker(ticker, exchangeName); if (coin != null) { marketList.Add(ticker.ToLowerInvariant()); } } }
protected async Task <T> Get <T>( string resource, object jsonObject = null) where T : class, new() { Debug.Assert(string.IsNullOrWhiteSpace(resource) == false); await throttle.WaitTillReady(); (HttpStatusCode status, T result) = await restClient.AsyncDownload <T>(resource, method : method, jsonObject : jsonObject, cancellationToken : CrypnosticController.instance.cancellationTokenSource.Token); if (status != HttpStatusCode.OK) { log.Error(status); throttle.BackOff(); // TODO backoff if 400's return(null); } return(result); }
async Task Refresh() { (HttpStatusCode status, List <CoinMarketCapTickerJson> resultList) = await restClient.AsyncDownload <List <CoinMarketCapTickerJson> >("v1/ticker/?limit=0"); if (status != HttpStatusCode.OK) { log.Error(status); throttle.BackOff(); // TODO backoff if 400's return; } if (resultList == null) { // Parsing error, it may work on the next refresh log.Error("Refresh failed"); return; } for (int i = 0; i < resultList.Count; i++) { CoinMarketCapTickerJson ticker = resultList[i]; Debug.Assert(ticker != null); Coin coin = await CrypnosticController.instance.CreateFromName(ticker.name); if (coin == null) { // Blacklisted continue; } DateTime lastUpdated; if (long.TryParse(ticker.last_updated, out long secondsSince)) { lastUpdated = DateTimeOffset.FromUnixTimeSeconds(secondsSince).DateTime; } else { lastUpdated = default(DateTime); } string symbol = ticker.symbol.ToLowerInvariant(); if (tickerLowerToCoin.ContainsKey(symbol) == false) { tickerLowerToCoin[symbol] = coin; } coin.coinMarketCapData = new MarketCap( ticker.symbol, int.Parse(ticker.rank), ticker.price_btc.ToNullableDecimal(), ticker.price_usd.ToNullableDecimal(), ticker._24h_volume_usd.ToNullableDecimal(), ticker.market_cap_usd.ToNullableDecimal(), ticker.available_supply.ToNullableDecimal(), ticker.total_supply.ToNullableDecimal(), ticker.max_supply.ToNullableDecimal(), ticker.percent_change_1h.ToNullableDecimal(), ticker.percent_change_24h.ToNullableDecimal(), ticker.percent_change_7d.ToNullableDecimal(), lastUpdated); } }