odin_market_feed_client 1.0.0
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');
}
}