firstrade-api icon indicating copy to clipboard operation
firstrade-api copied to clipboard

Support for “Sell-to-Close” (Option Close) Orders in place_option_order

Open Chia-Yu-Kuo opened this issue 8 months ago • 0 comments

I’m using the API to trade options. While the place_option_order function works fine for opening new positions, I discovered that it does not support closing an existing long position. Instead, every SELL_OPTION call is treated as “Sell-to-Open” and will always attempt to open a new short position, even if you already hold the same contract long.

Attempt to sell 1 contract I have bought ft_order.place_option_order( account=account_id, option_symbol="TLT250512C00088000", order_type=order.OrderType.SELL_OPTION, price_type=order.PriceType.MARKET, duration=order.Duration.DAY, contracts=1, dry_run=False )

error order message: { "statusCode": 400, "error": "Bad Request", "message": "You cannot open a short position in this option while holding a long position.", "refCode": 1103 }

When selling a contract you already hold, it should generate a Sell-to-Close order (transaction code SC) rather than Sell-to-Open. The client library needs a way to distinguish “close” from “open.”

Chia-Yu-Kuo avatar May 09 '25 19:05 Chia-Yu-Kuo