11class TftMarketData {
22 final double lastPrice;
33 final double lastUsdPrice;
4- final double change24h;
54 final double high24h;
65 final double low24h;
7- final double volume24h;
86
97 TftMarketData ({
108 required this .lastPrice,
119 required this .lastUsdPrice,
12- required this .change24h,
1310 required this .high24h,
1411 required this .low24h,
15- required this .volume24h,
1612 });
1713
1814 factory TftMarketData .fromTrades (List <dynamic > trades) {
@@ -25,41 +21,28 @@ class TftMarketData {
2521
2622 double high24h = lastUsdcPrice;
2723 double low24h = lastUsdcPrice;
28- double volume24h = 0 ;
29-
30- final oldestTrade = trades.last;
31- final double oldestUsdcPrice = double .parse (oldestTrade['base_amount' ]) /
32- double .parse (oldestTrade['counter_amount' ]);
3324
3425 for (var trade in trades) {
3526 double usdcPrice = double .parse (trade['base_amount' ]) /
3627 double .parse (trade['counter_amount' ]);
3728 high24h = usdcPrice > high24h ? usdcPrice : high24h;
3829 low24h = usdcPrice < low24h ? usdcPrice : low24h;
39- volume24h += double .parse (trade['counter_amount' ]);
4030 }
4131
42- final double change24h =
43- ((lastUsdcPrice - oldestUsdcPrice) / oldestUsdcPrice) * 100 ;
44-
4532 return TftMarketData (
4633 lastPrice: 1 / lastPrice,
4734 lastUsdPrice: lastUsdcPrice,
48- change24h: change24h,
4935 high24h: high24h,
5036 low24h: low24h,
51- volume24h: volume24h / 1000 ,
5237 );
5338 }
5439
5540 factory TftMarketData .empty () {
5641 return TftMarketData (
5742 lastPrice: 0 ,
5843 lastUsdPrice: 0 ,
59- change24h: 0 ,
6044 high24h: 0 ,
6145 low24h: 0 ,
62- volume24h: 0 ,
6346 );
6447 }
6548}
0 commit comments