This is a Python tutorial, not a strategy or trading recommendation. You can place and modify orders with the OpenAlgo Python SDK from a short Python script, once the server is in Analyze mode and you check status on every response. In our run at 5:06 PM IST on 30 November 2026, after the cash market had closed, a RELIANCE CNC market buy of one share completed at Rs 1,383.40, the session’s last price. A limit buy at Rs 1,200 stayed open until we changed its price, then its quantity, and later cancelled it.
OpenAlgo is an open source project created by the founder of Marketcalls. The snippets below were run against a local server with openalgo 2.4.1, and every response carried "mode": "analyze". The script never switched the server to live mode. The method names follow the OpenAlgo API documentation.
Check Analyze mode before you place and modify orders
Orders go through only after you confirm Analyze mode. client.analyzerstatus() is a read. It does not change the mode. Our first check, at 5:06:35 PM IST on 30 November 2026, returned this:
{'data': {'analyze_mode': True, 'mode': 'analyze', 'total_logs': 7},
'status': 'success'}
If mode is not "analyze", or analyze_mode is not True, stop. Do not call placeorder. Leave the mode as you found it.

However, a placement acknowledgement is not a fill. placeorder can return "status": "success" and an orderid while the order is still open, still trigger pending, or already rejected. The next call is always orderstatus.
Set up the client before you place and modify orders
You need a running OpenAlgo server, your API key in an environment variable, and openalgo 2.4.1 or later (pip install -U openalgo). This run used that version on Python 3.13. The REST host defaults to http://127.0.0.1:5000. Keep the API key out of the script.
pip install -U openalgo
export OPENALGO_API_KEY="your_api_key"
export OPENALGO_HOST="http://127.0.0.1:5000"
import os
from openalgo import api
client = api(
api_key=os.getenv("OPENALGO_API_KEY", "your_api_key"),
host=os.getenv("OPENALGO_HOST", "http://127.0.0.1:5000"),
)
status = client.analyzerstatus()
data = status.get("data") or {}
if (
status.get("status") != "success"
or data.get("mode") != "analyze"
or data.get("analyze_mode") is not True
):
raise SystemExit("Server is not in Analyze mode. No order was sent.")
The SDK methods are keyword-only. On placeorder and modifyorder the Python argument is price_type. The client sends the REST field pricetype. Use order_id in Python; the client sends orderid.
Once the client is ready, you can place and modify orders without putting the API key in the file. Once a signal comes from something like Your First Backtest with the OpenAlgo Python SDK, these are the calls that turn it into an order. For a view of the book around a quote, see Read the Live Order Book with OpenAlgo Market Depth.
Place a limit order and read its status
We bought RELIANCE on NSE as CNC, a delivery product, with a quantity of one share. The session’s last price was Rs 1,383.40, with a high of Rs 1,391.00, a low of Rs 1,373.70 and volume of 1,33,88,167 shares. We set the limit well below that last price so the order would remain open, which is what we needed in order to change it.
response = client.placeorder(
strategy="PlaceModifyTutorial",
symbol="RELIANCE",
action="BUY",
exchange="NSE",
price_type="LIMIT",
product="CNC",
quantity=1,
price=1200,
disclosed_quantity=0,
)
print(response)
{'mode': 'analyze', 'orderid': '2611xxxxxxx964', 'status': 'success'}
Order ids in this article are masked. Then orderstatus returned:
status = client.orderstatus(
order_id=response["orderid"],
strategy="PlaceModifyTutorial",
)
print(status)
{'data': {'action': 'BUY',
'average_price': 0.0,
'exchange': 'NSE',
'filled_quantity': 0,
'order_status': 'open',
'orderid': '2611xxxxxxx964',
'pending_quantity': 1,
'price': 1200.0,
'price_type': 'LIMIT',
'product': 'CNC',
'quantity': 1,
'strategy': 'PlaceModifyTutorial',
'symbol': 'RELIANCE',
'timestamp': '2026-11-30 17:06:35',
'trigger_price': 0.0},
'mode': 'analyze',
'status': 'success'}
The timestamp is 5:06:35 PM IST on 30 November 2026, from the order status returned by the server. order_status was open, filled_quantity was 0, and the limit price was still Rs 1,200. That is the state you want before you change an order.
Change the price and the quantity with modifyorder
modifyorder needs the same identity fields as the original order: order_id, symbol, action, exchange, price_type and product, plus the new quantity, price, disclosed_quantity and trigger_price. For a plain limit order, set trigger_price to 0.
First we moved the limit from Rs 1,200 to Rs 1,210, still for one share:
response = client.modifyorder(
order_id=limit_id,
strategy="PlaceModifyTutorial",
symbol="RELIANCE",
action="BUY",
exchange="NSE",
price_type="LIMIT",
product="CNC",
quantity=1,
price=1210,
disclosed_quantity=0,
trigger_price=0,
)
print(response)
{'message': 'Order modified successfully',
'mode': 'analyze',
'orderid': '2611xxxxxxx964',
'status': 'success'}
orderstatus then showed price of 1210.0, still open. A second modify raised quantity to 2 at the same price. After that, quantity and pending_quantity were both 2, and filled_quantity was still 0. The same orderid stayed on the order through both changes. That is the usual way to place and modify orders that are still open.
Place SL and SL-M orders, then change the trigger

