I used nodejs to place a order on testnet.binancefuture.com but got error, here is my code:
indent preformatted text by 4 spaces
import fetch from "node-fetch";
import CryptoJS from 'crypto-js';
var apiKey = "d48075f8255c00***********************502a7d87fac3f160433";
var apiSecret = "227a661ba00dda9*******************c0fa65c6601f12770d9d";
var hostAPI = 'https://testnet.binancefuture.com';
place_position();
async function place_position(){
var requestOptions = {
method: 'POST',
headers: {
"Content-Type":"application/x-www-form-urlencoded",
"X-MBX-APIKEY":apiKey,
"Access-Control-Allow-Origin":"*"
},
redirect: 'follow'
};
const query_string = 'symbol=BTCUSDT'+'&side=BUY'+'&type=MARKET'+'&quantity=0.001'+'&timeInForce=GTC'+'×tamp='+Date.now().toString();
let signature = CryptoJS.HmacSHA256(query_string, apiSecret).toString();
await fetch(hostAPI + "/fapi/v1/order?"+query_string+'&signature='+signature, requestOptions);
}
And error:
reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, 'system', error));
^
FetchError: request to https://testnet.binancefuture.com/fapi/v1/order?symbol=BTCUSDT&side=BUY&type=MARKET&quantity=0.001&timeInForce=GTC×tamp=1634096908875&signature=db77c358e18e4661a800347b614fffedae7cfcae3bb78d7cb2bfce6973cdef40 failed, reason: read ECONNRESET
at ClientRequest.<anonymous>
at ClientRequest.emit (node:events:394:28)
at TLSSocket.socketErrorListener (node:_http_client:447:9)
at TLSSocket.emit (node:events:394:28)
at emitErrorNT (node:internal/streams/destroy:193:8)
at emitErrorCloseNT (node:internal/streams/destroy:158:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET',
erroredSysCall: 'read'
}
Hi,
Is this script running client side? If so, USDM futures new order does not support CORS requests.