JSON Endpoint Invalid clientRequestId

Created at 01 Dec 2023, 14:36
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
BR

bruce.kristelijn

Joined 07.04.2019

JSON Endpoint Invalid clientRequestId
01 Dec 2023, 14:36


Hi there!
 I am using the JSON websocket endpoint to retrieve and influence positions. However when sending a close request for a positionid I get this error:
 

{'payloadType': 2132, 'clientMsgId': '', 'payload': {'errorCode': 'INVALID_REQUEST', 'ctidTraderAccountId': 31913053, 'description': 'Invalid clientRequestId length: 0. ClientRequestId length must be more then 0 and less or equal then 64'}}

However I am unsure where to supply or retrieve this request ID?


I am using the following endpoint:
https://help.ctrader.com/open-api/messages/#protooaorderlistbypositionidreq

My request looks like this:

{'clientMsgId': '', 'payloadType': 2111, 'payload': {'ctidTraderAccountId': 31913053, 'positionId': 387499060, 'volume': 1000}}

I hope someone can help me understand how to resolve this error :)


@bruce.kristelijn
Replies

... Deleted by UFO ...

bruce.kristelijn
04 Dec 2023, 23:01

RE: JSON Endpoint Invalid clientRequestId

ridden_topknot0j said: 


Sure, I can help you understand how to resolve the error you're encountering when sending a close request for a position ID.

The error message indicates that the clientRequestId length is invalid. The clientRequestId is a unique identifier for each request that you send to the cTrader API. It must be between 1 and 64 characters long.

To resolve this error, you need to add a clientRequestId to your request. You can generate a unique clientRequestId using any method you like, such as using a UUID generator.

Here is an example of how to modify your request to include a clientRequestId:

JSON

{  "clientMsgId": "",  "clientRequestId": "1234567890abcdef",  "payloadType": 2111,  "payload": {    "ctidTraderAccountId": 31913053,    "positionId": 387499060,    "volume": 1000  }}

Once you have added a clientRequestId to your request, the error should be resolved.

 

 

 

 

 

 

 

 

Thank you so much for getting back to me, however my json looks like this: 

{"clientMsgId": "", "payloadType": 2111, "clientRequestId": "1234567890abcdef", "payload": {"ctidTraderAccountId": 31913053, "positionId": 387499060, "volume": 1000}}

But it still gives me this error:

{'payloadType': 2132, 'clientMsgId': '', 'payload': {'errorCode': 'INVALID_REQUEST', 'ctidTraderAccountId': 31913053, 'description': 'Invalid clientRequestId length: 0. ClientRequestId length must be more then 0 and less or equal then 64'}}

Is there something else I need to do?


@bruce.kristelijn