Search code examples
jsonxapi

XTB API JSON cannot modify existing trade position


I am using a xAPI Playground for testing, link here: https://playground.xapi.pro/ I want to edit/modify existing position with command: tradeTransaction. Documentation says to modify existing position I should use "type" as 3 and "cmd" should match existing position (0 for BUY and 1 for SELL)

{
    "command": "tradeTransaction",
    "arguments": {
        "tradeTransInfo": {
            "cmd": 1,
            "customComment": "Some text",
            "expiration": 0,
            "order": order_number_as_int ,
            "price": open_price_as_double,
            "sl": my_double_value,
            "tp": my_another_double_value,
            "symbol": "f.e. OIL.WTI",
            "type": 3,
            "volume": 0.01
        }
    }
}

Error code

{
    "status": false,
    "errorCode": "SE199",
    "errorDescr": "Internal error"
}

All possible data collected from API about existing position:

{'cmd': 1, 'order': 474325736, 'digits': 2, 'offset': 0, 'order2': 474325838, 'position': 474325736, 'symbol': 'OIL.WTI', 'comment': '', 'customComment': '', 'commission': 0.0, 'storage': 0.0, 'margin_rate': 0.0, 'close_price': 76.65, 'open_price': 76.57, 'nominalValue': 0.0, 'profit': -3.56, 'volume': 0.01, 'sl': 80.0, 'tp': 70.0, 'closed': False, 'timestamp': 1676665564666, 'spread': 0, 'taxes': 0.0, 'open_time': 1676663063081, 'open_timeString': 'Fri Feb 17 20:44:23 CET 2023', 'close_time': None, 'close_timeString': None, 'expiration': None, 'expirationString': None},

API documentation is here: http://developers.xstore.pro/documentation/#tradeTransaction

Of course I tried every possible value in "cmd" and "type" but it does not help. Error code sometimes are different, for example:

{
    "command": "tradeTransaction",
    "arguments": {
        "tradeTransInfo": {
            "cmd": 3,
            "customComment": "Some text",
            "expiration": 0,
            "order": 474325838,
            "price": 0,
            "sl": 0,
            "tp": 0,
            "symbol": "OIL.WTI",
            "type": 3,
            "volume": 0.01
        }
    }
}

Error code:

{
    "status": false,
    "errorCode": "BE4",
    "errorDescr": "remaining nominal must be greater than zero"
}

Any ideas what I can do wrong? I am in touch with XTB support, still waiting for response.


Solution

  • Simply use on "cmd" and "type" 0.

    Order, open price and symbol must be filled correctly.

    XTB support does not see any issue, they tried with "cmd" and "type" 3 and for them it worked fine.