Course contents
Asking the broker what is true
Before placing a single order, a program should be able to read the account and the market: available funds, current positions and holdings, a live quote, and historical candles. This chapter covers the read endpoints, which are safe to call and the right place to start, and shows the simulated broker answering the same questions offline.
- Fetch funds, positions, holdings, and a quote through the API shape
- Retrieve historical data for a strategy and connect it to Python for Trading
- Treat read endpoints as the safe first step before any order
The safest thing a trading program can do is ask questions. How much cash do I have. What do I own. What is the price right now. None of these change anything in the world; they only read what is already true. That is exactly why you build and test them first. A program that cannot reliably read your account has no business placing an order into it.
The four questions
A broker API answers a handful of read questions, and four of them cover most of what a strategy needs to know before it acts.
Funds: how much money is available to trade. The risk limits and position sizes the Risk and Psychology course drilled into you are meaningless if the program does not know the size of the account.
Positions: what you hold right now from today's trading, each with a quantity and an average price. This is how a program knows whether it is already long, already short, or flat, before it decides to act.
Holdings: shares held in your demat account from earlier, delivered and settled, as opposed to today's intraday positions. A real broker separates the two, so know which you are reading.
A quote: the latest price of an instrument, and often the best buy and sell prices around it. It is how the program knows where the market is this instant.
Here are those reads against the simulated broker, after buying two stocks so there is something to see.
# Reading the account: funds, positions, and a quote. None of these calls change
# anything, so they are always safe and are the right place to start. We create a
# little state first by buying two stocks, then read it back.
from paper_broker import PaperBroker
broker = PaperBroker(cash=1_000_000, prices={"RELIANCE": 1400, "INFY": 1500})
# Some account state to read back.
broker.place_order("RELIANCE", "BUY", 100, "MARKET")
broker.place_order("INFY", "BUY", 50, "MARKET")
# Read-only calls.
print("Funds:", broker.get_funds())
print("Positions:")
for p in broker.get_positions():
print(f" {p['symbol']:<9} qty {p['quantity']:>4} avg {p['avg_price']}")
print("Holdings:", broker.get_holdings())
print("Quote RELIANCE:", broker.get_quote("RELIANCE"))Funds: {'available_cash': 785000.0}
Positions:
RELIANCE qty 100 avg 1400.0
INFY qty 50 avg 1500.0
Holdings: [{'symbol': 'RELIANCE', 'quantity': 100, 'avg_price': 1400.0}, {'symbol': 'INFY', 'quantity': 50, 'avg_price': 1500.0}]
Quote RELIANCE: {'symbol': 'RELIANCE', 'last_price': 1400, 'bid': 1400.0, 'ask': 1400.0}Read the output. After buying 100 Reliance at 1,400 and 50 Infosys at 1,500, the account shows 7,85,000 rupees left, from a starting 10,00,000, because 1,40,000 and 75,000 went into the two positions. The positions list reports exactly what is held and at what average price, and the quote gives the latest price. Every one of these is a question, not an action. You can call them as often as you like and nothing moves.
# The same reads through a real broker's SDK, shown generically and NOT run.
funds = client.get_funds()
positions = client.get_positions()
holdings = client.get_holdings()
quote = client.get_quote("NSE:RELIANCE")Historical data, and where it comes from
A strategy also needs history: the past prices it computes its signals from. You already know how to get that. In Python for Trading you loaded a CSV and fetched candles with an open library and a broker's data path. A live system does the same at startup, pulling the recent history it needs to warm up its indicators, then keeping that history current as new prices stream in. Historical data is a read like any other, and the broker's SDK usually offers it alongside the account reads.
# Historical candles through a broker's SDK, shown generically and NOT run.
# In Python for Trading you also fetched these with an open library (yfinance).
candles = client.historical_data("NSE:RELIANCE", interval="day",
start="2026-01-01", end="2026-03-31")Why reads come first
There is a discipline in starting with reads, beyond their safety. A program that can accurately read your funds, positions, and prices has proven that its connection works, its authentication is valid, and it understands the data the broker sends. Those are exactly the things that must be solid before an order is ever sensible. Many real bugs, a misread position, a stale price, a wrong symbol, show up harmlessly in a read and would be expensive in an order. Get the questions right, and the answers you act on later can be trusted.
What to carry forward
A trading program should be able to answer four questions before it acts: how much cash is available, what it holds today, what is settled in demat, and what the price is right now. These reads change nothing, so they are safe to run and are where you build confidence, and you saw them return real, consistent numbers from the simulated broker. History, the past prices a strategy needs, is another read, the same one you used in Python for Trading. Reads prove the connection, the login, and your understanding of the data, all of which must be solid before an order makes sense. Next, the one read that cannot be a simple question and answer: the live price stream.