What’s wrong in this code:
ws.on("open", () => {
console.log(`Connection Opened`);
const newOrderRespType = "ACK";
const price = 23416.1;
const quantity = 0.000847;
const recvWindow = 1000;
const side = "SELL";
const symbol = "BTCUSDT";
const timeInForce = "GTC";
const type = "LIMIT";
const query_string = `apiKey=${API_KEY}&newOrderRespType=${newOrderRespType}&price=${price}&quantity=${quantity}&recvWindow=${recvWindow}&side=${side}&symbol=${symbol}&timeInForce=${timeInForce}×tamp=${Date.now()}&type=${type}`;
const signature = crypto.createHmac("sha256", API_SECRET).update(query_string).digest("hex");
ws.send(
JSON.stringify({
id: "56374a46-3061-486b-a311-99ee972eb648",
method: "order.place",
params: {
symbol,
side,
type,
timeInForce,
quantity,
price,
newOrderRespType,
recvWindow,
timestamp: Date.now(),
apiKey: API_KEY,
signature: signature,
},
})
);
});
I get the error below:
{
id: '56374a46-3061-486b-a311-99ee972eb648',
status: 400,
error: { code: -1022, msg: 'Signature for this request is not valid.' },
rateLimits: ....
}