hyperliquid_dart 0.16.3 copy "hyperliquid_dart: ^0.16.3" to clipboard
hyperliquid_dart: ^0.16.3 copied to clipboard

A Dart SDK for the Hyperliquid DEX — REST API, WebSocket subscriptions, EIP-712 signing, and order management.

example/hyperliquid_dart_example.dart

import 'package:hyperliquid_dart/hyperliquid_dart.dart';

void main() async {
  // --- Read-only queries (no wallet needed) ---

  final info = InfoClient();

  // Fetch all mid prices.
  final mids = await info.allMids();
  print('BTC mid: ${mids['BTC']}');
  print('ETH mid: ${mids['ETH']}');

  // Fetch candles for BTC.
  final now = DateTime.now().millisecondsSinceEpoch;
  final oneDayAgo = now - (24 * 60 * 60 * 1000);
  final candles = await info.candleSnapshot(
    coin: 'BTC',
    interval: '1h',
    startTime: oneDayAgo,
    endTime: now,
  );
  print('Fetched ${candles.length} candles');

  // Fetch L2 orderbook.
  final book = await info.l2Book(coin: 'BTC');
  print('BTC bids: ${book.bids.length}, asks: ${book.asks.length}');

  // Fetch asset metadata.
  final meta = await info.metaAndAssetCtxs();
  print('Universe size: ${meta.universe.length}');
  print('First asset: ${meta.universe.first.name}');

  info.close();

  // --- WebSocket real-time data ---

  final ws = WebSocketClient();
  await ws.connect();

  // Subscribe to BTC orderbook updates.
  final bookHandle = ws.subscribeL2Book('BTC', (book) {
    print('L2 update — bids: ${book.bids.length}, asks: ${book.asks.length}');
  });

  // Subscribe to all mid prices.
  final midsHandle = ws.subscribeAllMids((mids) {
    print('Mid update — BTC: ${mids['BTC']}');
  });

  // Keep running for 10 seconds then clean up.
  await Future<void>.delayed(const Duration(seconds: 10));

  await bookHandle.cancel();
  await midsHandle.cancel();
  await ws.dispose();

  print('Done!');
}
1
likes
160
points
276
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart SDK for the Hyperliquid DEX — REST API, WebSocket subscriptions, EIP-712 signing, and order management.

Repository (GitHub)
View/report issues

Topics

#hyperliquid #defi #trading #web3 #cryptocurrency

Documentation

API reference

License

MIT (license)

Dependencies

convert, http, msgpack_dart, pointycastle, web_socket_channel

More

Packages that depend on hyperliquid_dart