0

I am using json and urllib to pull data from the IBKR client portal API:

data = json.load(urlopen("https://localhost:5000/v1/api/portfolio/{acct ID}/positions"

I am having trouble understanding how to pass information to it, for example, to place orders. The documentation just says "pass json here" basically and gives the url: /server/account/{accountId}/orders.

There are no other instructions in the documents.

helloimgeorgia
  • 311
  • 1
  • 10
  • It's a bit disingenuous to make the claim that "*There are no other instructions in the documents.*" [Their documentation](https://www.interactivebrokers.com/api/doc.html) is actually quite robust. Can you elaborate on why the [`iserver/account/{accountId}/order`](https://www.interactivebrokers.com/api/doc.html#tag/Order/paths/~1iserver~1account~1{accountId}~1order/post) endpoint doesn't meet your requirements? It's a `POST` request, so you would pass the JSON structure outlined there from your application as part of your request body, substituting the placeholders for your desired values. – esqew May 04 '21 at 18:37
  • If the question truly is regarding how to send `POST` requests from Python, this is a duplicate of [Simple URL GET/POST function in Python](https://stackoverflow.com/questions/4476373/simple-url-get-post-function-in-python), among many others. I'm voting to close as such. – esqew May 04 '21 at 18:41
  • doesn't actually answer my question, but thx for trying – helloimgeorgia May 04 '21 at 18:51

1 Answers1

0

I would imagine the API is expecting a POST request containing a JSON object in the body of the request.

Using the requests library (pip install requests)...

r = requests.post('.....server/account/{accountId}/orders', json={"key": "value"})

r is the response from that POST request.

You can then do these to view the response from the server and figure out if you are posting valid data:

r.status_code

r.json()

Donncha
  • 64
  • 1
  • 7