1

I'm using bybit api to create an order on the spot market in nodejs. i tried the below code:

var params = {
    api_key: api['key'],
    qty: 30,
    symbol: "EOSUSDT",
    timeInForce: this.bybit_enums["spot"]["time_in_force"]["GTC"],
    timestamp: expires,
    orderType: this.bybit_enums["spot"]["order_type"]["MARKET"],
};

var sign = getSignature(params, api['secret']);
params['sign'] = sign
const result = await axios({method: "post", url: "https://api-testnet.bybit.com/spot/v1/order", data: params});

but it doesn't work and responses me with: "Missing required parameter 'symbol'" which i have in the params. thanks.

based on this: https://bybit-exchange.github.io/docs/testnet/spot/#t-spotordercreate

2 Answers2

1

You'll have to use "Content-Type": "application/x-www-form-urlencoded" for this API.

const postParams = new URLSearchParams();
for (const [key, value] of Object.entries(params)) {
  postParams.append(key, value.toString());
}
postParams.append("sign", sign);

const result = await axios.post(
  'https://api-testnet.bybit.com/spot/v1/order',
  postParams,
  {
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  }
);
Yau Don
  • 40
  • 7
0

The first answer is right, the header is required, but when signing, the order of the parameters in the query string matters as well. For the full explanation refer to this post Sign error for bybit using c# when sending post request, specifically these 2 answers https://stackoverflow.com/a/70186674/10253105, https://stackoverflow.com/a/72035877/10253105

Though the question is for C#, the answers are for JS

David
  • 11
  • 1