6. Limit Order

Place buy/sell orders at a specified price (LO)

Objective

Place buy/sell stock orders at a specified price. The SDK auto-generates an Idempotency-Key and signs requests with RSA.

Flow

Order → Trading API (Create Order) → Order Tracking

Sample Code — Sync

python/sample_06_limit_order.py
from ssi_sdk import Auth, Trading, Config
from ssi_sdk.enums import OrderSide
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>"

with Auth(config) as auth:
    ensure_auth(auth, otp="<your_otp>")
    with Trading(auth) as trading:
        max_bs = trading.trading.get_max_buy_sell(ACCOUNT_NO, "SSI", 26000)
        if max_bs.max_buy_quantity >= 100:
            result = trading.trading.place_limit_order(
                account_no=ACCOUNT_NO, symbol="SSI",
                side=OrderSide.BUY, quantity=100, price=26000,
            )
            print(f"  Result: {result}")

            orders = trading.portfolio.get_today_orders(ACCOUNT_NO)
            for order in orders[-5:]:
                print(f"  {order.order_id} | {order.symbol} | {enum_value(order.status)}")

Sample Code — Async

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

config = Config(...)
ACCOUNT_NO = "<your_account_no>"

async def main():
    async with AsyncAuth(config) as auth:
        await ensure_auth_async(auth, otp="<your_otp>")
        async with AsyncTrading(auth) as trading:
            buy_result, sell_result = await asyncio.gather(
                trading.trading.place_limit_order(
                    account_no=ACCOUNT_NO, symbol="SSI",
                    side=OrderSide.BUY, quantity=100, price=26000,
                ),
                trading.trading.place_limit_order(
                    account_no=ACCOUNT_NO, symbol="SSI",
                    side=OrderSide.SELL, quantity=100, price=27000,
                ),
            )

asyncio.run(main())

Notes

  • SDK auto-generates Idempotency-Key (clientRequestId) to prevent duplicate orders. You may pass your own client_request_id (up to 20 characters); reusing a key on the same day is rejected with DuplicateRequestError (HTTP 409).
  • The SDK never retries an order placement/cancel after an error or timeout.
  • Order enum fields (side, order_type, status) can be an enum, a str or None: use helpers.enum_value instead of .value (see page 1).
  • Requests are RSA-signed using the private key in config.
  • Always check buying power before placing orders.

On this page