Issue with Axios Request Creating Multiple Orders in Binance API Integration

Hello Support,
I apologize for the lengthy description, but I wanted to bring attention to a problem that has persisted for the past month in my Binance API integration.
I am currently working on integrating the Binance API into my Node.js application to place stop-market orders when certain conditions are met. However, I am facing an issue where a single Axios POST request seems to be creating two orders instead of one.

This is order_trade_update of first order:

Order Update: {
  e: 'ORDER_TRADE_UPDATE',
  T: 1690792609714,
  E: 1690792609719,
  o: {
    s: 'BTCUSDT',
    c: 'SM9T7ELk4UyqPCuN9pY1vU',
    S: 'SELL',
    o: 'TRAILING_STOP_MARKET',
    f: 'GTC',
    q: '0.001',
    p: '0',
    ap: '0',
    sp: '29353.51',
    x: 'NEW',
    X: 'NEW',
    i: 176319221495,
    l: '0',
    z: '0',
    L: '0',
    n: '0',
    N: 'USDT',
    T: 1690792609714,
    t: 0,
    b: '0',
    a: '0',
    m: false,
    R: false,
    wt: 'CONTRACT_PRICE',
    ot: 'TRAILING_STOP_MARKET',
    ps: 'SHORT',
    cp: false,
    AP: '29383.90',
    cr: '0.1',
    rp: '0',
    pP: false,
    si: 0,
    ss: 0
  }
}

When first order on Binance Future FILLED, my application received 2 message: 1 for EXPIRED and 1 for NEW ?? I don’t understand, I guess it’s because I use TRAILING_STOP_MARKET type.

EXPIRED:

Order Update: {
  e: 'ORDER_TRADE_UPDATE',
  T: 1690794854484,
  E: 1690794854506,
  o: {
    s: 'BTCUSDT',
    c: 'SM9T7ELk4UyqPCuN9pY1vU',
    S: 'SELL',
    o: 'TRAILING_STOP_MARKET',
    f: 'GTC',
    q: '0.001',
    p: '0',
    ap: '0',
    sp: '29358.11',
    x: 'EXPIRED',
    X: 'EXPIRED',
    i: 176319221495,
    l: '0',
    z: '0',
    L: '0',
    n: '0',
    N: 'USDT',
    T: 1690794854484,
    t: 0,
    b: '0',
    a: '0',
    m: false,
    R: false,
    wt: 'CONTRACT_PRICE',
    ot: 'TRAILING_STOP_MARKET',
    ps: 'SHORT',
    cp: false,
    AP: '29383.90',
    cr: '0.1',
    rp: '0',
    pP: false,
    si: 0,
    ss: 0
  }
}

NEW:

Order Update: {
  e: 'ORDER_TRADE_UPDATE',
  T: 1690794854484,
  E: 1690794854506,
  o: {
    s: 'BTCUSDT',
    c: 'SM9T7ELk4UyqPCuN9pY1vU',
    S: 'SELL',
    o: 'MARKET',
    f: 'GTC',
    q: '0.001',
    p: '0',
    ap: '0',
    sp: '29358.11',
    x: 'NEW',
    X: 'NEW',
    i: 176319221495,
    l: '0',
    z: '0',
    L: '0',
    n: '0',
    N: 'USDT',
    T: 1690794854484,
    t: 0,
    b: '0',
    a: '0',
    m: false,
    R: false,
    wt: 'CONTRACT_PRICE',
    ot: 'TRAILING_STOP_MARKET',
    ps: 'SHORT',
    cp: false,
    AP: '29383.90',
    cr: '0.1',
    rp: '0',
    pP: false,
    si: 0,
    ss: 0
  }
}

And FILLED mesage:

Order Update: {
  e: 'ORDER_TRADE_UPDATE',
  T: 1690794854484,
  E: 1690794854507,
  o: {
    s: 'BTCUSDT',
    c: 'SM9T7ELk4UyqPCuN9pY1vU',
    S: 'SELL',
    o: 'MARKET',
    f: 'GTC',
    q: '0.001',
    p: '0',
    ap: '29352.90000',
    sp: '29358.11',
    x: 'TRADE',
    X: 'FILLED',
    i: 176319221495,
    l: '0.001',
    z: '0.001',
    L: '29352.90',
    n: '0.01174116',
    N: 'USDT',
    T: 1690794854484,
    t: 3976787107,
    b: '0',
    a: '0',
    m: false,
    R: false,
    wt: 'CONTRACT_PRICE',
    ot: 'TRAILING_STOP_MARKET',
    ps: 'SHORT',
    cp: false,
    AP: '29383.90',
    cr: '0.1',
    rp: '0',
    pP: false,
    si: 0,
    ss: 0
  }
}

If have FILLED message, i will push an order:

Here’s code about push order:

// Code snippet for the Axios POST request
const endpoint = 'https://fapi.binance.com/fapi/v1/order';
const payload = {
  symbol,
  side,
  positionSide',
  type,
  quantity,
  stopPrice,
  timestamp,
  signature: '...'
};

const response = await axios.post(endpoint, null, { params: payload, headers });
console.log('Response:', response.data);

Axios response

{
  status: 200,
  statusText: 'OK',
  headers: AxiosHeaders {
    date: 'Mon, 31 Jul 2023 09:14:14 GMT',
    'content-type': 'application/json',
    'transfer-encoding': 'chunked',
    connection: 'close',
    server: 'Tengine',
    vary: 'Accept-Encoding',
    'x-mbx-used-weight-1m': '-1',
    'x-mbx-order-count-10s': '1',
    'x-mbx-order-count-1m': '1',
    'x-response-time': '5ms',
    'access-control-allow-origin': '*',
    'access-control-allow-methods': 'GET, POST, PUT, DELETE, OPTIONS',
    'access-control-allow-credentials': 'true',
    'access-control-allow-headers': '*,clienttype,Content-Type,lang,x-ui-request-trace,bnc-uuid',
    'content-security-policy': "default-src 'self'",
    'cache-control': 'no-cache, no-store, must-revalidate',
    expires: '0',
    pragma: 'no-cache',
    'strict-transport-security': 'max-age=31536000; includeSubdomains',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'SAMEORIGIN',
    'x-xss-protection': '1; mode=block'
  },
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [ 'xhr', 'http' ],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    env: { FormData: [Function], Blob: [class Blob] },
    validateStatus: [Function: validateStatus],
    headers: AxiosHeaders {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/x-www-form-urlencoded',
      'X-MBX-APIKEY': 'LriUxkI9BTC9QFAPvUPSWWELbsviW5WycRftPOT9GEsr4exnDxt9xa4kR3h0W6Gh',
      'User-Agent': 'axios/1.4.0',
      'Accept-Encoding': 'gzip, compress, deflate, br'
    },
    params: {
      symbol: 'BTCUSDT',
      side: 'BUY',
      positionSide: 'SHORT',
      type: 'STOP_MARKET',
      quantity: '0.001',
      stopPrice: '29394',
      timestamp: 1690794854618,
      signature: '...'
    },
    method: 'post',
    url: 'https://fapi.binance.com/fapi/v1/order',
    data: null
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      finish: [Function: requestOnFinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: true,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    strictContentLength: false,
    _contentLength: 0,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: true,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'fapi.binance.com',
      alpnProtocol: false,
      authorized: false,
      authorizationError: 'SELF_SIGNED_CERT_IN_CHAIN',
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 9,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'fapi.binance.com',
      _closeAfterHandlingError: false,
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: null,
      _requestCert: true,
      _rejectUnauthorized: false,
      parser: null,
      _httpMessage: [Circular *1],
      write: [Function: writeAfterFIN],
      [Symbol(res)]: null,
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 518,
      [Symbol(kHandle)]: null,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: true,
      [Symbol(kSetKeepAliveInitialDelay)]: 60,
      [Symbol(kBytesRead)]: 1118,
      [Symbol(kBytesWritten)]: 527,
      [Symbol(connect-options)]: [Object]
    },
    _header: 'POST /fapi/v1/order?symbol=BTCUSDT&side=BUY&positionSide=SHORT&type=STOP_MARKET&quantity=0.001&stopPrice=29394&timestamp=1690794854618&signature=... HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Content-Type: application/x-www-form-urlencoded\r\n' +
      'X-MBX-APIKEY: ...\r\n' +
      'User-Agent: axios/1.4.0\r\n' +
      'Accept-Encoding: gzip, compress, deflate, br\r\n' +
      'Host: fapi.binance.com\r\n' +
      'Connection: close\r\n' +
      'Content-Length: 0\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype] {},
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 0,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'POST',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    joinDuplicateHeaders: undefined,
    path: '/fapi/v1/order?symbol=BTCUSDT&side=BUY&positionSide=SHORT&type=STOP_MARKET&quantity=0.001&stopPrice=29394&timestamp=1690794854618&signature=...',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      socket: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      joinDuplicateHeaders: undefined,
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 200,
      statusMessage: 'OK',
      client: [TLSSocket],
      _consuming: true,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'https://fapi.binance.com/fapi/v1/order?symbol=BTCUSDT&side=BUY&positionSide=SHORT&type=STOP_MARKET&quantity=0.001&stopPrice=29394&timestamp=1690794854618&signature=...',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 46,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'fapi.binance.com',
    protocol: 'https:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 0,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'https://fapi.binance.com/fapi/v1/order?symbol=BTCUSDT&side=BUY&positionSide=SHORT&type=STOP_MARKET&quantity=0.001&stopPrice=29394&timestamp=1690794854618&signature=...',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kBytesWritten)]: 0,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'content-type': [Array],
      'x-mbx-apikey': [Array],
      'user-agent': [Array],
      'accept-encoding': [Array],
      host: [Array]
    },
    [Symbol(errored)]: null,
    [Symbol(kUniqueHeaders)]: null
  },
  data: {
    orderId: 176324636148,
    symbol: 'BTCUSDT',
    status: 'NEW',
    clientOrderId: 'hv1l18kjSu46iiE0SyuyxA',
    price: '0.00',
    avgPrice: '0.00',
    origQty: '0.001',
    executedQty: '0.000',
    cumQty: '0.000',
    cumQuote: '0.00000',
    timeInForce: 'GTC',
    type: 'STOP_MARKET',
    reduceOnly: true,
    closePosition: false,
    side: 'BUY',
    positionSide: 'SHORT',
    stopPrice: '29394.00',
    workingType: 'CONTRACT_PRICE',
    priceProtect: false,
    origType: 'STOP_MARKET',
    updateTime: 1690794854809
  }
}

