trade test new order problem

hi (i work in linux mint 64 ) i have a problem with Tarde Test New Order + curl i have created a script for create time stamp , after this run a part of code for create a signature , after this run TradeTestNew Order with TimeStamp and Signature just created , but some time tell me {“code”:-1021,“msg”:“Timestamp for this request is outside of the recvWindow.”}, and often tell me {“code”:-1022,“msg”:“Signature for this request is not valid.”}
i try to run in shell by hand but also in this mode not work , example of my code

curl -H “X-MBX-APIKEY: MYAPIKEY HERE” -X ‘POST’ 'https://api.binance.com/api/v3/order/test?symbol=BNBUSDT&side=BUY&type=LIMIT&timestamp=1636982606730&signature=MY SIGNATURE HERE

this code for create signature
echo -n “symbol=BNBUSDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&timestamp=1636982705000” | openssl dgst -sha256 -hmac “MYSECRET KEY HERE”

and with this function return my time stamp

RING_FUNC(ring_mytimestamp)
{
char TimeStamp[15]={0};
struct timespec nstime;

if( clock_gettime( CLOCK_REALTIME, &nstime) == -1 ) {
perror(“orologio gettime”);
exit( EXIT_FAILURE );
}
int Test = ((nstime.tv_sec * 1000000000 + nstime.tv_nsec)/1000000);
RING_API_RETNUMBER((nstime.tv_sec * 1000000000 + nstime.tv_nsec)/1000000);

}

anyone can help me ?? thanks at all

{“code”:-1021,“msg”:“Timestamp for this request is outside of the recvWindow.”}

The error above is returned when the request attempts to be processed outside of the recvWindow provided.

By default, a parameter with the name recvWindow is set to 5000ms, meaning that the request must be processed within 5000ms of the timestamp sent or the server must refuse the request.

Therefore, if you are constructing the timestamp and signature by hand, the request must be sent within 5000ms of the timestamp set.

Since this is not the case, there are two solutions:

  • Reduce the duration of generating the timestamp & signature and send the request sooner by building a script to do so.

  • Increase the recvWindow value to be greater than 5000ms. (Maximum allowed is 60000ms)

While both options are allowed, the latter is not suggested when handling time sensitive operations such as trades.

More info regarding signed endpoints can be found here
https://binance-docs.github.io/apidocs/spot/en/#signed-trade-user_data-and-margin-endpoint-security

why in postman not exist recvWindow but exist in swagger Swagger UI ?

Postman

1 Like

Thanks for pointing this out, will inform the respective team.

hi @tantialex i try to insert all in simple bash script but return me always 404 not found
o_O i think my code is correct

my code
#!/bin/bash

APIKEY=“MY APIKEY”

APISECRET=“MY SECRET KEY”

URLPART2=“symbol=BNBUSDT&side=BUY&type=LIMIT”

RECVWINDOW=50000

RECVWINDOW=“recvWindow=$RECVWINDOW”

TIMESTAMP=“timestamp=$(( $(date +%s) *1000))”

QUERYSTRING="&$URLPART2&$RECVWINDOW&$TIMESTAMP"

SIGNATURE=$(echo -n “$QUERYSTRING” | openssl dgst -sha256 -hmac $APISECRET | cut -c 10-)

SIGNATURE=“signature=$SIGNATURE”

curl -s -H “X-MBX-APIKEY: $APIKEY” “https://api.binance.com/api/v3/order/test?$URLPART2&$RECVWINDOW&$TIMESTAMP&$SIGNATURE

echo

The above snippet is sending a curl request with Http Method GET.

The /api/v3/order/test endpoint only accepts POST.

Add curl -X POST to send the a curl request with Http Method POST.

In addition, remove the initial & from the start of the query string

QUERYSTRING="&$URLPART2&$RECVWINDOW&$TIMESTAMP"

to

QUERYSTRING="$URLPART2&$RECVWINDOW&$TIMESTAMP"

i have modify the code like this

#!/bin/bash
APIKEY="MY API KEY HERE"
APISECRET="MY SECRET KEY"
#sURLPART2="symbol=BNBUSDT&side=BUY&type=LIMIT&quoteOrderQty=10&price=270.3&newOrderRespType=FULL"
URLPART2="symbol=BNBUSDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity=10&price=270&newOrderRespType=FULL"
RECVWINDOW=50000
RECVWINDOW="recvWindow=$RECVWINDOW"
TIMESTAMP="timestamp=$(( $(date +%s) *1000))"
QUERYSTRING="$URLPART2&$RECVWINDOW&$TIMESTAMP"

SIGNATURE=$(echo -n "$QUERYSTRING" | openssl dgst -sha256 -hmac $APISECRET | cut -c 10-)
SIGNATURE="signature=$SIGNATURE"

curl  -H "X-MBX-APIKEY: $APIKEY" -X POST "https://api.binance.com/api/v3/order/test?$URLPART2&$RECVWINDOW&$TIMESTAMP&$SIGNATURE"
echo

but now return me this
{}
is correct??? i suppose no o_O thanks again

That is the correct response content from /api/v3/order/test.

The endpoint does not place an order, therefore it just returns a 200 OK response.

sorry if i disturb again , i try to run API CancelOrder , i created this code in bash , obviusly i set a fake orderid , but not return , not exist oreder id or somthing else , but return me
{“code”:-1102,“msg”:“Mandatory parameter ‘side’ was not sent, was empty/null, or malformed.”}
but in help API Postman
or Swagger UI
not exist a prameter of side , i must use side? or have a compleate sintax? thanks

#!/bin/bash
APIKEY="MY API KEY"
APISECRET="MY SECRET KEY"
#sURLPART2="symbol=BNBUSDT&side=BUY&type=LIMIT&quoteOrderQty=10&price=270.3&newOrderRespType=FULL"
URLPART2="symbol=BNBUSDT&orderId=12314"
RECVWINDOW=50000
RECVWINDOW="recvWindow=$RECVWINDOW"
TIMESTAMP="timestamp=$(( $(date +%s) *1000))"
QUERYSTRING="$URLPART2&$RECVWINDOW&$TIMESTAMP"

SIGNATURE=$(echo -n "$QUERYSTRING" | openssl dgst -sha256 -hmac $APISECRET | cut -c 10-)
SIGNATURE="signature=$SIGNATURE"

curl  -H "X-MBX-APIKEY: $APIKEY" -X POST "https://api.binance.com/api/v3/order?$URLPART2&$RECVWINDOW&$TIMESTAMP&$SIGNATURE"
echo

The above snippet is sending a curl request with Http Method POST.

The Cancel Order endpoint expects the HTTP Method DELETE.

Add curl -X DELETE to send the a curl request with Http Method DELETE.