I want to write a custom script using Google Apps Script for Spreadsheet that gets data from WebSocket. Is there a way doing so?
No, Google Apps Script does not include any Web APIs other than what UrlFetchApp offers. In particular, it cannot maintain a websocket connection.