したがって、このAPIを使用しています。これは、現在の価格とethereumコインに関するその他のものを示しています。私は最後にスキャンしたときから値が変わったかどうかを調べる小さなコンソールアプリケーションを作成しようとしています。古いデータ型の値を新しいものと比較するには
私は今までこれを持っています...そして、私は現在の値で現在の値をスキャンしているので、決して変化しないことは明らかです。 私は古い値を保持する変数を設定しようとしましたが、何もしませんでした。
最初のスキャンと2番目のスキャンを比較して、浮動小数点値が上下しているかどうかを確認するにはどうすればよいですか?
private static void Ticker()
{
while (true)
{
const string uri = @"https://api.coinmarketcap.com/v1/ticker/ethereum/";
var client = new WebClient();
var content = client.DownloadString(uri);
var results = JsonConvert.DeserializeObject<List<CoinApi>>(content);
float currentAmount = results[0].price_usd;
if (currentAmount < currentAmount)
{
Console.WriteLine("Ammount is lower than the last time.");
}
else if (currentAmount > currentAmount)
{
Console.WriteLine("The amount is higher than the last time.");
}
else if (currentAmount == currentAmount)
{
Console.WriteLine("The amount hasnt changed since the last time we scanned.");
}
}
}
これはクラスファイルです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CryptoTicker.Core
{
class Main
{
}
public class CoinApi
{
public string Id { get; set; }
public string Name { get; set; }
public string Symbol { get; set; }
public float price_usd { get; set; }
}
}
私のアプローチでは、いくつかのコインインスタンスを扱うことができます。もしあなたがただ一つの価格を管理する必要があれば、他のユーザーはもっと望ましいかもしれないもっと簡単なアプローチを投稿しました – Ben