I'm experiencing issues with both the FYERS WebSocket and Webhook functionalities. Neither is providing real-time order updates as expected.
Detailed Description: I've set up both WebSocket and Webhook integrations in my application according to the official FYERS API documentation. However, I'm not receiving real-time order status updates through either method.
* WebSocket: I've implemented the FyersOrderSocket
using the fyers-api-v3
Node.js library. I'm successfully connecting to the WebSocket (I see the "Order Socket Connected" log message).
I'm subscribing to orderUpdates,tradeUpdates,positionUpdates,edis,pricealerts
.
However, the orders
callback function is not being triggered when order statuses change.
* Here is my code snippet for websocket:
// services/orderService.js
const FyersOrderSocket = require("fyers-api-v3").fyersOrderSocket;
const Order = require("../models/order");
const logger = require('../utils/logger');
let fyersOrderdata = null;
module.exports = {
initializeOrderSocket: (accessToken) => {
if (!fyersOrderdata) {
fyersOrderdata = new FyersOrderSocket(accessToken);
fyersOrderdata.on("error", (errmsg) => {
logger.error(`Order Socket Error: ${errmsg}`);
});
fyersOrderdata.on('connect', () => {
fyersOrderdata.subscribe([fyersOrderdata.orderUpdates, fyersOrderdata.tradeUpdates, fyersOrderdata.positionUpdates, fyersOrderdata.edis, fyersOrderdata.pricealerts])
logger.info('Order Socket Connected');
});
fyersOrderdata.on('close', () => {
logger.info('Order Socket Closed');
});
fyersOrderdata.on('orders', async (msg) => {
logger.info("Order Update Received:", msg);
try {
await module.exports.processOrderUpdate(msg);
} catch (error) {
logger.error("Error processing order update:", error);
}
});
fyersOrderdata.autoreconnect(50);
fyersOrderdata.connect();
} else {
logger.info("Order Socket already initialized");
}
},
processOrderUpdate: async (msg) => {
const orderId = msg.id;
const status = msg.s;
try {
logger.info(`Order ${orderId} status updated to ${status}`);
// Code for process order
} catch (error) {
logger.error(`Error updating order ${orderId}:`, error);
}
},
};
// controllers/orderController.js
const orderService = require('../services/orderService');
const config = require('../config/config');
module.exports = {
startOrderMonitoring: () => {
orderService.initializeOrderSocket(config.fyers.accessToken);
}
};
// app.js or server.js
const orderController = require('./controllers/orderController');
orderController.startOrderMonitoring();
const express = require("express");
const router = express.Router();
router.post('/webhook', async (req, res) => {
try {
console.log("Fyres webhook called with data:", req.body);
return res.status(200).json({
sucess: true,
date: {},
message: "Test webhook",
error: {}
})
} catch (err) {
return res.status(500).json({
sucess: false,
date: {},
message: "Error in test webhook",
error: err
})
}
});
Webhook: I've configured a webhook URL in my FYERS account settings. My webhook endpoint is accessible and can receive HTTP POST requests. I'm not receiving any POST requests to my webhook endpoint when order statuses change. Here is my configuration details for webhook: Webhook URL : (paste your webhook url here)
Steps to Reproduce:
1. Place a GTT order (or any order that changes status).
2. Observe that neither the WebSocket orders
callback nor the webhook endpoint receives an update.
Expected Behavior: The WebSocket orders
callback should be triggered with the updated order status.
The webhook endpoint should receive a POST request with the updated order details.
Actual Behavior: No updates are received through the WebSocket or webhook. *Environment:**
- Operating System: [Windows]
- Node.js Version: [v20.15.0]
fyers-api-v3 Version: [[email protected]]
*Logs (if applicable):**
- When I started my server then I received log for socket that has connected Order Socket Connected
*Additional Information:**
I've verified that my FYERS API credentials are correct.
I have verified that my network connection is stable. I have verified that my server is running.
Questions: Are there any known issues with the FYERS WebSocket or webhook services?
Are there any specific configurations or settings that I might be missing?
Is there a way to increase logging detail on the fyres side, to help debug this issue?
Thank you for your assistance.