Has order placing base url changed?

Hello Upstox team, has order placing base url has changed from https://api-v2.upstox.com/order/place to https://api-hft.upstox.com/v2/order/place

I am getting 400 status code while placing order with v2 version.

@shanmu @vishalchawda @Vaibhav_Naik

Hello @Anand_Kumar,

Both URLs are functional. Could you please share the cURL request that resulted in a 400 response, along with the error details, for further assistance.

Thank you.

hello @Ketan, here is the error from nodejs application with axios.

AxiosError: Request failed with status code 400
      at settle (/home/ec2-user/projects/fibFan_nodejs/node_modules/axios/lib/core/settle.js:19:12)
      at IncomingMessage.handleStreamEnd (/home/ec2-user/projects/fibFan_nodejs/node_modules/axios/lib/adapters/http.js:570:11)
      at IncomingMessage.emit (node:events:531:35)
      at endReadableNT (node:internal/streams/readable:1696:12)
      at processTicksAndRejections (node:internal/process/task_queues:82:21) {
    code: 'ERR_BAD_REQUEST',
    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',
        'Content-Type': 'application/json',
        'Api-Version': '2.0',
        Authorization: 'Bearer eyJ0eXAiOiJKV1QiLCJrZXlfaWQiO......x2tQ',
        'User-Agent': 'axios/1.4.0',
        'Content-Length': '228',
        'Accept-Encoding': 'gzip, compress, deflate, br'
      },
      method: 'post',
      url: 'https://api-v2.upstox.com/order/place',
      data: '{"quantity":30,"product":"D","validity":"DAY","price":10,"tag":"BN_buy_order_nodejs_v2_api","instrument_token":"NSE_FO|48046","order_type":"LIMIT","transaction_type":"BUY","disclosed_quantity":0,"trigger_price":0,"is_amo":false}'
    },
    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: false,
      chunkedEncoding: false,
      shouldKeepAlive: true,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: '228',
      _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: 'api-v2.upstox.com',
        alpnProtocol: false,
        authorized: true,
        authorizationError: null,
        encrypted: true,
        _events: [Object: null prototype],
        _eventsCount: 9,
        connecting: false,
        _hadError: false,
        _parent: null,
        _host: 'api-v2.upstox.com',
        _closeAfterHandlingError: false,
        _readableState: [ReadableState],
        _writableState: [WritableState],
        allowHalfOpen: false,
        _maxListeners: undefined,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: [TLSWrap],
        _requestCert: true,
        _rejectUnauthorized: true,
        timeout: 5000,
        parser: null,
        _httpMessage: null,
        autoSelectFamilyAttemptedAddresses: [Array],
        [Symbol(alpncallback)]: null,
        [Symbol(res)]: [TLSWrap],
        [Symbol(verified)]: true,
        [Symbol(pendingSession)]: null,
        [Symbol(async_id_symbol)]: -1,
        [Symbol(kHandle)]: [TLSWrap],
        [Symbol(lastWriteQueueSize)]: 0,
        [Symbol(timeout)]: Timeout {
          _idleTimeout: 5000,
          _idlePrev: [TimersList],
          _idleNext: [Timeout],
          _idleStart: 830409,
          _onTimeout: [Function: bound ],
          _timerArgs: undefined,
          _repeat: null,
          _destroyed: false,
          [Symbol(refed)]: false,
          [Symbol(kHasPrimitive)]: false,
          [Symbol(asyncId)]: 3307,
          [Symbol(triggerId)]: 3305
        },
        [Symbol(kBuffer)]: null,
        [Symbol(kBufferCb)]: null,
        [Symbol(kBufferGen)]: null,
        [Symbol(shapeMode)]: true,
        [Symbol(kCapture)]: false,
        [Symbol(kSetNoDelay)]: false,
        [Symbol(kSetKeepAlive)]: true,
        [Symbol(kSetKeepAliveInitialDelay)]: 1,
        [Symbol(kBytesRead)]: 0,
        [Symbol(kBytesWritten)]: 0,
        [Symbol(connect-options)]: [Object]
      },
      _header: 'POST /order/place HTTP/1.1\r\n' +
        'Accept: application/json\r\n' +
        'Content-Type: application/json\r\n' +
        'Api-Version: 2.0\r\n' +
        'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJrZXlfaWQiO......x2tQ\r\n' +
        'User-Agent: axios/1.4.0\r\n' +
        'Content-Length: 228\r\n' +
        'Accept-Encoding: gzip, compress, deflate, br\r\n' +
        'Host: api-v2.upstox.com\r\n' +
        'Connection: keep-alive\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: true,
        maxSockets: Infinity,
        maxFreeSockets: 256,
        scheduling: 'lifo',
        maxTotalSockets: Infinity,
        totalSocketCount: 1,
        maxCachedSessions: 100,
        _sessionCache: [Object],
        [Symbol(shapeMode)]: false,
        [Symbol(kCapture)]: false
      },
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/order/place',
      _ended: true,
      res: IncomingMessage {
        _events: [Object],
        _readableState: [ReadableState],
        _maxListeners: undefined,
        socket: null,
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        rawHeaders: [Array],
        rawTrailers: [],
        joinDuplicateHeaders: undefined,
        aborted: false,
        upgrade: false,
        url: '',
        method: null,
        statusCode: 400,
        statusMessage: 'Bad Request',
        client: [TLSSocket],
        _consuming: true,
        _dumped: false,
        req: [Circular *1],
        _eventsCount: 4,
        responseUrl: 'https://api-v2.upstox.com/order/place',
        redirects: [],
        [Symbol(shapeMode)]: true,
        [Symbol(kCapture)]: false,
        [Symbol(kHeaders)]: [Object],
        [Symbol(kHeadersCount)]: 42,
        [Symbol(kTrailers)]: null,
        [Symbol(kTrailersCount)]: 0
      },
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'api-v2.upstox.com',
      protocol: 'https:',
      _redirectable: Writable {
        _events: [Object],
        _writableState: [WritableState],
        _maxListeners: undefined,
        _options: [Object],
        _ended: true,
        _ending: true,
        _redirectCount: 0,
        _redirects: [],
        _requestBodyLength: 228,
        _requestBodyBuffers: [],
        _eventsCount: 3,
        _onNativeResponse: [Function (anonymous)],
        _currentRequest: [Circular *1],
        _currentUrl: 'https://api-v2.upstox.com/order/place',
        [Symbol(shapeMode)]: true,
        [Symbol(kCapture)]: false
      },
      [Symbol(shapeMode)]: false,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype] {
        accept: [Array],
        'content-type': [Array],
        'api-version': [Array],
        authorization: [Array],
        'user-agent': [Array],
        'content-length': [Array],
        'accept-encoding': [Array],
        host: [Array]
      },
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null
    },
    response: {
      status: 400,
      statusText: 'Bad Request',
      headers: AxiosHeaders {
        date: 'Fri, 23 Aug 2024 04:46:02 GMT',
        'content-type': 'application/json',
        'transfer-encoding': 'chunked',
        connection: 'keep-alive',
        vary: 'Origin, Access-Control-Request-Method, Access-Control-Request-Headers',
        'x-content-type-options': 'nosniff',
        'x-xss-protection': '1; mode=block',
        'cache-control': 'no-cache, no-store, max-age=0, must-revalidate',
        pragma: 'no-cache',
        expires: '0',
        'strict-transport-security': 'max-age=0; includeSubDomains',
        'x-frame-options': 'DENY',
        message: 'request failed',
        'cf-cache-status': 'DYNAMIC',
        'set-cookie': [Array],
        server: 'cloudflare',
        'cf-ray': '8b7874de4aa66eca-BOM',
        'alt-svc': 'h3=":443"; ma=86400'
      },
      config: {
        transitional: [Object],
        adapter: [Array],
        transformRequest: [Array],
        transformResponse: [Array],
        timeout: 0,
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: -1,
        maxBodyLength: -1,
        env: [Object],
        validateStatus: [Function: validateStatus],
        headers: [AxiosHeaders],
        method: 'post',
        url: 'https://api-v2.upstox.com/order/place',
        data: '{"quantity":30,"product":"D","validity":"DAY","price":10,"tag":"BN_buy_order_nodejs_v2_api","instrument_token":"NSE_FO|48046","order_type":"LIMIT","transaction_type":"BUY","disclosed_quantity":0,"trigger_price":0,"is_amo":false}'
      },
      request: <ref *1> ClientRequest {
        _events: [Object: null prototype],
        _eventsCount: 7,
        _maxListeners: undefined,
        outputData: [],
        outputSize: 0,
        writable: true,
        destroyed: true,
        _last: false,
        chunkedEncoding: false,
        shouldKeepAlive: true,
        maxRequestsOnConnectionReached: false,
        _defaultKeepAlive: true,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        strictContentLength: false,
        _contentLength: '228',
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        _closed: true,
        socket: [TLSSocket],
        _header: 'POST /order/place HTTP/1.1\r\n' +
          'Accept: application/json\r\n' +
          'Content-Type: application/json\r\n' +
          'Api-Version: 2.0\r\n' +
          'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJrZXlfaWQiO......x2tQ\r\n' +
          'User-Agent: axios/1.4.0\r\n' +
          'Content-Length: 228\r\n' +
          'Accept-Encoding: gzip, compress, deflate, br\r\n' +
          'Host: api-v2.upstox.com\r\n' +
          'Connection: keep-alive\r\n' +
          '\r\n',
        _keepAliveTimeout: 0,
        _onPendingData: [Function: nop],
        agent: [Agent],
        socketPath: undefined,
        method: 'POST',
        maxHeaderSize: undefined,
        insecureHTTPParser: undefined,
        joinDuplicateHeaders: undefined,
        path: '/order/place',
        _ended: true,
        res: [IncomingMessage],
        aborted: false,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        reusedSocket: false,
        host: 'api-v2.upstox.com',
        protocol: 'https:',
        _redirectable: [Writable],
        [Symbol(shapeMode)]: false,
        [Symbol(kCapture)]: false,
        [Symbol(kBytesWritten)]: 0,
        [Symbol(kNeedDrain)]: false,
        [Symbol(corked)]: 0,
        [Symbol(kOutHeaders)]: [Object: null prototype],
        [Symbol(errored)]: null,
        [Symbol(kHighWaterMark)]: 16384,
        [Symbol(kRejectNonStandardBodyWrites)]: false,
        [Symbol(kUniqueHeaders)]: null
      },
      data: { status: 'error', errors: [Array] }
    }
  }

hello @shanmu @Ketan @Vaibhav_Naik @vishalchawda , it seems order placing v2 API is working today.

please make sure that, none of the API have breaking changes. and it should be always backward compatible.

since, now v2 API trading is not in beta phase and chargeable too, we as a client expect 100% confidence on your APIā€™s.

Thanks.

We have verified that both URLs are functioning correctly. It was noted that you disabled NSE_FO segment on August 13th and subsequently re-enabled on August 23rd at 10:40:59.735 Additionally, it was noted that the above mentioned order was placed before 10:40 a.m. on August 23rd.

I hope this clarifies the issue above.

Thank you

1 Like

Thanks @Ketan for the update.

I believe a proper error message (instead of just status: 400,statusText: ā€˜Bad Requestā€™,) would have saved a lot of time for all of us.

Regards.

Dear @Anand_Kumar,

We do provide clear error messages along with corresponding status codes. Based on the response you shared, the error message can be found in the data section, within the errors field. However, since arrays are objects in Node.js, they may not have been displayed as expected on your end.

To view the error messages properly, please use appropriate object-to-string conversion libraries, such as JSON.stringify().
Screenshot 2024-08-29 at 12.34.46 PM

I hope the above information helps.

Thank you.