8. Order Status

Track order execution progress via polling

Objective

Track the execution progress of a specific order by polling the order book at short intervals.

Flow

Order Monitor Service → Trading API (Order Detail) → Execution

Order Statuses

StatusMeaning
PENDING (PD)Accepted, not yet processed
PENDING_APPROVALAwaiting approval
READY / SENT / QUEUEDWaiting to match
PARTIAL_FILLEDPartially filled
PARTIAL_CANCELLED (FFPC)Partially filled, remainder cancelled
FILLEDFully filled
PENDING_MODIFY / PENDING_CANCELWaiting for a modification / cancellation to be confirmed
CANCELLEDCancelled
REJECTEDRejected
EXPIREDExpired

The SDK declares more codes the server may send (PRE_SESSION, REQUESTED, ERROR...). Since SDK 3.3.0, Order.status can be an OrderStatus enum, a str (a new code the SDK does not know yet) or None: use helpers.enum_value (see page 1) to print it safely. PARTIAL_CANCELLED is also treated as a terminal status in the samples.

Sample Code — Sync

python/sample_08_order_status.py
import time
from ssi_sdk import Auth, Trading, Config
from ssi_sdk.enums import OrderSide, OrderStatus
from auth_helper import ensure_auth
from helpers import enum_value

config = Config(
    client_id="<your_client_id>",
    api_key="<your_api_key>",
    api_secret="<your_api_secret>",
    private_key="<your_private_key>",
)
ACCOUNT_NO = "<your_account_no>"
TERMINAL_STATUSES = {
    OrderStatus.FILLED, OrderStatus.CANCELLED,
    OrderStatus.REJECTED, OrderStatus.EXPIRED,
    OrderStatus.PARTIAL_CANCELLED,
}

with Auth(config) as auth:
    ensure_auth(auth, otp="<your_otp>")
    with Trading(auth) as trading:
        result = trading.trading.place_limit_order(
            account_no=ACCOUNT_NO, symbol="SSI",
            side=OrderSide.BUY, quantity=100, price=26000,
        )

        for i in range(1, 11):
            orders = trading.portfolio.get_today_orders(ACCOUNT_NO)
            if orders and orders[-1].status in TERMINAL_STATUSES:
                print(f"  Order finished: {enum_value(orders[-1].status)}")
                break
            time.sleep(3)

Sample Code — Async

python/sample_08_order_status_async.py
import asyncio
from ssi_sdk import AsyncAuth, AsyncTrading, Config
from ssi_sdk.enums import OrderSide, OrderStatus
from auth_helper import ensure_auth_async

config = Config(...)
ACCOUNT_NO = "<your_account_no>"
TERMINAL_STATUSES = {
    OrderStatus.FILLED, OrderStatus.CANCELLED,
    OrderStatus.REJECTED, OrderStatus.EXPIRED,
    OrderStatus.PARTIAL_CANCELLED,
}

async def main():
    async with AsyncAuth(config) as auth:
        await ensure_auth_async(auth, otp="<your_otp>")
        async with AsyncTrading(auth) as trading:
            result = await trading.trading.place_limit_order(
                account_no=ACCOUNT_NO, symbol="SSI",
                side=OrderSide.BUY, quantity=100, price=26000,
            )
            for i in range(1, 11):
                orders = await trading.portfolio.get_today_orders(ACCOUNT_NO)
                if orders and orders[-1].status in TERMINAL_STATUSES:
                    break
                await asyncio.sleep(3)

asyncio.run(main())

Notes

  • Polling is suitable for quick checks. For real-time, use WebSocket Trading.
  • Limit poll count and add timeout to avoid infinite loops.

On this page