SL is a stop-loss limit: when the last price crosses trigger_price, a limit order is sent at price. SL-M is a stop-loss market order: after the trigger, it is sent as a market order, so you pass trigger_price and not a limit price.
A CNC sell stop needs a holding
However, a CNC sell is refused if you have no delivery position to sell. Our first RELIANCE CNC sell stop, placed with no holding, came back as HTTP 400: “Cannot sell RELIANCE in CNC. No positions or holdings available.” The order was recorded as rejected.
The working path was to buy one share first, then place the sell stop against that holding. After a CNC market buy completed at Rs 1,383.40, this SL sell was accepted:
response = client.placeorder(
strategy="PlaceModifyTutorial",
symbol="RELIANCE",
action="SELL",
exchange="NSE",
price_type="SL",
product="CNC",
quantity=1,
price=1090,
trigger_price=1100,
disclosed_quantity=0,
)
{'mode': 'analyze', 'orderid': '2611xxxxxxx878', 'status': 'success'}
orderstatus showed order_status of trigger pending, price of 1090.0 and trigger_price of 1100.0, at 5:07:26 PM IST. We then changed the trigger to 1110 and the limit to 1100 with modifyorder, passing price_type="SL" and the new trigger_price. The order stayed trigger pending, with trigger_price of 1110.0 and price of 1100.0.
An SL-M sell at a trigger of Rs 1,050 was also accepted, with order_status of trigger pending and price of 0.0. We cancelled both stops before flattening the long. The same two price types also rest as trigger pending on the buy side when the trigger sits above the last price, and that buy-side case does not need a holding.
Cancel one order, or cancel all open orders
cancelorder takes the order_id and a strategy label. We placed a second limit buy at Rs 1,150, then cancelled just that order:
response = client.cancelorder(
order_id=limit2_id,
strategy="PlaceModifyTutorial",
)
print(response)
{'message': 'Order cancelled successfully',
'mode': 'analyze',
'orderid': '2611xxxxxxx906',
'status': 'success'}
orderstatus then showed order_status of cancelled.
cancelallorder, however, is different. The strategy argument is a label for the logs. It is not a filter. The call cancels every open and trigger-pending order on the account that owns the API key, including stops that protect other positions. In Analyze mode it cancels every open sandbox order for that user. Read orderbook first, and do not call it if any open order is not yours.
After that check, our book had one open limit left, the one at Rs 1,210 for two shares. cancelallorder(strategy="PlaceModifyTutorial") returned:
{'canceled_orders': ['2611xxxxxxx964'],
'failed_cancellations': [],
'message': 'Canceled 1 orders. Failed to cancel 0 orders.',
'mode': 'analyze',
'status': 'success'}
Place a market order, then flatten with placesmartorder
At 5:06:37 PM IST, after the resting orders had been cancelled, we sent a market buy of one share:
response = client.placeorder(
strategy="PlaceModifyTutorial",
symbol="RELIANCE",
action="BUY",
exchange="NSE",
price_type="MARKET",
product="CNC",
quantity=1,
)
{'mode': 'analyze', 'orderid': '2611xxxxxxx217', 'status': 'success'}
orderstatus showed order_status of complete, filled_quantity of 1, pending_quantity of 0 and average_price of 1383.4, the last price of the completed session. openposition for RELIANCE CNC then returned quantity of 1, with "mode": "analyze".
placesmartorder adds one required argument, position_size, which is the net position you want to have after the call, not the size of this ticket alone. With one share already open, this call sold that share and left the position flat:
response = client.placesmartorder(
strategy="PlaceModifyTutorial",
symbol="RELIANCE",
action="SELL",
exchange="NSE",
price_type="MARKET",
product="CNC",
quantity=1,
position_size=0,
)
The smart order completed at an average_price of 1383.4, and openposition returned quantity of 0. After you place and modify orders, this is the call that takes the net position back to zero. We confirmed Analyze mode again at the end of the run, still mode: analyze.
If you send many orders in a tight loop, connection reuse matters. Slashing API order latency with HTTP connection pooling covers that part of the same client path.
Check every response when you place and modify orders
However, a returned dictionary does not mean the call succeeded. Look at status. On a validation or lookup failure the SDK returns status of error, an HTTP code, and error_type of http_error. The message wraps the server JSON.
A limit order sent without price came back as HTTP 400:
{'status': 'error',
'message': 'HTTP 400: {"message":"LIMIT orders require price","mode":"analyze","status":"error"}',
'code': 400,
'error_type': 'http_error'}
orderstatus and modifyorder on an unknown id, 000000000000000, both came back as HTTP 404: “Order 000000000000000 not found”.
A small helper keeps the happy path readable:
def check(response, label):
print(label)
print(response)
if not isinstance(response, dict) or response.get("status") != "success":
raise SystemExit(f"{label} did not succeed.")
return response
A complete script to place and modify orders
The complete example below is a single file you can run to place and modify orders in Analyze mode. It uses the check helper, re-checks Analyze mode before every order call, cancels the working limit and the sell stop, and flattens any leftover RELIANCE CNC position with placesmartorder. It does not call cancelallorder, because that call is account-wide.
#!/usr/bin/env python3
"""Place and modify orders with the OpenAlgo Python SDK.
Needs openalgo 2.4.1 or later (pip install -U openalgo) and a running
OpenAlgo server. Set OPENALGO_API_KEY in your environment. Optionally
set OPENALGO_HOST (default http://127.0.0.1:5000). Never paste the key
into a script you share.
The script sends orders only when analyzerstatus() reports Analyze mode.
It never toggles the mode. If the server is not in Analyze mode, it stops
before any order is sent.
"""
import os
import sys
from openalgo import api
STRATEGY = "PlaceModifyTutorial"
SYMBOL = "RELIANCE"
EXCHANGE = "NSE"
PRODUCT = "CNC"
def require_analyze(client):
status = client.analyzerstatus()
data = status.get("data") or {}
if (
status.get("status") != "success"
or data.get("mode") != "analyze"
or data.get("analyze_mode") is not True
):
print("Server is not in Analyze mode. No order was sent.")
print(status)
raise SystemExit(2)
return status
def check(response, label):
print(label)
print(response)
if not isinstance(response, dict) or response.get("status") != "success":
raise SystemExit(f"{label} did not succeed.")
return response
def main():
api_key = os.getenv("OPENALGO_API_KEY", "your_api_key")
host = os.getenv("OPENALGO_HOST", "http://127.0.0.1:5000")
if not api_key or api_key == "your_api_key":
print("Set OPENALGO_API_KEY in the environment.")
return 1
client = api(api_key=api_key, host=host)
require_analyze(client)
quote = check(client.quotes(symbol=SYMBOL, exchange=EXCHANGE), "quotes")
last_price = float(quote["data"]["ltp"])
print("last_price", last_price)
# Limit buy well below the last price, so it should rest as open.
require_analyze(client)
limit = check(
client.placeorder(
strategy=STRATEGY,
symbol=SYMBOL,
action="BUY",
exchange=EXCHANGE,
price_type="LIMIT",
product=PRODUCT,
quantity=1,
price=1200,
disclosed_quantity=0,
),
"placeorder LIMIT",
)
limit_id = limit["orderid"]
check(client.orderstatus(order_id=limit_id, strategy=STRATEGY), "status after place")
require_analyze(client)
check(
client.modifyorder(
order_id=limit_id,
strategy=STRATEGY,
symbol=SYMBOL,
action="BUY",
exchange=EXCHANGE,
price_type="LIMIT",
product=PRODUCT,
quantity=1,
price=1210,
disclosed_quantity=0,
trigger_price=0,
),
"modify price to 1210",
)
require_analyze(client)
check(
client.modifyorder(
order_id=limit_id,
strategy=STRATEGY,
symbol=SYMBOL,
action="BUY",
exchange=EXCHANGE,
price_type="LIMIT",
product=PRODUCT,
quantity=2,
price=1210,
disclosed_quantity=0,
trigger_price=0,
),
"modify quantity to 2",
)
check(client.orderstatus(order_id=limit_id, strategy=STRATEGY), "status after modify")
require_analyze(client)
check(client.cancelorder(order_id=limit_id, strategy=STRATEGY), "cancel limit")
check(client.orderstatus(order_id=limit_id, strategy=STRATEGY), "status after cancel")
# Market buy of one share, then a sell stop, then flatten.
require_analyze(client)
market = check(
client.placeorder(
strategy=STRATEGY,
symbol=SYMBOL,
action="BUY",
exchange=EXCHANGE,
price_type="MARKET",
product=PRODUCT,
quantity=1,
),
"placeorder MARKET",
)
check(
client.orderstatus(order_id=market["orderid"], strategy=STRATEGY),
"status after market",
)
require_analyze(client)
stop = check(
client.placeorder(
strategy=STRATEGY,
symbol=SYMBOL,
action="SELL",
exchange=EXCHANGE,
price_type="SL",
product=PRODUCT,
quantity=1,
price=1090,
trigger_price=1100,
disclosed_quantity=0,
),
"placeorder SL",
)
stop_id = stop["orderid"]
check(client.orderstatus(order_id=stop_id, strategy=STRATEGY), "status after SL")
require_analyze(client)
check(
client.modifyorder(
order_id=stop_id,
strategy=STRATEGY,
symbol=SYMBOL,
action="SELL",
exchange=EXCHANGE,
price_type="SL",
product=PRODUCT,
quantity=1,
price=1100,
disclosed_quantity=0,
trigger_price=1110,
),
"modify SL trigger",
)
check(client.orderstatus(order_id=stop_id, strategy=STRATEGY), "status after SL modify")
require_analyze(client)
check(client.cancelorder(order_id=stop_id, strategy=STRATEGY), "cancel SL")
require_analyze(client)
check(
client.placesmartorder(
strategy=STRATEGY,
symbol=SYMBOL,
action="SELL",
exchange=EXCHANGE,
price_type="MARKET",
product=PRODUCT,
quantity=1,
position_size=0,
),
"placesmartorder flatten",
)
print("openposition", client.openposition(
strategy=STRATEGY, symbol=SYMBOL, exchange=EXCHANGE, product=PRODUCT
))
require_analyze(client)
return 0
if __name__ == "__main__":
raise SystemExit(main())
Key takeaways
The useful sequence, when you place and modify orders, is short. Confirm Analyze mode. Place the order. Read orderstatus. Change only an order that is still open or trigger pending. Cancel what you no longer want, or use placesmartorder when the job is to reach a net position, as we did to go from one share back to zero at Rs 1,383.40. And treat cancelallorder as an account-wide switch, not as a filter on the strategy name you pass in.
Learn by watching: free videos every week
Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

