Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop limit order #108

Open
hnguyen2k opened this issue Sep 2, 2020 · 1 comment
Open

Stop limit order #108

hnguyen2k opened this issue Sep 2, 2020 · 1 comment
Labels
bug Concrete, reproducible bugs

Comments

@hnguyen2k
Copy link

hnguyen2k commented Sep 2, 2020

I've been trying to set a stop limit order for a vertical spread, but haven't been successful.

Whenever I set the orderType to OrderType.STOP_LIMIT, I got the following error from the broker:
b'{\n "error" : "OrderType must be one of those values: NET_CREDIT, NET_DEBIT, NET_ZERO or MARKET."\n}'

If I set the orderType to OrderType.NET_CREDIT or OrderType.NET_DEBIT, it became a Limit Order, which is not a Stop Limit Order.

Here is my code to build a stop limit order to buy back a vertical spread:

 def build_stop_limit_for_vertical_spread_order(
      self, sell_symbol, buy_symbol, quantity, stop_price):
         # Constants
         order_type = OrderType.STOP_LIMIT
         session = Session.NORMAL
         duration = Duration.DAY
         order_strategy_type = OrderStrategyType.SINGLE
 
         _buy_order_leg = create_option_order_leg(
             instruction=Instruction.BUY_TO_OPEN, quantity=quantity, symbol=buy_symbol,
         )
 
         _sell_order_leg = create_option_order_leg(
             instruction=Instruction.SELL_TO_OPEN, quantity=quantity, symbol=sell_symbol,
         )
 
         order_leg_collection = [
             _buy_order_leg,
             _sell_order_leg,
         ]
 
         # Hard coded 1% from the stop price as the price limit
         limit_price = str(stop_price + 0.01*stop_price) 
 
         return Order(
             orderType=order_type,
             session=session,
             price=limit_price,
             stopPrice=stop_price,
             stopType=StopType.BID,
             duration=duration,
             orderStrategyType=order_strategy_type,
             orderLegCollection=order_leg_collection,
         )
 

I read TD API from https://developer.tdameritrade.com/account-access/apis/post/accounts/%7BaccountId%7D/orders-0. It seems that they support stop limit order through API.

Can you please point out what wrong with the code? Has anyone successfully gotten the stop limit order working? Any sample code of it is very appreciated. Thanks!

@timkpaine timkpaine added the bug Concrete, reproducible bugs label Sep 10, 2020
@timkpaine
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Concrete, reproducible bugs
Projects
None yet
Development

No branches or pull requests

2 participants