Is "orderId" and "id" the same?

issue: unable to cancel order using cancelOrder end point

API end point orderList returns:

[{'id': 517123456, # generalized for security
'accountId': 0, # generalized for security
'contractId': 0, # generalized for security
'timestamp': '2021-09-10T15:52:24.826Z', 
'action': 'Buy', 
'ordStatus': 
'Working',
'executionProviderId': 1, 
'archived': False, 
'external': False, 
'admin': False}]

API endpoint cancelOrder requires “orderId” for payload. How do I obtain “orderId”, when orderList does not provide this (at least by name). I have attempted using “id”, “accountId”, and 'contractId" with each returning a 404 error.

Schema for cancelOrder:

def cancel_order(orderid):
    endpoint = r'https://live.tradovateapi.com/v1/order/cancelorder'
    headers = {
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + cfg.access_token
    }

    payload = {
        'orderId': orderid,
        "isAutomated": False
    }

    content = requests.post(url=endpoint, headers=headers, params=payload)
    reply = content.json()

I have attempted with “isAutomated” removed, set too True, and as presented False.

Looks like Python, so I think you’ll want to use:
content = requests.post(url=endpoint, headers=headers, json=payload)

The order/cancelorder endpoint doesn’t use query parameters, so those go in the body.

Until Requests 2.4.2, you had to use data=JSON.dumps(payload), but in current versions it handles it for you.

Thank you. I have updated my files.

To answer the topic header. I can pseudo confirm commandItem provides both id and orderId which are the same value.

1 Like