Sub-account api connection

Hello, I have a new sub-account to connect to the API. My main account works fine. Where do I specify the sub-account ID/name in the API so it places trades in that account?
Thanks! Mark

Hi @Mark_Friedman. When you are placing an order via API, you should specify it in the JSON body of the requests to order/placeorder (or startOrderStrategy, /placeOCO or /placeOSO requests). You would use the accountId field:

const requestBody = {
    //below: string identifier, typically the account name is most identifiable
    accountSpec: identifierForThisTxn, 
    accountId: yourAcctId, // <- this is the field you need to put the account ID in.
    action: "Buy",
    symbol: "ES",
    orderQty: 1,
    orderType: "Market",
    isAutomated: true //must be true if this isn't an order made directly by a human
}

This is a trivial example, you’ll likely want to use a more complex order scheme, but the accountId field will be present in orders of every type. If you want to place orders in both simultaneously, hold onto the request body and send it again with your main account’s name and ID.

Thank you Alex! One question, sorry if obvious, Im doing this myself and mostly figured it out

Do I put the new account # in the quotations and replace “account ID”?
json[“accountSpec”] = accountSpec;
json[“accountId”] = (int)StringToInteger(accountId);
json[“action”] = “Buy”;
json[“symbol”] = Symb;
json[“orderQty”] = (int)LotSize;
json[“orderType”] = “Market”;
json[“isAutomated”] = true ;

See the part where it says (int)StringToInteger(accountId)? If you know the exact ID you can just replace that whole part with the ID number. You need to know the ID of the account though which will typically be found via API - the account ID is it’s entity ID in our system. You can find this by calling /account/find?name=YOUR_ACCT_NAME. You will receive JSON like this:

{
  "id": 0, 
  "name": "string",
  "userId": 0,
  "accountType": "Customer",
  "active": true,
  "clearingHouseId": 0,
  "riskCategoryId": 0,
  "autoLiqProfileId": 0,
  "marginAccountType": "Hedger",
  "legalStatus": "Corporation",
  "timestamp": "2019-08-24T14:15:22Z",
  "readonly": true
}

It will have real values of course. You want the value from the "id" field in this response.

FYI, if you don’t know already, we have nice interactive API Docs. You can test calls right there on the page (they will use the simulation environment, keep that in mind). Use the accessTokenRequest to pull an access token using your credentials. Then copy the value into the Authorize button at the top of the page - now you can use any (90%) of the operations. Just click Interact → Try it Out and fill out the form to test various API calls. It’s a very useful tool for learning the API functions and output.

Works now! Thanks Alex

Hey Alex,

Had another question please. We use Metatrader to send orders to Tradovate but currently have to use demo accounts (which expire after 3 mths), from other brokers in order to access real-time futures data. Is there a way we can access futures data through the API?
Thanks!
Mark

You can access real-time market data via API, but current CME rules state that our users will need to register as sub-vendors of CME data in order to actually view that data.

Thanks Alex - yes we are registered with CME and pay the monthly license fee so we can use the API…

In that case, sure we have a whole segment on it in our documentation. But basically the gist is this:

  • acquire standard access token using REST API /auth/accesstokenrequest
  • open a websocket connection to wss://md.tradovateapi.com/v1/websocket
  • authorize the websocket using the access token you acquired.
  • subscribe to some market data you care about. There are a few types of subscriptions (all detailed here), all of which will return a real-time stream of data through the websocket:
    • md/subscribeQuote - probably the cheapest way to request real-time price data.
    • md/subscribeDOM - opens a subscription to Depth-of-market data for an instrument.
    • md/subscribeHistogram - gets histogram footprint data
    • md/getChart - can do a few things - you can get the raw tick stream (some people call this time-and-price), or you can get a variety of pre-aggregated bar chart data based on your parameters. There is more info here.

Thanks Alex! Will go for it and lyk if any questions.
Cheers,
Mark