if i send ping iam getting pong` i am not getting morket feeds , i want to know if market feed will be only available in market hrs ? if we connect after market hrs what will be message from websocket?
import 'package:web_socket/web_socket.dart';
try {
final socket = await WebSocket.connect(Uri.parse(wssUrl));
print('Connected to WebSocket: $wssUrl');
final subscriptionMessage = jsonEncode({
'guid': params.guid,
'method': params.method,
'data': {
'mode': params.data.mode,
'instrumentKeys': params.data.instrumentKeys,
},
});
socket.sendText(subscriptionMessage);
print('Sent subscription message: $subscriptionMessage');
// Listen to WebSocket events
socket.events.listen((event) {
switch (event) {
case TextDataReceived(text: final text):
try {
print('Received WebSocket message: $text');
// Decode the received message and parse it
final decodedMarketData =
MarketFullFeed.fromBuffer(utf8.encode(text));
controller.add(decodedMarketData);
} catch (e) {
print('Error decoding WebSocket message: $e');
controller.addError('Error decoding WebSocket message: $e');
}
break;
case BinaryDataReceived(data: final data):
print('Unexpected binary data received: $data');
break;
case CloseReceived(code: final code, reason: final reason):
print('WebSocket closed: Code $code, Reason: $reason');
controller.close();
break;
default:
print('Unhandled WebSocket event: $event');
}
}, onError: (error) {
print('WebSocket error: $error');
controller.addError('WebSocket error: $error');
}, onDone: () {
print('WebSocket connection closed.');
controller.close();
});
// Yield the stream
yield* controller.stream;
} catch (e) {
print('Error connecting to WebSocket: $e');
throw Exception('Error connecting to WebSocket: $e');
}