What is a trading API? How programs talk to your broker

7 min read · Updated October 4, 2026

In short
  • An API (application programming interface) is a set of web addresses a program can call instead of a person clicking buttons: get my balance, get prices, place this order.
  • Each call is a request with a response. Your program proves who it is with a key or token, like a password made for software.
  • Trading APIs have two halves: market data (prices coming in) and orders (instructions going out), plus account information.
  • Live prices usually arrive over a streaming connection that stays open, rather than repeated requests.
  • Treat API keys like the keys to your account, and check your broker's or firm's rules on API use.

When you click Buy on your trading platform, the platform sends a message to your broker saying, in effect, "buy one contract of this market at the market price, for this account". An API lets your own program send that same message. Nothing more mysterious than that. Automated trading is a program that sends those messages based on your rules instead of your clicks.

Requests and responses

Most broker APIs work like the web. Your program sends a request to an address, and the broker sends back a response. A request to place an order might carry this information:

{
  "account": "your account id",
  "symbol": "MNQ",
  "side": "buy",
  "quantity": 1,
  "type": "market"
}

The response says whether the broker accepted it and gives the order an id, which your program uses later to check on it, change it or cancel it. If something is wrong (the market is closed, the account doesn't have enough margin, the size is over a limit), the response says that instead, and your program has to handle it.

The format above is JSON, a plain-text way of writing labelled values. Almost every modern API uses it, and it's readable by people as well as programs.

Proving who you are: keys and tokens

An API has to know a request really comes from you. Brokers do this with an API key, a long secret string you create in your broker's settings, often exchanged for a short-lived token that goes with every request. Anyone with your key can do whatever the key allows, so:

The three parts of a trading API

Account information

Balances, open positions, working orders and past fills. Journals use this part: TradeHarbor's broker auto-import (on Pro) reads your fills and positions this way, with a read-only connection where the broker offers one.

Market data

Prices. Historical bars (each 1 or 5-minute bar's open, high, low and close) are usually fetched with a request, which is how a backtester gets its history. Live prices are different: requesting them over and over would be slow and wasteful, so brokers offer a streaming connection that stays open and pushes each new price or bar to your program the moment it happens.

Orders

Place, modify and cancel. Most APIs support the same order types you'd use by hand: market, limit, stop. A common pattern is a bracket: the entry, plus a stop and a target that are placed as soon as the entry fills, with one cancelling the other when either is hit.

Limits and failures

Rules about API trading

Not every account may use an API, and not from anywhere. Some prop firms restrict automated or API trading, the places it can run from (such as servers or third-party services), or don't allow it on funded accounts at all. Brokers have their own terms. Read the current rules for your account before you connect a program to it.

How TradeHarbor uses broker APIs

Next steps

See how these pieces come together for a single trade in how automated trading works, or start from the beginning with how to automate a trading strategy.

Build it, test it, then automate it

Describe your idea in TradeHarbor's Strategy lab and see the rules and the Python they become. Test it on real futures history on Pro, then let it trade for you with automation.

Start free

Educational content only. Nothing here is investment, financial, or trading advice, and TradeHarbor is not affiliated with any prop firm or broker mentioned. Trading futures involves substantial risk of loss. Each firm's current published rules always govern.