odin_market_feed_client 1.0.0 copy "odin_market_feed_client: ^1.0.0" to clipboard
odin_market_feed_client: ^1.0.0 copied to clipboard

A Dart Library for ODIN Market Feed WebSocket client with support for real-time market data streaming, touchline data, and best five quotes.

example/example.dart

import 'package:odin_market_feed/odin_market_feed_sdk.dart';

void main() async {
  final client = ODINMarketFeedClient();

  // Set up event handlers
  client.onOpen = () async {
    print('āœ… WebSocket opened');

    // Define tokens - exactly like Go code
    final tokens = [
      '1_22', // Replace with actual token
      '1_2885', // Replace with actual token
    ];
    // Subscribe Touchline with responseType "0" and ltpChangeOnly false
    // await client.subscribeTouchline(tokens,
    //     responseType: "0", ltpChangeOnly: false);

    // Subscribe Touchline with responseType "0" and ltpChangeOnly true
    // await client.subscribeTouchline(tokens,
    //     responseType: "0", ltpChangeOnly: true);

    // Subscribe Touchline with responseType "1" and ltpChangeOnly false
    // await client.subscribeTouchline(tokens,
    //     responseType: "1", ltpChangeOnly: false);

    // Subscribe Touchline with responseType "1" and ltpChangeOnly true
    // await client.subscribeTouchline(tokens,
    //     responseType: "1", ltpChangeOnly: true);

    // Subscribe to Best Five (Market Depth)
    //await client.subscribeBestFive("2885", 1); // token, marketSegmentID

    // Subscribe to LTP Touchline
    await client.subscribeLTPTouchline(tokens);

    // Wait 15 seconds
    await Future.delayed(Duration(seconds: 15));

    // Pause subscription
    await client.subscribePauseResume(true);

    // Wait 5 seconds
    await Future.delayed(Duration(seconds: 5));

    // Resume subscription
    await client.subscribePauseResume(false);

    // Keep running to receive data...
    await Future.delayed(Duration(seconds: 30));

    // Unsubscribe
    //await client.unsubscribeLTPTouchline(['1_26000']);

    // Using streams to listen for errors
    // client.errorStream.listen((error) {
    //   print('Error occurred: $error');
    // });
  };

  client.onMessage = (message) {
    print('šŸ“Ø Received: $message');
  };

  client.onError = (error) {
    print('āŒ Error: $error');
  };

  client.onClose = (code, reason) {
    print('šŸ”Œ Closed: $code - $reason');
  };

  try {
    print('šŸš€ Connecting to server...\n');

    // CHANGE THESE VALUES TO YOUR SERVER
    await client.connect(
      'YOUR-SERVER-IP', // ← Your server host
      4509, // ← Your server port
      false, // ← Use SSL/TLS
      'PRAJYOT', // ← Your user ID
      '',
    );

    // Send custom message
    //await client.sendMessage('your|custom|message');

    // Keep connection alive
    print('\nšŸ’¤ Keeping connection alive for 180 seconds...\n');
    await Future.delayed(Duration(seconds: 180));
    //String? name = stdin.readLineSync();
  } catch (e) {
    print('šŸ’„ Error: $e');
  } finally {
    print('\nšŸ”Œ Disconnecting...');
    await client.disconnect();
    client.dispose();
    print('šŸ‘‹ Application closed');
  }
}
0
likes
150
points
7
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Dart Library for ODIN Market Feed WebSocket client with support for real-time market data streaming, touchline data, and best five quotes.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on odin_market_feed_client