Created
July 17, 2025 06:37
-
-
Save Lxxyx/637ed2d9063196033c12976d97c96476 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:http/http.dart' as http; | |
| import 'dart:convert'; | |
| void main() => runApp(const MyApp()); | |
| class MyApp extends StatelessWidget { | |
| const MyApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Hyperliquid Funding Rate', | |
| debugShowCheckedModeBanner: false, | |
| theme: ThemeData( | |
| colorSchemeSeed: Colors.blue, | |
| ), | |
| home: const MyHomePage(title: 'Hyperliquid Funding Rate'), | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| final String title; | |
| const MyHomePage({ | |
| super.key, | |
| required this.title, | |
| }); | |
| @override | |
| State<MyHomePage> createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| List<Token> _tokens = []; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| _fetchData(); | |
| } | |
| Future<void> _fetchData() async { | |
| final response = await http.get(Uri.parse('https://api.hyperliquid.com/v1/tokens?funding_rate_DESC=true&limit=10')); | |
| if (response.statusCode == 200) { | |
| final jsonData = jsonDecode(response.body); | |
| setState(() { | |
| _tokens = jsonData['data'].map((token) => Token.fromJson(token)).toList(); | |
| }); | |
| } else { | |
| throw Exception('Failed to load tokens'); | |
| } | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text(widget.title), | |
| ), | |
| body: _tokens.isEmpty | |
| ? Center(child: CircularProgressIndicator()) | |
| : ListView.builder( | |
| itemCount: _tokens.length, | |
| itemBuilder: (context, index) { | |
| return Card( | |
| child: ListTile( | |
| title: Text(_tokens[index].symbol), | |
| subtitle: Text('Funding Rate: ${_tokens[index].fundingRate}%'), | |
| ), | |
| ); | |
| }, | |
| ), | |
| ); | |
| } | |
| } | |
| class Token { | |
| String symbol; | |
| double fundingRate; | |
| Token({required this.symbol, required this.fundingRate}); | |
| factory Token.fromJson(Map<String, dynamic> json) { | |
| return Token( | |
| symbol: json['symbol'], | |
| fundingRate: json['funding_rate'], | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment