Multi Websocket
Using Multi Websocket will provide multiple instruments available actions and possible values at once.
from typing import Any
from thefirstock.firstockModules import firstockWebSockets
from thefirstock.pyClient.websocket import WsClient
from thefirstock.pyClient.websocket.enums import MessageTopic
# Pass 1 or 2 for Activating Websocket 1 or Websocket 2 in webSocketLogin()
client = firstockWebSockets.webSocketLogin()
ws = client.ws
@ws.on_connect
def connected(client, message):
if message.get('s') == 'OK':
client.subscribe_feed('NSE|26000#NSE|26009#NSE|22')
@ws.on_message(MessageTopic.SUBSCRIBE_FEED)
def msg_handler(client: WsClient, message: Any):
print(message)
ws.connect(uid="<userId>", actid="<userId>")
ws.run_forever()
const Firstock = require("thefirstock");
const firstock = new Firstock();
// Pass 1 or 2 for Activating Websocket 1 or Websocket 2 in initializeWebSocket()
const ws = firstock.initializeWebSocket();
ws.on("open", function open() {
firstock.getWebSocketDetails((err, result) => {
if (!err) {
firstock.initialSendWebSocketDetails(ws, result, () => {
ws.send(firstock.subscribeFeed("NSE|26000#NSE|26009"));
});
}
});
});
ws.on("error", function error(error) {
console.log(`WebSocket error: ${error}`);
});
ws.on("message", function message(data) {
const result = firstock.receiveWebSocketDetails(data);
console.log("message: ", result);
});
using thefirstock;
using System.Net.WebSockets;
class Program
{
public static void Main()
{
Firstock firstock = new Firstock();
using (ClientWebSocket webSocket = new ClientWebSocket())
{
// Pass 1 or 2 for Activating Websocket 1 or Websocket 2 in initializeWebSocket()
firstock.initializeWebsocket(webSocket,1);
while (webSocket.State == WebSocketState.Open)
{
string socketResult = firstock.startWebsocketDetails(webSocket, () =>
{
firstock.sendWebsocketData(firstock.subscribeFeedAcknowledgement("NSE|26000#NSE|26009"), webSocket);
});
Console.WriteLine("Data" + socketResult);
}
webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None).Wait();
}
Console.WriteLine("WebSocket closed.");
}
}