peterszombati / xapi-node

xStation5 Trading API for NodeJS/JS
https://peterszombati.github.io/xapi-node/
Other
57 stars 19 forks source link

Issue with closing STC positions on XTB #25

Closed Rudy-Dev closed 2 years ago

Rudy-Dev commented 2 years ago

Hi there, the issue only occur when trying to close STC position doesn't happen when trying to close CRT position. I'm using XTB demo account.

code:

  try {
    await x.Socket.send
      .tradeTransaction({
        order: <POSITION_ID>,
        symbol: "RBLX.US",
        type: TYPE_FIELD.CLOSE,
        price: 0,
        volume: 1,
      })
      .then(() => {
        console.log("done");
      });
  } catch (err) {
    logError(err);
  }

also here is error dump:

 JsonError
    at Socket.sendCommand (C:\Users\mazep\Desktop\Projects\TS\TradeBot\node_modules\xapi-node\build\core\Socket\SocketConnection.js:60:23)
    at C:\Users\mazep\Desktop\Projects\TS\TradeBot\node_modules\xapi-node\build\core\Socket\Socket.js:119:33
    at new Promise (<anonymous>)
    at Object.tradeTransaction (C:\Users\mazep\Desktop\Projects\TS\TradeBot\node_modules\xapi-node\build\core\Socket\Socket.js:103:24)
    at Object.g2 (C:\Users\mazep\Desktop\Projects\TS\TradeBot\dist\index.js:93:14) {
  params: {
    reason: { code: 'BE11', explain: 'Position not found (#<POSITION_ID>)' },
    transaction: {
      command: 'tradeTransaction',
      type: 'Socket',
      request: [Object],
      response: [Object],
      transactionId: '164089816808500060',
      createdAt: [Time],
      status: 3,
      transactionPromise: [Object],
      urgent: true,
      stack: 'Error\n' +
        '    at Socket.sendCommand (C:\\Users\\mazep\\Desktop\\Projects\\TS\\TradeBot\\node_modules\\xapi-node\\build\\core\\Socket\\SocketConnection.js:60:23)\n' +
        '    at C:\\Users\\mazep\\Desktop\\Projects\\TS\\TradeBot\\node_modules\\xapi-node\\build\\core\\Socket\\Socket.js:119:33\n' +
        '    at new Promise (<anonymous>)\n' +
        '    at Object.tradeTransaction (C:\\Users\\mazep\\Desktop\\Projects\\TS\\TradeBot\\node_modules\\xapi-node\\build\\core\\Socket\\Socket.js:103:24)\n' +
        '    at Object.g2 (C:\\Users\\mazep\\Desktop\\Projects\\TS\\TradeBot\\dist\\index.js:93:14)'
    }
  }
}
peterszombati commented 2 years ago

for stocks I think you dont have to close positions you have to sell stocks for closing position but after market open I will give a try

Rudy-Dev commented 2 years ago

Hi, I got it working however I cannot specify orderId, It is closing the first order on the list. This is the code that I used:

  .tradeTransaction({
        cmd: CMD_FIELD.SELL,
        customComment: null,
        expiration: 0,
        offset: 0,
        order: 0,
        price: 1,
        symbol: "LBW.PL",
        tp: 0,
        sl: 0,
        type: TYPE_FIELD.OPEN,
        volume: 500,
      })