Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3683

How can I fix the following error "Invalid JSON body","errorCode":"oanda::rest::core::ClientRequestException" with OANDA trading platform?

$
0
0

I am having a hard time figuring out what could be wrong with my POST request to OANDA. I have been trying to submit limit and stop orders with no success so far. In terms of setup I am using Python 3.10 and the Requests package on a Windows 10 machine.

Here is my Python code that returns the following error message:

b'{"errorMessage":"Invalid JSON body","errorCode":"oanda::rest::core::ClientRequestException"}'.

If anyone uses OANDA, with a demo account, and has experienced the same situation, please help. Here is the developer guide I have been relying on: https://developer.oanda.com/rest-live-v20/order-ep/.

Also, I can successfully submit GET requests for data retrieval.

import requestsdef submit_order():   headers = {"Content-Type": "application/json","Authorization": "Bearer " + [my access token]   }   submit_order_path = "https://api-fxpractice.oanda.com/v3/accounts/[my account number]/orders"   formatted_order = {   "order":{    "type": "STOP",    "instrument": "GBP_USD",    "units": "10000",    "price": "1.33606",    "priceBound": "1.33606",    "timeInForce": "GTD",    "gtdTime": "2024-09-27 21:00:00",    "positionFill": "DEFAULT",    "triggerCondition": "DEFAULT",    "clientExtensions": {        "id": "V-ALPHA",        "tag": "V-ALPHA",        "comment": "V-ALPHA"    },    "takeProfitOnFill": {        "price": "1.34374",        "timeInForce": "GTD",        "gtdTime": "2024-09-27 21:00:00"    },    "stopLossOnFill": {        "price": "1.33016",        "timeInForce": "GTD",        "gtdTime": "2024-09-27 21:00:00"    },    "tradeClientExtensions": {        "id": "V-ALPHA",        "tag": "V-ALPHA",        "comment": "V-ALPHA"    }    }  }  response = requests.post(url=submit_order_path, headers=headers, json=json.dumps(formatted_order))  return response

I have tried to contact the OANDA Support Team but at no avail.


Viewing all articles
Browse latest Browse all 3683

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>