I am trying to open a websocket connection to check status of my orders and eventually make some action if status has changed. I am having 404 error message and a 1006 code as if my url is incorrect which i don’t believe is not the case. Please see my snippet below
const wsTestURL2 = 'wss://testnet.binance.vision/ws-api/v3'
export async function getOrderStatusFromBinance(symbol: string, orderId: number): Promise<Order> {
console.log("order id",orderId)
return new Promise(async (resolve, reject) => {
const listenKey = await getUserDataStream();
const wsUserData = new WebSocket(`${wsTestURL2}/${listenKey}`);
if (!testApiSecret) {
throw new Error('No test API secret provided');
}
const requestId = uuidv4();
wsUserData.on('open', () => {
const timeStamp = Date.now();
const queryString = `symbol=${symbol}&orderId=${orderId}×tamp=${timeStamp}`;
const signature = crypto.createHmac("sha256", testApiSecret).update(queryString).digest("hex");
const params = {
symbol: symbol,
orderId: orderId,
apiKey: testApiKey,
signature: signature,
timestamp: timeStamp,
}
const message = {
id: requestId,
method: 'order.status',
params: params,
}
wsUserData.send(JSON.stringify(message));
});
wsUserData.on('message', (message: string) => {
const data = JSON.parse(message) as { id: string; result: Order };
console.log('order status', data);
if (data.id === requestId) {
resolve(data.result);
}
});
wsUserData.on('error', (error) => {
reject(error);
});
});
}
``` what do i do wrong here? I made a change to the url as follow , ‘wss://testnet.binance.vision/ws’, i now get error message order status {
[1] error: {
[1] code: 2,
[1] msg: ‘Invalid request: unknown variant order.status, expected one of SUBSCRIBE, UNSUBSCRIBE, LIST_SUBSCRIPTIONS, SET_PROPERTY, GET_PROPERTY at line 1 column 68’
[1] }
[1] } however the documentation do not require this params in the request .I am using this documention as reference [Documention link](https://developers.binance.com/docs/binance-trading-api/websocket_api#query-order-user_data)
@ilammy@dino Hi both, thanks for assisting me finding the issue. I was wrongly formatting my url addind the listen key behing it, This only required to open the userdataStream. I assumed it was mandatory going forward.
it was this
const wsUserData = new WebSocket(`${wsTestURL}/${listenKey}`);
corrected to
const wsUserData = new WebSocket(`${wsTestURL}`);
Also @ilammy you were correct about the importance of signing the api key value and sorting the value by name.