BUT, after that, we have 2 orders on Binance Futures with same active price but different in ID, this is message:

Order Update: {
  e: 'ORDER_TRADE_UPDATE',
  T: 1690794854809,
  E: 1690794854814,
  o: {
    s: 'BTCUSDT',
    c: 'hv1l18kjSu46iiE0SyuyxA',
    S: 'BUY',
    o: 'STOP_MARKET',
    f: 'GTC',
    q: '0.001',
    p: '0',
    ap: '0',
    sp: '29394',
    x: 'NEW',
    X: 'NEW',
    i: **176324636148**,
    l: '0',
    z: '0',
    L: '0',
    n: '0',
    N: 'USDT',
    T: 1690794854809,
    t: 0,
    b: '0',
    a: '0',
    m: false,
    R: true,
    wt: 'CONTRACT_PRICE',
    ot: 'STOP_MARKET',
    ps: 'SHORT',
    cp: false,
    rp: '0',
    pP: false,
    si: 0,
    ss: 0
  }
}
Order Update: {
  e: 'ORDER_TRADE_UPDATE',
  T: 1690794854868,
  E: 1690794854874,
  o: {
    s: 'BTCUSDT',
    c: 'B2oxvft88BDeYMamNKDlnw',
    S: 'BUY',
    o: 'STOP_MARKET',
    f: 'GTC',
    q: '0.001',
    p: '0',
    ap: '0',
    sp: '29394',
    x: 'NEW',
    X: 'NEW',
    i: **176324636505**,
    l: '0',
    z: '0',
    L: '0',
    n: '0',
    N: 'USDT',
    T: 1690794854868,
    t: 0,
    b: '0',
    a: '0',
    m: false,
    R: true,
    wt: 'CONTRACT_PRICE',
    ot: 'STOP_MARKET',
    ps: 'SHORT',
    cp: false,
    rp: '0',
    pP: false,
    si: 0,
    ss: 0
  }
}

Despite listening to a single WebSocket message and calling this Axios request once, two orders are being created in my Binance futures account. I have checked the WebSocket message handling logic, and there doesn’t seem to be any issue with multiple calls to the Axios request.

Could you please assist me in identifying the root cause of this problem? I have already verified that the WebSocket message is received only once when using console.log(message), so I suspect there might be something related to the Axios request.

Thank you for your help!

From the data you provided above, I think you have sent 2 orders; The websocket messages shows 2 orders with different orderId in NEW status.

Maybe you could try with different script to place order, it will help with debug.

1 Like

Thank for your support. I’ll try