Jump to content
annadel

order/openpositions returns invalid error

Recommended Posts

Hi, I have a node.js program that does a GET method sent to "https://ciapi.cityindex.com/TradingAPI/order/openpositions?TradingAccountId=XXXXXXXX".  And keep getting the following error:

      HttpStatus: 401,
      ErrorMessage: 'Session is not valid',
      ErrorCode: 4011

I am using the same session acquired via https://ciapi.cityindex.com/TradingAPI/session, and it actually works fine with "barhistorybetween", which returns the history price data as expected.

I also open the streaming using the same session and subscribing stuff including CLIENTACCOUNTMARGIN, ORDERS, TRADEMARGIN, and multiple PRICE.xxxx's which also seem working fine.

So what is wrong with my openpositions query??  I attach the detailed error log from node.js/axios below.

Thank you for your help.

 response: {
    status: 401,
    statusText: 'Unauthorized',
    headers: {
      date: 'Mon, 31 Jan 2022 00:12:43 GMT',
      'content-type': 'application/json; charset=utf-8',
      'content-length': '73',
      connection: 'close',
      'cache-control': 'no-cache',
      pragma: 'no-cache',
      expires: '-1',
      'set-cookie': [Array],
      'x-aspnet-version': '4.0.30319',
      'x-powered-by': 'ASP.NET',
      'x-cache': 'CONFIG_NOCACHE',
      'x-azure-ref': '0ein3YQAAAAD6wVYdgh6yQbMdRSW7hw+JU0pDRURHRTA1MDgAOGJmMjA5ZmMtYzE2Mi00ZjhlLWE0NGUtNDRjNzg5NjcxNGQw',
      'cf-cache-status': 'DYNAMIC',
      'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
      server: 'cloudflare',
      'cf-ray': '6d5ebae06b7370e3-SJC'
    },
    config: {
      transitional: [Object],
      adapter: [Function: httpAdapter],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      headers: [Object],
      method: 'get',
      url: 'https://ciapi.cityindex.com/TradingAPI/order/openpositions?TradingAccountId=XXXXXXXX',
      data: undefined
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      _header: 'GET /TradingAPI/order/openpositions?TradingAccountId=XXXXXXXX HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'UserName: XXXXXXXX\r\n' +
        'Session: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\r\n' +
        'User-Agent: axios/0.25.0\r\n' +
        'Host: ciapi.cityindex.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/TradingAPI/order/openpositions?TradingAccountId=XXXXXXXX',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'ciapi.cityindex.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: {
      HttpStatus: 401,
      ErrorMessage: 'Session is not valid',
      ErrorCode: 4011
    }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]

Share this post


Link to post

Hello Annadel,

As a quick check, are you using the TradingAccountId obtained by making a GetClientAndTradingAccount call? A quick way to check if that is the error cause is to send the ListOpenPositions call without the ?TradingAccountId={TradingAccountId} at the end. 

If it still doesn't work we'll have to investigate further.

Kind Regards, PM

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×