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 TrackingSample Code — Sync
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
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 ownclient_request_id(up to 20 characters); reusing a key on the same day is rejected withDuplicateRequestError(HTTP 409). - The SDK never retries an order placement/cancel after an error or timeout.
Orderenum fields (side,order_type,status) can be an enum, astrorNone: usehelpers.enum_valueinstead of.value(see page 1).- Requests are RSA-signed using the private key in config.
- Always check buying power before placing orders.