dart_tdx 1.0.1 copy "dart_tdx: ^1.0.1" to clipboard
dart_tdx: ^1.0.1 copied to clipboard

TDX (通达信) stock market data interface for Dart. Real-time quotes, historical K-line data, financial data, and offline file reading - a Dart port of mootdx.

example/main.dart

import 'dart:math';
import 'package:dart_tdx/dart_tdx.dart';

void main() async {
  print('=== dart_tdx Example ===\n');

  // Example 1: Connect and get stock count
  print('1. Connecting to TDX server...');
  try {
    final quotes = await Quotes.factory(
      market: 'std',
      timeout: const Duration(seconds: 10),
    );

    if (quotes is StdQuotes) {
      print('   Connected successfully!');

      // Get stock count for Shanghai market
      final count = await quotes.stockCount(Market.sh);
      print('   Shanghai market stock count: $count');

      // Get K-line data for 平安银行
      print('\n2. Fetching K-line data for 000001 (平安银行)...');
      final bars = await quotes.bars('000001',
          frequency: KLineType.day, start: 0, offset: 5);

      for (final bar in bars) {
        print('   ${bar.datetime} O:${bar.open} C:${bar.close} '
            'H:${bar.high} L:${bar.low} V:${bar.vol}');
      }

      // Get real-time quotes
      print('\n3. Fetching real-time quotes...');
      final quotesList = await quotes.quotes(['000001', '600036']);
      for (final q in quotesList) {
        print('   ${q.code} Price:${q.price} Open:${q.open} '
            'High:${q.high} Low:${q.low} Vol:${q.vol}');
      }

      // Get security list
      print('\n4. Fetching security list (first 10)...');
      final stocks = await quotes.securityList(Market.sz, 0);
      for (int i = 0; i < min(10, stocks.length); i++) {
        print('   ${stocks[i].code} ${stocks[i].name}');
      }

      quotes.close();
    }
  } catch (e) {
    print('   Error: $e');
    print('   (This is expected if no TDX server is reachable)');
  }

  print('\n=== Done ===');
}
0
likes
135
points
131
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

TDX (通达信) stock market data interface for Dart. Real-time quotes, historical K-line data, financial data, and offline file reading - a Dart port of mootdx.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

archive

More

Packages that depend on dart_tdx